From a24189dd716e0e3578e4931d601296e287a2cc82 Mon Sep 17 00:00:00 2001 From: Jacob Daniel Franklin Date: Wed, 7 Jul 2021 17:15:37 -0700 Subject: [PATCH 1/4] test(Scenarios): make tests more extensible --- .../app/components/Scenarios.spec.jsx | 47 ++++++++++++------- .../__snapshots__/Scenarios.spec.jsx.snap | 1 + 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/parrot-devtools/__tests__/app/components/Scenarios.spec.jsx b/packages/parrot-devtools/__tests__/app/components/Scenarios.spec.jsx index f752ebc4..19a9187e 100644 --- a/packages/parrot-devtools/__tests__/app/components/Scenarios.spec.jsx +++ b/packages/parrot-devtools/__tests__/app/components/Scenarios.spec.jsx @@ -19,6 +19,17 @@ import { shallow } from 'enzyme'; import ScenariosMiddleware from '../../../src/app/components/Scenarios'; +const scenario = 'api-fetch'; +const setScenario = jest.fn(() => Promise.resolve()); +const scenariosData = { + scenario, + setScenario, + loading: false, + filteredScenarios: [{ name: scenario }, { name: 'scenario-2' }], + loadScenarios: jest.fn(() => Promise.resolve()), +}; +const mockProps = { scenariosData }; + describe('Scenarios', () => { beforeEach(() => { jest.clearAllMocks(); @@ -26,20 +37,7 @@ describe('Scenarios', () => { describe('ScenariosMiddleware', () => { it('should render scenarios middleware component', () => { - const scenario = 'api-fetch'; - const setScenario = jest.fn(() => Promise.resolve()); - - const result = shallow( - Promise.resolve()), - }} - /> - ); + const result = shallow(); expect(result).toMatchSnapshot(); @@ -47,19 +45,32 @@ describe('Scenarios', () => { .find('button') .first() .simulate('click'); + expect(setScenario).toHaveBeenCalledWith(scenario); }); it('should loading state', () => { - const result = shallow(); + const props = { + scenariosData: { + ...scenariosData, + loading: true, + }, + }; + const result = shallow(); expect(result).toMatchSnapshot(); }); it('should inform the user of failure', () => { - const result = shallow( - - ); + const props = { + scenariosData: { + ...scenariosData, + loading: false, + scenario: '', + scenarios: [], + }, + }; + const result = shallow(); expect(result).toMatchSnapshot(); }); diff --git a/packages/parrot-devtools/__tests__/app/components/__snapshots__/Scenarios.spec.jsx.snap b/packages/parrot-devtools/__tests__/app/components/__snapshots__/Scenarios.spec.jsx.snap index 73538a5c..ee089ea8 100644 --- a/packages/parrot-devtools/__tests__/app/components/__snapshots__/Scenarios.spec.jsx.snap +++ b/packages/parrot-devtools/__tests__/app/components/__snapshots__/Scenarios.spec.jsx.snap @@ -21,6 +21,7 @@ exports[`Scenarios ScenariosMiddleware should inform the user of failure 1`] = ` Try