Skip to content

Commit 0f8d852

Browse files
committed
merge
2 parents e88ce8d + 60a1be5 commit 0f8d852

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

src/app/__tests__/SwitchApp.test.jsx

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,56 @@ describe('Unit testing for SwitchApp.jsx', () => {
1616

1717
const state = {
1818
currentTab: 100,
19-
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1 } },
19+
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1, title: 'component'} },
2020
};
21-
const tabsArray = [];
22-
const currTab = {
21+
const dropdownCurrTabLabel = {
2322
value: 100,
24-
label: {},
23+
label: 'component',
2524
};
26-
25+
// nate and edwin: mockImplementation creates a mock function call
2726
const dispatch = jest.fn();
28-
useStoreContext.mockImplementation(() => [dispatch, state]);
27+
28+
// nate and edwin: mockImplementation creates a mock state
29+
useStoreContext.mockImplementation(() => [state, dispatch]);
2930

3031
beforeEach(() => {
3132
wrapper = shallow(<SwitchApp />);
33+
dispatch.mockClear();
34+
});
35+
36+
describe('SwitchApp Component', () => {
37+
beforeEach(() => {
38+
wrapper.find('.tab-select-container').simulate('change', {});
39+
});
40+
// console.log('dispatch mock calls', dispatch.mock.calls);
41+
it('SwitchApp component returns <Select /> from react-select library', () => {
42+
expect(wrapper.find('.tab-select-container').type()).toEqual(Select);
43+
expect(wrapper.find('.tab-select-container').props().className).toBe('tab-select-container');
44+
expect(wrapper.find('.tab-select-container').props().value).toEqual(dropdownCurrTabLabel);
45+
});
46+
it('OnChange should run dispatch function', () => {
47+
expect(dispatch.mock.calls.length).toBe(1);
48+
})
49+
it('options prop should be an array', () => {
50+
expect(Array.isArray(wrapper.find('.tab-select-container').props().options)).toBeTruthy();
51+
expect(wrapper.find('.tab-select-container').props().options[0]).toHaveProperty('value');
52+
expect(wrapper.find('.tab-select-container').props().options[0]).toHaveProperty('label');
53+
});
3254
});
3355

34-
describe('currentTab', () => {
56+
describe('dropdownCurrTabLabel', () => {
3557
it('should have properties value and label', () => {
36-
expect(currTab).toHaveProperty('value');
37-
expect(currTab).toHaveProperty('label');
58+
expect(dropdownCurrTabLabel).toHaveProperty('value');
59+
expect(dropdownCurrTabLabel).toHaveProperty('label');
3860
});
3961
});
4062

41-
// check if currTab has properties value, label
42-
// currentTab should be a number
43-
// tab should be an object
44-
// check if onChange if the function runs
45-
// className should be tab-select-container
46-
// options should be an array
47-
// value prop should be equal to a number
48-
})
63+
describe('state', () => {
64+
it('currentTab value should be a number', () => {
65+
expect(typeof state.currentTab).toEqual('number');
66+
});
67+
it('tabs value should be an object', () => {
68+
expect(typeof state.tabs).toEqual('object');
69+
});
70+
});
71+
});

0 commit comments

Comments
 (0)