Passed
Pull Request — master (#81)
by Alejandro
02:56
created

ColorGenerator.test.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.85
1
import * as sinon from 'sinon';
2
import ColorGenerator from '../../../src/utils/services/ColorGenerator';
3
4
describe('ColorGenerator', () => {
5
  let colorGenerator;
6
  const storageMock = {
7
    set: sinon.fake(),
8
    get: sinon.fake.returns(undefined),
9
  };
10
11
  beforeEach(() => {
12
    storageMock.set.resetHistory();
13
    storageMock.get.resetHistory();
14
15
    colorGenerator = new ColorGenerator(storageMock);
16
  });
17
18
  it('sets a color in the storage and makes it available after that', () => {
19
    const color = '#ff0000';
20
21
    colorGenerator.setColorForKey('foo', color);
22
23
    expect(colorGenerator.getColorForKey('foo')).toEqual(color);
24
    expect(storageMock.set.callCount).toEqual(1);
25
    expect(storageMock.get.callCount).toEqual(1);
26
  });
27
28
  it('generates a random color when none is available for requested key', () => {
29
    expect(colorGenerator.getColorForKey('bar')).toEqual(expect.stringMatching(/^#(?:[0-9a-fA-F]{6})$/));
0 ignored issues
show
Bug introduced by
The variable expect seems to be never declared. If this is a global, consider adding a /** global: expect */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
    expect(storageMock.set.callCount).toEqual(1);
31
    expect(storageMock.get.callCount).toEqual(1);
32
  });
33
34
  it('trims and lower cases keys before trying to match', () => {
35
    const color = '#ff0000';
36
37
    colorGenerator.setColorForKey('foo', color);
38
39
    expect(colorGenerator.getColorForKey('  foo')).toEqual(color);
40
    expect(colorGenerator.getColorForKey('foO')).toEqual(color);
41
    expect(colorGenerator.getColorForKey('FoO')).toEqual(color);
42
    expect(colorGenerator.getColorForKey('FOO')).toEqual(color);
43
    expect(colorGenerator.getColorForKey('FOO  ')).toEqual(color);
44
    expect(colorGenerator.getColorForKey(' FoO  ')).toEqual(color);
45
    expect(storageMock.set.callCount).toEqual(1);
46
    expect(storageMock.get.callCount).toEqual(1);
47
  });
48
});
49