Skip to content

Commit a9ae0ba

Browse files
complete test for onFirstSelect
callback
1 parent 5a3664a commit a9ae0ba

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/index.test.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ beforeEach(() => {
2626
},
2727
],
2828
selectedTabID: '1',
29+
onFirstSelect: jest.fn(function () {}),
2930
onSelect: jest.fn(function () {}),
3031
onChange: jest.fn(function () {}),
3132
onInit: jest.fn(function () {}),
@@ -153,7 +154,7 @@ describe('apply multiple actions : ', () => {
153154
expect(op.onInit.mock.calls.length).toBe(3);
154155
});
155156
test('checking events execution count', () => {
156-
expect.assertions(9);
157+
expect.assertions(10);
157158
const onSelectHandler = jest.fn(() => {});
158159
renderApp();
159160
act(() => {
@@ -170,6 +171,7 @@ describe('apply multiple actions : ', () => {
170171
expect(op.onInit.mock.calls.length).toBe(2);
171172
expect(op.onChange.mock.calls.length).toBe(1);
172173
expect(onSelectHandler.mock.calls.length).toBe(1);
174+
expect(op.onFirstSelect.mock.calls.length).toBe(1);
173175
expect(op.onSelect.mock.calls.length).toBe(1);
174176
expect(op.onClose.mock.calls.length).toBe(1);
175177
expect(op.onOpen.mock.calls.length).toBe(1);
@@ -261,6 +263,7 @@ describe('calling some action inside the events options', () => {
261263
expect(op.onLoad.mock.calls.length === 1).toBe(true);
262264
expect(op.onInit.mock.calls.length === 2).toBe(true);
263265
expect(op.onChange.mock.calls.length === 1).toBe(true);
266+
expect(op.onFirstSelect.mock.calls.length === 1).toBe(true);
264267
expect(op.onSelect.mock.calls.length === 1).toBe(true);
265268
});
266269
});
@@ -511,3 +514,38 @@ describe('onSelect callback : ', () => {
511514
});
512515
});
513516
});
517+
describe('onFirstSelect callback : ', () => {
518+
test('it is not triggered initially', () => {
519+
renderApp();
520+
expect(op.onFirstSelect.mock.calls.length).toBe(0);
521+
});
522+
test('it is triggered at most once per each tab, before onSelect event. if the tab has not been selected yet', () => {
523+
renderApp();
524+
expect(op.onFirstSelect.mock.calls.length).toBe(0);
525+
expect(op.onSelect.mock.calls.length).toBe(0);
526+
act(() => {
527+
instance.select('2');
528+
});
529+
expect(op.onFirstSelect.mock.calls.length).toBe(1);
530+
expect(op.onSelect.mock.calls.length).toBe(1);
531+
expect(op.onFirstSelect).toHaveBeenCalledBefore(op.onSelect);
532+
act(() => {
533+
instance.select('1');
534+
});
535+
act(() => {
536+
instance.select('2');
537+
});
538+
expect(op.onFirstSelect.mock.calls.length).toBe(1);
539+
expect(op.onSelect.mock.calls.length).toBe(3);
540+
});
541+
test('onFirstSelect is called with {currentSelectedTabId,previousSelectedTabId} object as a parameter', () => {
542+
renderApp();
543+
act(() => {
544+
instance.select('2');
545+
});
546+
expect(op.onFirstSelect.mock.calls[0][0]).toEqual({
547+
currentSelectedTabId: '2',
548+
previousSelectedTabId: '1',
549+
});
550+
});
551+
});

0 commit comments

Comments
 (0)