Skip to content

Commit

Permalink
UIQM-730 added tests for validation errors notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Nov 12, 2024
1 parent 91aba02 commit db8eb43
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions src/QuickMarcEditor/QuickMarcEditor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,15 +793,12 @@ describe('Given QuickMarcEditor', () => {
});

describe('when saving form with validation errors and deleted fields', () => {
beforeEach(() => {
beforeEach(async () => {
mockValidate.mockClear().mockResolvedValue({ [MISSING_FIELD_ID]: [{ id: 'some error', severity: 'error', values: {} }] });
});

it('should show errors and not show confirmation modal', async () => {
const {
getAllByRole,
getByText,
queryByText,
getByTestId,
} = renderQuickMarcEditor();

Expand All @@ -811,16 +808,60 @@ describe('Given QuickMarcEditor', () => {
fireEvent.change(contentField, { target: { value: '' } });
fireEvent.click(deleteButtons[0]);
await fireEvent.click(getByText('stripes-acq-components.FormFooter.save'));
});

it('should show errors and not show confirmation modal', async () => {
await waitFor(() => {
expect(queryByText('Confirmation modal')).toBeNull();
expect(screen.queryByText('Confirmation modal')).toBeNull();
expect(mockShowCallout).toHaveBeenCalledWith({
messageId: 'some error',
values: {},
type: 'error',
});
});
});

it('should show a toast notification about validation error', async () => {
await waitFor(() => {
expect(mockShowCallout).toHaveBeenCalledWith({
messageId: 'ui-quick-marc.record.save.error.fail',
values: {
failCount: 1,
warnCount: 0,
},
type: 'error',
});
});
});
});

describe('when saving form with validation warnings', () => {
beforeEach(async () => {
mockValidate.mockClear().mockResolvedValue({ [MISSING_FIELD_ID]: [{ id: 'some warning', severity: 'warn', values: {} }] });

const {
getByText,
getByTestId,
} = renderQuickMarcEditor();

const contentField = getByTestId('content-field-3');

fireEvent.change(contentField, { target: { value: '' } });
await fireEvent.click(getByText('stripes-acq-components.FormFooter.save'));
});

it('should show a toast notification about validation warning', async () => {
await waitFor(() => {
expect(mockShowCallout).toHaveBeenCalledWith({
messageId: 'ui-quick-marc.record.save.error.warn',
values: {
failCount: 0,
warnCount: 1,
},
type: 'warning',
});
});
});
});

describe('when marc record is of type HOLDINGS', () => {
Expand Down

0 comments on commit db8eb43

Please sign in to comment.