added edit tests + fixed reduce test

This commit is contained in:
ronronscelestes 2021-10-14 15:40:11 +02:00
parent fff532db70
commit ba9eb03f70
4 changed files with 183 additions and 133 deletions

View File

@ -106,6 +106,7 @@ const EditFieldForm = ({
<Grid gap={4}> <Grid gap={4}>
<GridItem s={12} col={6}> <GridItem s={12} col={6}>
<TextInput <TextInput
id="label-input"
label={formatMessage({ label={formatMessage({
id: getTrad('form.Input.label'), id: getTrad('form.Input.label'),
defaultMessage: 'Label', defaultMessage: 'Label',
@ -122,6 +123,7 @@ const EditFieldForm = ({
{shouldDisplaySortToggle && ( {shouldDisplaySortToggle && (
<GridItem s={12} col={6}> <GridItem s={12} col={6}>
<ToggleInput <ToggleInput
data-testid="Enable sort on this field"
checked={fieldForm.sortable} checked={fieldForm.sortable}
label={formatMessage({ label={formatMessage({
id: getTrad('form.Input.sort.field'), id: getTrad('form.Input.sort.field'),

View File

@ -1594,7 +1594,7 @@ exports[`ADMIN | CM | LV | Configure the view renders and matches the snapshot 1
<span <span
class="c80 c81 c82" class="c80 c81 c82"
> >
ID hey
</span> </span>
</div> </div>
<div <div
@ -3601,7 +3601,7 @@ exports[`ADMIN | CM | LV | Configure the view should add field 1`] = `
<span <span
class="c80 c81 c82" class="c80 c81 c82"
> >
ID hey
</span> </span>
</div> </div>
<div <div

View File

@ -46,27 +46,32 @@ const layout = {
metadatas: { metadatas: {
address: { address: {
list: { list: {
label: 'address', label: '',
sortable: false,
}, },
}, },
averagePrice: { averagePrice: {
list: { list: {
label: 'AveragePrice', label: 'AveragePrice',
sortable: true,
}, },
}, },
cover: { cover: {
list: { list: {
label: 'michka', label: 'michka',
sortable: false,
}, },
}, },
id: { id: {
list: { list: {
label: 'ID', label: 'hey',
sortable: true,
}, },
}, },
since: { since: {
list: { list: {
label: 'since', label: 'since',
sortable: false,
}, },
}, },
}, },
@ -166,4 +171,47 @@ describe('ADMIN | CM | LV | Configure the view', () => {
expect(queryByTestId('delete-id')).not.toBeInTheDocument(); expect(queryByTestId('delete-id')).not.toBeInTheDocument();
}); });
describe('Edit modal', () => {
it('should open edit modal', async () => {
const history = createMemoryHistory();
render(makeApp(history), { container: document.body });
await waitFor(() =>
expect(screen.getByText('Configure the view - Michka')).toBeInTheDocument()
);
fireEvent.click(screen.getByLabelText('Edit address'));
expect(
screen.getByText("This value overrides the label displayed in the table's head")
).toBeInTheDocument();
});
it('should not show sortable toggle input if field not sortable', async () => {
const history = createMemoryHistory();
const { queryByText } = render(makeApp(history), { container: document.body });
await waitFor(() =>
expect(screen.getByText('Configure the view - Michka')).toBeInTheDocument()
);
fireEvent.click(screen.getByLabelText('Edit address'));
expect(queryByText('Enable sort on this field')).not.toBeInTheDocument();
});
it('should show sortable toggle input if field sortable', async () => {
const history = createMemoryHistory();
const { queryByTestId } = render(makeApp(history), { container: document.body });
await waitFor(() =>
expect(screen.getByText('Configure the view - Michka')).toBeInTheDocument()
);
fireEvent.click(screen.getByLabelText('Edit id'));
expect(queryByTestId('Enable sort on this field')).toBeInTheDocument();
});
});
}); });

View File

@ -5,8 +5,8 @@ describe('CONTENT MANAGER | CONTAINERS | ListSettingsView | reducer', () => {
beforeEach(() => { beforeEach(() => {
state = { state = {
labelForm: {}, fieldForm: {},
labelToEdit: '', fieldToEdit: '',
initialData: {}, initialData: {},
modifiedData: {}, modifiedData: {},
status: 'resolved', status: 'resolved',
@ -72,19 +72,19 @@ describe('CONTENT MANAGER | CONTAINERS | ListSettingsView | reducer', () => {
}); });
}); });
// describe('ON_CHANGE_LABEL_METAS', () => { describe('ON_CHANGE_FIELD_METAS', () => {
// it('should set the attribute metas label in the label form', () => { it('should set the attribute metas label in the label form', () => {
// const expected = { const expected = {
// ...state, ...state,
// labelForm: { fieldForm: {
// label: 'Cover', label: 'Cover',
// }, },
// }; };
// const action = { type: 'ON_CHANGE_LABEL_METAS', name: 'label', value: 'Cover' }; const action = { type: 'ON_CHANGE_FIELD_METAS', name: 'label', value: 'Cover' };
// expect(reducer(state, action)).toEqual(expected); expect(reducer(state, action)).toEqual(expected);
// }); });
// }); });
// describe('ON_RESET', () => { // describe('ON_RESET', () => {
// it('should set the current modified data to the initial state', () => { // it('should set the current modified data to the initial state', () => {
@ -130,124 +130,124 @@ describe('CONTENT MANAGER | CONTAINERS | ListSettingsView | reducer', () => {
}); });
}); });
// describe('SET_LABEL_TO_EDIT', () => { describe('SET_FIELD_TO_EDIT', () => {
// it('should set the label form data of the field to edit', () => { it('should set the label form data of the field to edit', () => {
// state.modifiedData = { state.modifiedData = {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// }, },
// }, },
// }; };
// const expected = { const expected = {
// ...state, ...state,
// labelToEdit: 'cover', fieldToEdit: 'cover',
// labelForm: { fieldForm: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// modifiedData: { modifiedData: {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// }, },
// }, },
// }, },
// }; };
// const action = { type: 'SET_LABEL_TO_EDIT', labelToEdit: 'cover' }; const action = { type: 'SET_FIELD_TO_EDIT', fieldToEdit: 'cover' };
// expect(reducer(state, action)).toEqual(expected); expect(reducer(state, action)).toEqual(expected);
// }); });
// }); });
// describe('UNSET_LABEL_TO_EDIT', () => { describe('UNSET_FIELD_TO_EDIT', () => {
// it('should unset the label to edit and clean the label form', () => { it('should unset the label to edit and clean the label form', () => {
// state = { state = {
// ...state, ...state,
// labelToEdit: 'cover', fieldToEdit: 'cover',
// labelForm: { fieldForm: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// modifiedData: { modifiedData: {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// }, },
// }, },
// }, },
// }; };
// const expected = { const expected = {
// ...state, ...state,
// labelToEdit: '', fieldToEdit: '',
// labelForm: {}, fieldForm: {},
// modifiedData: { modifiedData: {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// }, },
// }, },
// }, },
// }; };
// const action = { type: 'UNSET_LABEL_TO_EDIT', labelToEdit: 'cover' }; const action = { type: 'UNSET_FIELD_TO_EDIT', fieldToEdit: 'cover' };
// expect(reducer(state, action)).toEqual(expected); expect(reducer(state, action)).toEqual(expected);
// }); });
// }); });
// describe('SUBMIT_LABEL_FORM', () => { describe('SUBMIT_FIELD_FORM', () => {
// it('should submit the label and the sortable value of the field to edit', () => { it('should submit the label and the sortable value of the field to edit', () => {
// state = { state = {
// ...state, ...state,
// labelToEdit: 'cover', fieldToEdit: 'cover',
// labelForm: { fieldForm: {
// label: 'New Cover', label: 'New Cover',
// sortable: true, sortable: true,
// }, },
// modifiedData: { modifiedData: {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'Cover', label: 'Cover',
// sortable: false, sortable: false,
// }, },
// }, },
// }, },
// }, },
// }; };
// const expected = { const expected = {
// ...state, ...state,
// labelToEdit: 'cover', fieldToEdit: 'cover',
// labelForm: { fieldForm: {
// label: 'New Cover', label: 'New Cover',
// sortable: true, sortable: true,
// }, },
// modifiedData: { modifiedData: {
// metadatas: { metadatas: {
// cover: { cover: {
// list: { list: {
// label: 'New Cover', label: 'New Cover',
// sortable: true, sortable: true,
// }, },
// }, },
// }, },
// }, },
// }; };
// const action = { type: 'SUBMIT_LABEL_FORM', labelToEdit: 'cover' }; const action = { type: 'SUBMIT_FIELD_FORM', fieldToEdit: 'cover' };
// expect(reducer(state, action)).toEqual(expected); expect(reducer(state, action)).toEqual(expected);
// }); });
// }); });
}); });