mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-19 03:01:53 +10:00
Dashboard tests: added test for loading screen
This commit is contained in:
@ -4,7 +4,7 @@ import { getRandomTip } from '../../data/tips';
|
|||||||
import Logo from '../shared/Logo';
|
import Logo from '../shared/Logo';
|
||||||
|
|
||||||
const LoadingScreen = () => (
|
const LoadingScreen = () => (
|
||||||
<Modal open hideBackdrop>
|
<Modal data-testid="loading-screen" open hideBackdrop>
|
||||||
<Fade in>
|
<Fade in>
|
||||||
<div className="w-screen h-screen flex justify-center items-center outline-none">
|
<div className="w-screen h-screen flex justify-center items-center outline-none">
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import React from 'react';
|
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';
|
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
|
||||||
|
|
||||||
@ -16,8 +21,9 @@ import Dashboard from '../dashboard';
|
|||||||
describe('Dashboard', () => {
|
describe('Dashboard', () => {
|
||||||
let resumes = null;
|
let resumes = null;
|
||||||
const user = DatabaseConstants.user1;
|
const user = DatabaseConstants.user1;
|
||||||
|
const loadingScreenTestId = 'loading-screen';
|
||||||
|
|
||||||
beforeEach(async () => {
|
async function setup(waitForLoadingScreenToDisappear) {
|
||||||
FirebaseStub.database().initializeData();
|
FirebaseStub.database().initializeData();
|
||||||
|
|
||||||
resumes = (
|
resumes = (
|
||||||
@ -48,29 +54,51 @@ describe('Dashboard', () => {
|
|||||||
await FirebaseStub.auth().signInAnonymously();
|
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', () => {
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renders', () => {
|
describe('while loading', () => {
|
||||||
it('document title', async () => {
|
beforeEach(async () => {
|
||||||
expect(document.title).toEqual('Dashboard | Reactive Resume');
|
await setup(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create resume', async () => {
|
describe('renders', () => {
|
||||||
expect(screen.getByText('Create Resume')).toBeInTheDocument();
|
it('loading screen', () => {
|
||||||
});
|
expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
|
||||||
|
});
|
||||||
it('preview of user resumes', async () => {
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user