Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

Dashboard tests: added test for loading screen

gianantoniopini1215071ab96e
diff --git a/src/components/router/LoadingScreen.js b/src/components/router/LoadingScreen.js
index 19b6ec3ad..67e387318 100644
--- a/src/components/router/LoadingScreen.js
+++ b/src/components/router/LoadingScreen.js
@@ -4,7 +4,7 @@ import { getRandomTip } from '../../data/tips';
import Logo from '../shared/Logo';
const LoadingScreen = () => (
- <Modal open hideBackdrop>
+ <Modal data-testid="loading-screen" open hideBackdrop>
<Fade in>
<div className="w-screen h-screen flex justify-center items-center outline-none">
<div className="flex flex-col items-center">
diff --git a/src/pages/app/__tests__/dashboard.test.js b/src/pages/app/__tests__/dashboard.test.js
index 6ab6cf91b..93d1615e2 100644
--- a/src/pages/app/__tests__/dashboard.test.js
+++ b/src/pages/app/__tests__/dashboard.test.js
@@ -1,5 +1,10 @@
import React from 'react';
-import { act, render, screen, waitFor } from '@testing-library/react';
+import {
+ act,
+ render,
+ screen,
+ waitForElementToBeRemoved,
+} from '@testing-library/react';
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
@@ -16,8 +21,9 @@ import Dashboard from '../dashboard';
describe('Dashboard', () => {
let resumes = null;
const user = DatabaseConstants.user1;
+ const loadingScreenTestId = 'loading-screen';
- beforeEach(async () => {
+ async function setup(waitForLoadingScreenToDisappear) {
FirebaseStub.database().initializeData();
resumes = (
@@ -48,29 +54,51 @@ describe('Dashboard', () => {
await FirebaseStub.auth().signInAnonymously();
});
- await waitFor(() => screen.getByText('Create Resume'));
- });
+ if (waitForLoadingScreenToDisappear) {
+ await waitForElementToBeRemoved(() =>
+ screen.getByTestId(loadingScreenTestId),
+ );
+ }
+ }
- describe('renders', () => {
- it('document title', async () => {
- expect(document.title).toEqual('Dashboard | Reactive Resume');
+ describe('after loading', () => {
+ beforeEach(async () => {
+ await setup(true);
});
- it('create resume', async () => {
- expect(screen.getByText('Create Resume')).toBeInTheDocument();
+ describe('renders', () => {
+ it('document title', () => {
+ expect(document.title).toEqual('Dashboard | Reactive Resume');
+ });
+
+ it('create resume', () => {
+ expect(screen.getByText(/create resume/i)).toBeInTheDocument();
+ });
+
+ it('preview of user resumes', () => {
+ expect(Object.keys(resumes)).toHaveLength(2);
+
+ expect(Object.values(resumes)[0].user).toEqual(user.uid);
+ expect(
+ screen.getByText(Object.values(resumes)[0].name),
+ ).toBeInTheDocument();
+ expect(Object.values(resumes)[1].user).toEqual(user.uid);
+ expect(
+ screen.getByText(Object.values(resumes)[1].name),
+ ).toBeInTheDocument();
+ });
});
+ });
- it('preview of user resumes', async () => {
- expect(Object.keys(resumes)).toHaveLength(2);
+ describe('while loading', () => {
+ beforeEach(async () => {
+ await setup(false);
+ });
- expect(Object.values(resumes)[0].user).toEqual(user.uid);
- expect(
- screen.getByText(Object.values(resumes)[0].name),
- ).toBeInTheDocument();
- expect(Object.values(resumes)[1].user).toEqual(user.uid);
- expect(
- screen.getByText(Object.values(resumes)[1].name),
- ).toBeInTheDocument();
+ describe('renders', () => {
+ it('loading screen', () => {
+ expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
+ });
});
});
});