Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3k committed Dec 4, 2024
1 parent 25f39fe commit d249dbd
Showing 1 changed file with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ describe('AddAnnouncementPage', () => {
await wrappedRender();
const saveButton = getByRole('button', { name: 'Save' });
const title = getByLabelText('Title');
const linkUrl = getByLabelText('Link URL');
const displayLinkAs = getByLabelText('Display URL As');
const fileName = getByLabelText('Display File Link As');
await fireEvent.update(title, 'Test Title');
setRichTextValue(
Expand All @@ -458,8 +456,6 @@ describe('AddAnnouncementPage', () => {
});
const noExpiry = getByRole('checkbox', { name: 'No expiry' });
await fireEvent.click(noExpiry);
await fireEvent.update(linkUrl, 'https://example.com');
await fireEvent.update(displayLinkAs, 'a'.repeat(50));
await fireEvent.update(fileName, 'a'.repeat(101));
await markAsPublish();
await fireEvent.click(saveButton);
Expand All @@ -470,13 +466,13 @@ describe('AddAnnouncementPage', () => {
});
});
});
describe('when link url is empty', () => {
describe('when file is empty', () => {
it('should show error message', async () => {
const { getByRole, getByLabelText, getByText, container } =
await wrappedRender();
const saveButton = getByRole('button', { name: 'Save' });
const title = getByLabelText('Title');
const displayLinkAs = getByLabelText('Display URL As');
const displayLinkAs = getByLabelText('Display File Link As');
await fireEvent.update(title, 'Test Title');
setRichTextValue(
container,
Expand All @@ -494,7 +490,45 @@ describe('AddAnnouncementPage', () => {
await markAsPublish();
await fireEvent.click(saveButton);
await waitFor(() => {
expect(getByText('Link URL is required.')).toBeInTheDocument();
expect(getByText('File attachment is required.')).toBeInTheDocument();
});
});
});
});
describe('when file is not empty', () => {
describe('when file name is empty', () => {
it('should show error message', async () => {
const { getByRole, getByLabelText, getByText, container } =
await wrappedRender();
const saveButton = getByRole('button', { name: 'Save' });
const title = getByLabelText('Title');
const attachment = getByLabelText('Attachment');
const file = new File(['hello'], 'chucknorris.png', {
type: 'image/png',
});
await waitFor(() => userEvent.upload(attachment, file));
await waitFor(() => {
expect(mockClamavScanFile).toHaveBeenCalled();
});
await fireEvent.update(title, 'Test Title');
setRichTextValue(
container,
'announcementDescription',
'Test description',
);
const activeOn = getByLabelText('Active On');
const activeOnDate = formatDate(LocalDate.now());
await setDate(activeOn, () => {
return getByLabelText(activeOnDate);
});
const noExpiry = getByRole('checkbox', { name: 'No expiry' });
await fireEvent.click(noExpiry);
await markAsPublish();
await fireEvent.click(saveButton);
await waitFor(() => {
expect(
getByText('File display text is required.'),
).toBeInTheDocument();
});
});
});
Expand Down

0 comments on commit d249dbd

Please sign in to comment.