Unit tests fixes

This commit is contained in:
Virginie Ky 2019-11-26 10:39:26 +01:00
parent ef66c9ccb8
commit ce3ada140d
6 changed files with 86 additions and 69 deletions

View File

@ -36,6 +36,9 @@ describe('<Admin />', () => {
strapiVersion: '3',
uuid: false,
},
intl: {
formatMessage: jest.fn(),
},
location: {},
setAppError: jest.fn(),
showGlobalAppBlocker: jest.fn(),

View File

@ -190,6 +190,7 @@ function ListView({
},
});
}
onChangeListLabels({
target: {
name,

View File

@ -16,34 +16,42 @@ describe('Content Manager | Main | reducer', () => {
components: [],
initialLayouts: {
test: {
layouts: {
edit: [],
editRelations: [],
list: ['test'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['test'],
},
},
},
otherTest: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
},
},
},
},
isLoading: true,
layouts: {
test: {
layouts: {
edit: [],
editRelations: [],
list: ['test'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['test'],
},
},
},
otherTest: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
},
},
},
},
@ -55,7 +63,11 @@ describe('Content Manager | Main | reducer', () => {
const expected = {
...state,
layouts: {
test: { layouts: { edit: [], editRelations: [], list: ['test'] } },
test: {
contentType: {
layouts: { edit: [], editRelations: [], list: ['test'] },
},
},
},
};
@ -72,17 +84,23 @@ describe('Content Manager | Main | reducer', () => {
});
it('should handle the resetListLabels action correctly', () => {
state.layouts.test.layouts.list.push('label');
state.layouts.test.contentType.layouts.list.push('label');
const expected = {
...state,
layouts: {
test: { layouts: { edit: [], editRelations: [], list: ['test'] } },
test: {
contentType: {
layouts: { edit: [], editRelations: [], list: ['test'] },
},
},
otherTest: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest'],
},
},
},
},
@ -99,34 +117,12 @@ describe('Content Manager | Main | reducer', () => {
layouts: {
...state.layouts,
otherTest: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest', 'foo'],
},
},
},
};
expect(
mainReducer(
fromJS(state),
onChangeListLabels({ target: { name: 'otherTest.foo', value: true } })
).toJS()
).toEqual(expected);
});
it('should handle the onChangeListLabels action correctly when removing a label', () => {
state.layouts.otherTest.layouts.list = ['otherTest', 'foo'];
const expected = {
...state,
layouts: {
...state.layouts,
otherTest: {
layouts: {
edit: [],
editRelations: [],
list: ['foo'],
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['otherTest', 'foo'],
},
},
},
},
@ -136,7 +132,39 @@ describe('Content Manager | Main | reducer', () => {
mainReducer(
fromJS(state),
onChangeListLabels({
target: { name: 'otherTest.otherTest', value: false },
target: { name: 'foo', slug: 'otherTest', value: true },
})
).toJS()
).toEqual(expected);
});
it('should handle the onChangeListLabels action correctly when removing a label', () => {
state.layouts.otherTest.contentType.layouts.list = ['otherTest', 'foo'];
const expected = {
...state,
layouts: {
...state.layouts,
otherTest: {
contentType: {
layouts: {
edit: [],
editRelations: [],
list: ['foo'],
},
},
},
},
};
expect(
mainReducer(
fromJS(state),
onChangeListLabels({
target: {
name: 'otherTest',
slug: 'otherTest',
value: false,
},
})
).toJS()
).toEqual(expected);

View File

@ -28,19 +28,4 @@ describe('<EditViewLink />', () => {
expect(liLink).toHaveLength(0);
});
it('should handle the source correctly if it is undefined', () => {
const wrapper = shallow(<EditViewLink {...props} />);
const liLink = wrapper.find(LiLink);
expect(liLink.prop('url')).toBe('/plugins/test');
});
it('should handle the source correctly if it is not undefined', () => {
props.getSource = jest.fn(() => 'users-permissions');
const wrapper = shallow(<EditViewLink {...props} />);
const liLink = wrapper.find(LiLink);
expect(liLink.prop('url')).toBe('/plugins/test&source=users-permissions');
});
});

View File

@ -2,13 +2,13 @@
exports[`<Loader /> should not crash 1`] = `
<div
className="sc-fYxtnH jGsbTZ"
className="sc-jnlKLf dzQmya"
>
<div
className="centered"
>
<div
className="sc-fMiknA iIEoBL"
className="sc-fBuWsC chFDHA"
>
<div />
</div>