Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe('rgbToHexColor works correct', () => {
- const colors = ['red', 'green', 'blue'];
- for (let indexRGB = 0; indexRGB < 3; indexRGB++) {
- it(`Invalid ${colors[indexRGB]} values should return undefined`, () => {
- const expected = undefined;
- const InvalidValues = ['1', 1.1, -1, -100, -1000, 256, 300, 1000];
- const Dummy = [1, 1, 1];
- for (let indexInvalidValue = 0; indexInvalidValue < InvalidValues.length; indexInvalidValue++) {
- const currInvalidValue = InvalidValues[indexInvalidValue];
- let newArr = Dummy.slice();
- newArr[indexRGB] = currInvalidValue;
- const actual = rgbToHexColor(...newArr);
- assert.equal(expected, actual);
- }
- });
- }
- it('Should start with # and be 7 symbols long', () => {
- const actual = rgbToHexColor(100, 100, 100);
- assert.equal(actual.length, 7);
- assert.equal(actual[0], '#');
- });
- for (let indexRGB = 0; indexRGB < 3; indexRGB++) {
- it(`Hex value for ${colors[indexRGB]} with length of one should be prepended wih 0`, () => {
- const SmallValue = '123456789';
- const Dummy = [200, 200, 200];
- for (let indexSmallValue = 0; indexSmallValue < SmallValue.length; indexSmallValue++) {
- const currSmallValue = SmallValue[indexSmallValue];
- const newArr = Dummy.slice();
- newArr[indexRGB] = +currSmallValue;
- const result = rgbToHexColor(...newArr);
- const trimmed = result.slice(1);
- const actual = trimmed.substr(indexRGB * 2, 2);
- assert(actual[0], '0');
- }
- });
- }
- it('Should return correct RGB value', () => {
- const actual1 = rgbToHexColor(0, 0, 0);
- const actual2 = rgbToHexColor(100, 100, 100);
- const actual3 = rgbToHexColor(255, 255, 255);
- const expexted1 = '#000000';
- const expexted2 = '#646464';
- const expexted3 = '#FFFFFF';
- assert.equal(actual1, expexted1);
- assert.equal(actual2, expexted2);
- assert.equal(actual3, expexted3);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement