mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
added edit tests + fixed reduce test
This commit is contained in:
parent
fff532db70
commit
ba9eb03f70
@ -106,6 +106,7 @@ const EditFieldForm = ({
|
||||
<Grid gap={4}>
|
||||
<GridItem s={12} col={6}>
|
||||
<TextInput
|
||||
id="label-input"
|
||||
label={formatMessage({
|
||||
id: getTrad('form.Input.label'),
|
||||
defaultMessage: 'Label',
|
||||
@ -122,6 +123,7 @@ const EditFieldForm = ({
|
||||
{shouldDisplaySortToggle && (
|
||||
<GridItem s={12} col={6}>
|
||||
<ToggleInput
|
||||
data-testid="Enable sort on this field"
|
||||
checked={fieldForm.sortable}
|
||||
label={formatMessage({
|
||||
id: getTrad('form.Input.sort.field'),
|
||||
|
@ -1594,7 +1594,7 @@ exports[`ADMIN | CM | LV | Configure the view renders and matches the snapshot 1
|
||||
<span
|
||||
class="c80 c81 c82"
|
||||
>
|
||||
ID
|
||||
hey
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
@ -3601,7 +3601,7 @@ exports[`ADMIN | CM | LV | Configure the view should add field 1`] = `
|
||||
<span
|
||||
class="c80 c81 c82"
|
||||
>
|
||||
ID
|
||||
hey
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
|
@ -46,27 +46,32 @@ const layout = {
|
||||
metadatas: {
|
||||
address: {
|
||||
list: {
|
||||
label: 'address',
|
||||
label: '',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
averagePrice: {
|
||||
list: {
|
||||
label: 'AveragePrice',
|
||||
sortable: true,
|
||||
},
|
||||
},
|
||||
cover: {
|
||||
list: {
|
||||
label: 'michka',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
id: {
|
||||
list: {
|
||||
label: 'ID',
|
||||
label: 'hey',
|
||||
sortable: true,
|
||||
},
|
||||
},
|
||||
since: {
|
||||
list: {
|
||||
label: 'since',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -166,4 +171,47 @@ describe('ADMIN | CM | LV | Configure the view', () => {
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -5,8 +5,8 @@ describe('CONTENT MANAGER | CONTAINERS | ListSettingsView | reducer', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
labelForm: {},
|
||||
labelToEdit: '',
|
||||
fieldForm: {},
|
||||
fieldToEdit: '',
|
||||
initialData: {},
|
||||
modifiedData: {},
|
||||
status: 'resolved',
|
||||
@ -72,19 +72,19 @@ describe('CONTENT MANAGER | CONTAINERS | ListSettingsView | reducer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// describe('ON_CHANGE_LABEL_METAS', () => {
|
||||
// it('should set the attribute metas label in the label form', () => {
|
||||
// const expected = {
|
||||
// ...state,
|
||||
// labelForm: {
|
||||
// label: 'Cover',
|
||||
// },
|
||||
// };
|
||||
// const action = { type: 'ON_CHANGE_LABEL_METAS', name: 'label', value: 'Cover' };
|
||||
describe('ON_CHANGE_FIELD_METAS', () => {
|
||||
it('should set the attribute metas label in the label form', () => {
|
||||
const expected = {
|
||||
...state,
|
||||
fieldForm: {
|
||||
label: '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', () => {
|
||||
// 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', () => {
|
||||
// it('should set the label form data of the field to edit', () => {
|
||||
// state.modifiedData = {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const expected = {
|
||||
// ...state,
|
||||
// labelToEdit: 'cover',
|
||||
// labelForm: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// modifiedData: {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const action = { type: 'SET_LABEL_TO_EDIT', labelToEdit: 'cover' };
|
||||
describe('SET_FIELD_TO_EDIT', () => {
|
||||
it('should set the label form data of the field to edit', () => {
|
||||
state.modifiedData = {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
...state,
|
||||
fieldToEdit: 'cover',
|
||||
fieldForm: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
modifiedData: {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
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', () => {
|
||||
// it('should unset the label to edit and clean the label form', () => {
|
||||
// state = {
|
||||
// ...state,
|
||||
// labelToEdit: 'cover',
|
||||
// labelForm: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// modifiedData: {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const expected = {
|
||||
// ...state,
|
||||
// labelToEdit: '',
|
||||
// labelForm: {},
|
||||
// modifiedData: {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const action = { type: 'UNSET_LABEL_TO_EDIT', labelToEdit: 'cover' };
|
||||
describe('UNSET_FIELD_TO_EDIT', () => {
|
||||
it('should unset the label to edit and clean the label form', () => {
|
||||
state = {
|
||||
...state,
|
||||
fieldToEdit: 'cover',
|
||||
fieldForm: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
modifiedData: {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
...state,
|
||||
fieldToEdit: '',
|
||||
fieldForm: {},
|
||||
modifiedData: {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
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', () => {
|
||||
// it('should submit the label and the sortable value of the field to edit', () => {
|
||||
// state = {
|
||||
// ...state,
|
||||
// labelToEdit: 'cover',
|
||||
// labelForm: {
|
||||
// label: 'New Cover',
|
||||
// sortable: true,
|
||||
// },
|
||||
// modifiedData: {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'Cover',
|
||||
// sortable: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const expected = {
|
||||
// ...state,
|
||||
// labelToEdit: 'cover',
|
||||
// labelForm: {
|
||||
// label: 'New Cover',
|
||||
// sortable: true,
|
||||
// },
|
||||
// modifiedData: {
|
||||
// metadatas: {
|
||||
// cover: {
|
||||
// list: {
|
||||
// label: 'New Cover',
|
||||
// sortable: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// const action = { type: 'SUBMIT_LABEL_FORM', labelToEdit: 'cover' };
|
||||
describe('SUBMIT_FIELD_FORM', () => {
|
||||
it('should submit the label and the sortable value of the field to edit', () => {
|
||||
state = {
|
||||
...state,
|
||||
fieldToEdit: 'cover',
|
||||
fieldForm: {
|
||||
label: 'New Cover',
|
||||
sortable: true,
|
||||
},
|
||||
modifiedData: {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'Cover',
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
...state,
|
||||
fieldToEdit: 'cover',
|
||||
fieldForm: {
|
||||
label: 'New Cover',
|
||||
sortable: true,
|
||||
},
|
||||
modifiedData: {
|
||||
metadatas: {
|
||||
cover: {
|
||||
list: {
|
||||
label: 'New Cover',
|
||||
sortable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const action = { type: 'SUBMIT_FIELD_FORM', fieldToEdit: 'cover' };
|
||||
|
||||
// expect(reducer(state, action)).toEqual(expected);
|
||||
// });
|
||||
// });
|
||||
expect(reducer(state, action)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user