Skip to content

Commit

Permalink
chore(discoverability): use .each
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenCodes committed Oct 20, 2020
1 parent b29629c commit 7fa2915
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,52 +54,44 @@ describe('lib/viewers/image/ImageViewer', () => {
});

describe('destroy()', () => {
beforeEach(() => {
jest.spyOn(image, 'removeListener');
});

test('should remove the zoom event listener if enableAnnotationsImageDiscoverability is true', () => {
image.options.enableAnnotationsImageDiscoverability = true;

image.destroy();

expect(image.removeListener).toBeCalledWith('zoom', expect.any(Function));
});

test('should not remove the zoom event listener if enableAnnotationsImageDiscoverability is false', () => {
image.options.enableAnnotationsImageDiscoverability = false;
test.each`
enableAnnotationsImageDiscoverability | numberOfCalls
${true} | ${1}
${false} | ${0}
`(
'should call removeListener $numberOfCalls times if enableAnnotationsImageDiscoverability is $enableAnnotationsImageDiscoverability',
({ enableAnnotationsImageDiscoverability, numberOfCalls }) => {
image.options.enableAnnotationsImageDiscoverability = enableAnnotationsImageDiscoverability;
jest.spyOn(image, 'removeListener');

image.destroy();
image.destroy();

expect(image.removeListener).not.toBeCalledWith('zoom', expect.any(Function));
});
expect(image.removeListener).toBeCalledTimes(numberOfCalls);
},
);
});

describe('setup()', () => {
beforeEach(() => {
jest.spyOn(image, 'addListener');
});

test('should set up layout', () => {
expect(image.wrapperEl).toHaveClass('bp-image');
expect(image.imageEl).toHaveClass('bp-is-invisible');
});

test('should bind zoom listener if enableAnnotationsImageDiscoverability is true', () => {
image.options.enableAnnotationsImageDiscoverability = true;

image.setup();

expect(image.addListener).toBeCalledWith('zoom', expect.any(Function));
});

test('should not bind zoom listener if enableAnnotationsImageDiscoverability is false', () => {
image.options.enableAnnotationsImageDiscoverability = false;
test.each`
enableAnnotationsImageDiscoverability | numberOfCalls
${true} | ${1}
${false} | ${0}
`(
'should call addListener $numberOfCalls times if enableAnnotationsImageDiscoverability is $enableAnnotationsImageDiscoverability',
({ enableAnnotationsImageDiscoverability, numberOfCalls }) => {
image.options.enableAnnotationsImageDiscoverability = enableAnnotationsImageDiscoverability;
jest.spyOn(image, 'addListener');

image.setup();
image.setup();

expect(image.addListener).not.toBeCalledWith('zoom', expect.any(Function));
});
expect(image.addListener).toBeCalledTimes(numberOfCalls);
},
);
});

describe('load()', () => {
Expand Down

0 comments on commit 7fa2915

Please sign in to comment.