Dashboard tests: added test for loading screen

This commit is contained in:
gianantoniopini
2021-01-20 14:27:27 +01:00
parent 3d39576a90
commit 1215071ab9
2 changed files with 50 additions and 22 deletions

View File

@ -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">

View File

@ -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,19 +54,28 @@ describe('Dashboard', () => {
await FirebaseStub.auth().signInAnonymously();
});
await waitFor(() => screen.getByText('Create Resume'));
if (waitForLoadingScreenToDisappear) {
await waitForElementToBeRemoved(() =>
screen.getByTestId(loadingScreenTestId),
);
}
}
describe('after loading', () => {
beforeEach(async () => {
await setup(true);
});
describe('renders', () => {
it('document title', async () => {
it('document title', () => {
expect(document.title).toEqual('Dashboard | Reactive Resume');
});
it('create resume', async () => {
expect(screen.getByText('Create Resume')).toBeInTheDocument();
it('create resume', () => {
expect(screen.getByText(/create resume/i)).toBeInTheDocument();
});
it('preview of user resumes', async () => {
it('preview of user resumes', () => {
expect(Object.keys(resumes)).toHaveLength(2);
expect(Object.values(resumes)[0].user).toEqual(user.uid);
@ -73,4 +88,17 @@ describe('Dashboard', () => {
).toBeInTheDocument();
});
});
});
describe('while loading', () => {
beforeEach(async () => {
await setup(false);
});
describe('renders', () => {
it('loading screen', () => {
expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
});
});
});
});