From ef3f2a802f46ec9d64eefc7ca48aa4d53daea263 Mon Sep 17 00:00:00 2001
From: gianantoniopini <63844628+gianantoniopini@users.noreply.github.com>
Date: Mon, 25 Jan 2021 15:15:02 +0100
Subject: [PATCH] Dashboard page: added first unit test for create resume
interaction
---
src/components/dashboard/CreateResume.js | 5 +++
src/pages/app/__tests__/dashboard.test.js | 41 +++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/src/components/dashboard/CreateResume.js b/src/components/dashboard/CreateResume.js
index 0f15b601..a1ec0b4e 100644
--- a/src/components/dashboard/CreateResume.js
+++ b/src/components/dashboard/CreateResume.js
@@ -5,6 +5,8 @@ import ModalContext from '../../contexts/ModalContext';
import { handleKeyUp } from '../../utils';
import styles from './CreateResume.module.css';
+const createResumeButtonDataTestId = 'create-resume-button';
+
const CreateResume = () => {
const { t } = useTranslation();
const { emitter, events } = useContext(ModalContext);
@@ -17,6 +19,7 @@ const CreateResume = () => {
{
};
export default memo(CreateResume);
+
+export { createResumeButtonDataTestId };
diff --git a/src/pages/app/__tests__/dashboard.test.js b/src/pages/app/__tests__/dashboard.test.js
index eede7d67..331f940b 100644
--- a/src/pages/app/__tests__/dashboard.test.js
+++ b/src/pages/app/__tests__/dashboard.test.js
@@ -14,6 +14,7 @@ import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
import '../../../i18n/index';
import '../../../utils/dayjs';
import { dataTestId as loadingScreenTestId } from '../../../components/router/LoadingScreen';
+import { createResumeButtonDataTestId } from '../../../components/dashboard/CreateResume';
import { menuToggleDataTestIdPrefix as resumePreviewMenuToggleDataTestIdPrefix } from '../../../components/dashboard/ResumePreview';
import { SettingsProvider } from '../../../contexts/SettingsContext';
import { ModalProvider } from '../../../contexts/ModalContext';
@@ -101,6 +102,46 @@ describe('Dashboard', () => {
});
});
+ describe('when resume is created', () => {
+ beforeEach(async () => {
+ await setup();
+
+ const dashboardCreateResumeButton = await screen.findByTestId(
+ createResumeButtonDataTestId,
+ );
+ fireEvent.click(dashboardCreateResumeButton);
+ });
+
+ describe('with name shorter than 5 characters', () => {
+ it('displays validation error and notification', async () => {
+ const nameTextBox = screen.getByRole('textbox', { name: /name/i });
+ fireEvent.change(nameTextBox, { target: { value: 'CV 1' } });
+
+ fireEvent.focusOut(nameTextBox);
+
+ await waitFor(() =>
+ expect(
+ screen.getByText(/Please enter at least 5 characters/i),
+ ).toBeInTheDocument(),
+ );
+
+ const modalCreateResumeButton = screen.getByRole('button', {
+ name: /create resume/i,
+ });
+ fireEvent.click(modalCreateResumeButton);
+
+ const notification = await screen.findByRole('alert');
+ expect(
+ getByText(
+ notification,
+ /You might need to fill up all the required fields/i,
+ ),
+ ).toBeInTheDocument();
+ fireEvent.click(notification);
+ });
+ });
+ });
+
describe('when resume is deleted', () => {
let mockDatabaseRemoveFunction = null;
let resumeToDelete = null;