From 766f8636557b113757312be500df8d801c325122 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Tue, 15 Oct 2019 11:11:44 -0700 Subject: [PATCH] update ProjectDetails tests with memoryHistory --- .../ProjectDetail/ProjectDetail.test.jsx | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx index 8ec8858c67..ab9c024c7e 100644 --- a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx +++ b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import { createMemoryHistory } from 'history'; import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; import ProjectDetail from './ProjectDetail'; @@ -175,46 +176,26 @@ describe('', () => { }); test('edit button should navigate to project edit', () => { - const context = { - router: { - history: { - push: jest.fn(), - replace: jest.fn(), - createHref: jest.fn(), - }, - }, - }; + const history = createMemoryHistory(); const wrapper = mountWithContexts(, { - context, + context: { router: { history } }, }); expect(wrapper.find('Button[aria-label="edit"]').length).toBe(1); - expect(context.router.history.push).not.toHaveBeenCalled(); wrapper .find('Button[aria-label="edit"] Link') .simulate('click', { button: 0 }); - expect(context.router.history.push).toHaveBeenCalledWith( - '/projects/1/edit' - ); + expect(history.location.pathname).toEqual('/projects/1/edit'); }); test('close button should navigate to projects list', () => { - const context = { - router: { - history: { - push: jest.fn(), - replace: jest.fn(), - createHref: jest.fn(), - }, - }, - }; + const history = createMemoryHistory(); const wrapper = mountWithContexts(, { - context, + context: { router: { history } }, }); expect(wrapper.find('Button[aria-label="close"]').length).toBe(1); - expect(context.router.history.push).not.toHaveBeenCalled(); wrapper .find('Button[aria-label="close"] Link') .simulate('click', { button: 0 }); - expect(context.router.history.push).toHaveBeenCalledWith('/projects'); + expect(history.location.pathname).toEqual('/projects'); }); });