Skip to content

Commit dca7cc4

Browse files
committed
test: improved test coverage
1 parent c695f61 commit dca7cc4

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

src/discussions/discussions-home/DiscussionsConfirmEmailBanner.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DiscussionsConfirmEmailBanner = () => {
3131
const openConfirmModalButtonClick = () => {
3232
dispatch(sendAccountActivationEmail());
3333
openConfirmModal();
34+
closePageBanner();
3435
};
3536

3637
const userConfirmEmailButtonClick = () => {

src/discussions/discussions-home/DiscussionsConfirmEmailBanner.test.jsx

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,29 @@ describe('DiscussionsConfirmEmailBanner', () => {
6666
renderComponent();
6767
});
6868

69-
it('shows banner', async () => {
69+
it('shows banner and confirm now button', async () => {
7070
const banner = await screen.findByRole('alert');
7171
expect(banner.textContent).toContain('Remember to confirm');
72-
});
73-
74-
it('shows confirm now button', async () => {
7572
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
7673
expect(confirmButton).toBeInTheDocument();
7774
});
7875

79-
it('shows modal when confirm now button is clicked', async () => {
76+
it('opens modal, closes banner, and calls resend email API when confirm now button is clicked', async () => {
8077
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
8178
await act(async () => {
8279
fireEvent.click(confirmButton);
8380
});
8481
await waitFor(() => {
8582
const modal = screen.getByRole('dialog');
8683
expect(modal).toBeInTheDocument();
84+
const banner = screen.queryByRole('alert');
85+
expect(banner).not.toBeInTheDocument();
86+
expect(axiosMock.history.post.length).toBe(1);
87+
expect(axiosMock.history.post[0].url).toBe(resendEmailUrl);
8788
});
8889
});
8990

90-
it('shows modal header and body', async () => {
91+
it('shows modal header, body, image, and confirm email button and closes modal and banner on click', async () => {
9192
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
9293
await act(async () => {
9394
fireEvent.click(confirmButton);
@@ -97,38 +98,20 @@ describe('DiscussionsConfirmEmailBanner', () => {
9798
expect(modalHeader).toBeInTheDocument();
9899
const modalBody = screen.getByText(messages.confirmEmailModalBody.defaultMessage);
99100
expect(modalBody).toBeInTheDocument();
100-
});
101-
});
102-
103-
it('shows confirm image', async () => {
104-
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
105-
await act(async () => {
106-
fireEvent.click(confirmButton);
107-
});
108-
await waitFor(() => {
109101
const confirmImage = screen.getByRole('img', { name: messages.confirmEmailImageAlt.defaultMessage });
110102
expect(confirmImage).toBeInTheDocument();
111-
});
112-
});
113-
114-
it('shows confirm email button', async () => {
115-
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
116-
await act(async () => {
117-
fireEvent.click(confirmButton);
118-
});
119-
await waitFor(() => {
120103
const verifyButton = screen.getByRole('button', { name: messages.verifiedConfirmEmailButton.defaultMessage });
121104
expect(verifyButton).toBeInTheDocument();
105+
act(() => {
106+
fireEvent.click(verifyButton);
107+
});
122108
});
123-
});
124-
125-
it('calls resend email API when confirm now button is clicked', async () => {
126-
const confirmButton = await screen.findByRole('button', { name: messages.confirmNowButton.defaultMessage });
127-
await act(async () => {
128-
fireEvent.click(confirmButton);
109+
await waitFor(() => {
110+
const modal = screen.queryByRole('dialog');
111+
expect(modal).not.toBeInTheDocument();
112+
const banner = screen.queryByRole('alert');
113+
expect(banner).not.toBeInTheDocument();
129114
});
130-
await waitFor(() => expect(axiosMock.history.post.length).toBe(1));
131-
expect(axiosMock.history.post[0].url).toBe(resendEmailUrl);
132115
});
133116
});
134117
});

0 commit comments

Comments
 (0)