Builder: updated unit test handling non-existent resume

This commit is contained in:
gianantoniopini
2021-01-22 17:25:04 +01:00
parent dc18e84bc2
commit 9a7bdb188b
5 changed files with 26 additions and 4 deletions

View File

@ -2,7 +2,7 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import Constants from '../constants/auth'; import Constants from '../constants/auth';
import delay from '../utils/index'; import delay from '../../utils/index';
const singleton = Symbol(''); const singleton = Symbol('');
const singletonEnforcer = Symbol(''); const singletonEnforcer = Symbol('');

View File

@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import DatabaseConstants from '../constants/database'; import DatabaseConstants from '../constants/database';
import DataSnapshot from './dataSnapshot'; import DataSnapshot from './dataSnapshot';
import delay from '../utils/index'; import delay from '../../utils/index';
const parsePath = (path) => { const parsePath = (path) => {
if (!path) { if (!path) {

View File

@ -1,5 +1,7 @@
import React from 'react'; import React from 'react';
import delay from './utils/index';
const Gatsby = jest.requireActual('gatsby'); const Gatsby = jest.requireActual('gatsby');
const fluidImageShapes = [ const fluidImageShapes = [
@ -67,6 +69,14 @@ const useStaticQuery = () => ({
}, },
}); });
const defaultDelayInMilliseconds = 100;
const navigate = async () => {
await delay(defaultDelayInMilliseconds);
return Promise.resolve();
};
module.exports = { module.exports = {
...Gatsby, ...Gatsby,
graphql: jest.fn(), graphql: jest.fn(),
@ -76,6 +86,6 @@ module.exports = {
href: to, href: to,
}), }),
), ),
navigate: jest.fn(), navigate: jest.fn(navigate),
useStaticQuery, useStaticQuery,
}; };

View File

@ -89,15 +89,27 @@ describe('Builder', () => {
describe('handles errors', () => { describe('handles errors', () => {
describe('if resume does not exist', () => { describe('if resume does not exist', () => {
const waitForNavigateFunctionToHaveCompleted = async () => {
await waitFor(() => mockNavigateFunction.mock.results[0].value);
};
beforeEach(async () => { beforeEach(async () => {
await setup('xxxxxx', false, false); await setup('xxxxxx', false, false);
}); });
it('navigates to Dashboard', async () => { afterEach(async () => {
await waitForNavigateFunctionToHaveCompleted();
});
it('navigates to Dashboard and displays notification', async () => {
await waitFor(() => await waitFor(() =>
expect(mockNavigateFunction).toHaveBeenCalledTimes(1), expect(mockNavigateFunction).toHaveBeenCalledTimes(1),
); );
expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard'); expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard');
await waitFor(() => {
expect(screen.getByRole('alert')).toBeInTheDocument();
});
}); });
}); });
}); });