From 9a7bdb188b015ec133eee8171dd1276426d06b76 Mon Sep 17 00:00:00 2001 From: gianantoniopini <63844628+gianantoniopini@users.noreply.github.com> Date: Fri, 22 Jan 2021 17:25:04 +0100 Subject: [PATCH] Builder: updated unit test handling non-existent resume --- __mocks__/gatsby-plugin-firebase/auth/auth.js | 2 +- .../gatsby-plugin-firebase/database/reference.js | 2 +- __mocks__/gatsby.js | 12 +++++++++++- .../{gatsby-plugin-firebase => }/utils/index.js | 0 src/pages/app/__tests__/builder.test.js | 14 +++++++++++++- 5 files changed, 26 insertions(+), 4 deletions(-) rename __mocks__/{gatsby-plugin-firebase => }/utils/index.js (100%) diff --git a/__mocks__/gatsby-plugin-firebase/auth/auth.js b/__mocks__/gatsby-plugin-firebase/auth/auth.js index b27aaf10..fc5eb043 100644 --- a/__mocks__/gatsby-plugin-firebase/auth/auth.js +++ b/__mocks__/gatsby-plugin-firebase/auth/auth.js @@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid'; import Constants from '../constants/auth'; -import delay from '../utils/index'; +import delay from '../../utils/index'; const singleton = Symbol(''); const singletonEnforcer = Symbol(''); diff --git a/__mocks__/gatsby-plugin-firebase/database/reference.js b/__mocks__/gatsby-plugin-firebase/database/reference.js index 305c82b7..08e345fd 100644 --- a/__mocks__/gatsby-plugin-firebase/database/reference.js +++ b/__mocks__/gatsby-plugin-firebase/database/reference.js @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid'; import DatabaseConstants from '../constants/database'; import DataSnapshot from './dataSnapshot'; -import delay from '../utils/index'; +import delay from '../../utils/index'; const parsePath = (path) => { if (!path) { diff --git a/__mocks__/gatsby.js b/__mocks__/gatsby.js index e9339f5d..09ea71c7 100644 --- a/__mocks__/gatsby.js +++ b/__mocks__/gatsby.js @@ -1,5 +1,7 @@ import React from 'react'; +import delay from './utils/index'; + const Gatsby = jest.requireActual('gatsby'); const fluidImageShapes = [ @@ -67,6 +69,14 @@ const useStaticQuery = () => ({ }, }); +const defaultDelayInMilliseconds = 100; + +const navigate = async () => { + await delay(defaultDelayInMilliseconds); + + return Promise.resolve(); +}; + module.exports = { ...Gatsby, graphql: jest.fn(), @@ -76,6 +86,6 @@ module.exports = { href: to, }), ), - navigate: jest.fn(), + navigate: jest.fn(navigate), useStaticQuery, }; diff --git a/__mocks__/gatsby-plugin-firebase/utils/index.js b/__mocks__/utils/index.js similarity index 100% rename from __mocks__/gatsby-plugin-firebase/utils/index.js rename to __mocks__/utils/index.js diff --git a/src/pages/app/__tests__/builder.test.js b/src/pages/app/__tests__/builder.test.js index 55860935..cc9b80ef 100644 --- a/src/pages/app/__tests__/builder.test.js +++ b/src/pages/app/__tests__/builder.test.js @@ -89,15 +89,27 @@ describe('Builder', () => { describe('handles errors', () => { describe('if resume does not exist', () => { + const waitForNavigateFunctionToHaveCompleted = async () => { + await waitFor(() => mockNavigateFunction.mock.results[0].value); + }; + beforeEach(async () => { await setup('xxxxxx', false, false); }); - it('navigates to Dashboard', async () => { + afterEach(async () => { + await waitForNavigateFunctionToHaveCompleted(); + }); + + it('navigates to Dashboard and displays notification', async () => { await waitFor(() => expect(mockNavigateFunction).toHaveBeenCalledTimes(1), ); expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard'); + + await waitFor(() => { + expect(screen.getByRole('alert')).toBeInTheDocument(); + }); }); }); });