Ensured tags list is not updated until the edit modal is closed

This commit is contained in:
Alejandro Celaya
2022-11-07 21:32:19 +01:00
parent 2183b09ffe
commit 5ecc791b38
4 changed files with 19 additions and 21 deletions

View File

@@ -9,12 +9,11 @@ import { ProblemDetailsError } from '../../../src/api/types/errors';
describe('<EditTagModal />', () => {
const EditTagModal = createEditTagModal(Mock.of<ColorGenerator>({ getColorForKey: jest.fn(() => 'green') }));
const editTag = jest.fn().mockReturnValue(Promise.resolve());
const tagEdited = jest.fn().mockReturnValue(Promise.resolve());
const toggle = jest.fn();
const setUp = (tagEdit: Partial<TagEdition> = {}) => {
const edition = Mock.of<TagEdition>(tagEdit);
return renderWithEvents(
<EditTagModal isOpen tag="foo" tagEdit={edition} editTag={editTag} tagEdited={tagEdited} toggle={toggle} />,
<EditTagModal isOpen tag="foo" tagEdit={edition} editTag={editTag} tagEdited={jest.fn()} toggle={toggle} />,
);
};
@@ -30,7 +29,6 @@ describe('<EditTagModal />', () => {
expect(toggle).toHaveBeenCalledTimes(2);
expect(editTag).not.toHaveBeenCalled();
expect(tagEdited).not.toHaveBeenCalled();
});
it.each([
@@ -63,12 +61,12 @@ describe('<EditTagModal />', () => {
const { user } = setUp();
expect(editTag).not.toHaveBeenCalled();
expect(tagEdited).not.toHaveBeenCalled();
expect(toggle).not.toHaveBeenCalled();
await user.click(screen.getByRole('button', { name: 'Save' }));
expect(editTag).toHaveBeenCalled();
expect(tagEdited).toHaveBeenCalled();
expect(toggle).toHaveBeenCalled();
});
it('changes color when changing on color picker', async () => {

View File

@@ -21,24 +21,23 @@ describe('tagEditReducer', () => {
it('returns loading on EDIT_TAG_START', () => {
expect(reducer(undefined, Mock.of<EditTagAction>({ type: EDIT_TAG_START }))).toEqual({
editing: true,
edited: false,
error: false,
oldName: '',
newName: '',
});
});
it('returns error on EDIT_TAG_ERROR', () => {
expect(reducer(undefined, Mock.of<EditTagAction>({ type: EDIT_TAG_ERROR }))).toEqual({
editing: false,
edited: false,
error: true,
oldName: '',
newName: '',
});
});
it('returns tag names on EDIT_TAG', () => {
expect(reducer(undefined, { type: EDIT_TAG, oldName, newName, color })).toEqual({
editing: false,
edited: true,
error: false,
oldName: 'foo',
newName: 'bar',
@@ -82,7 +81,7 @@ describe('tagEditReducer', () => {
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_TAG_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_TAG, oldName, newName });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_TAG, oldName, newName, color });
});
it('throws on error', async () => {