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 2c6bd0a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/QuickMarcEditor/QuickMarcEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ const QuickMarcEditor = ({
/>
{
confirmRemoveAuthorityLinking && (
<IfPermission perm="ui-quick-marc.quick-marc-authority-records.linkUnlink">
<IfPermission perm="ui-quick-marc.quick-marc-authority-records.link-unlink.execute">
<ConfirmationModal
id="quick-marc-remove-authority-linking-confirm-modal"
open={isUnlinkRecordsModalOpen}
Expand Down
85 changes: 80 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,94 @@ 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 saving form with validation warnings and errors', () => {
beforeEach(async () => {
mockValidate.mockClear().mockResolvedValue({
[MISSING_FIELD_ID]: [
{ id: 'some warning', severity: 'warn', values: {} },
{ id: 'some error', severity: 'error', 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 and error', async () => {
await waitFor(() => {
expect(mockShowCallout).toHaveBeenCalledWith({
messageId: 'ui-quick-marc.record.save.error.failAndWarn',
values: {
failCount: 1,
warnCount: 1,
},
type: 'error',
});
});
});
});

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

0 comments on commit 2c6bd0a

Please sign in to comment.