mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 15:27:47 -02:30
update ProjectDetails tests with memoryHistory
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { createMemoryHistory } from 'history';
|
||||||
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||||
import ProjectDetail from './ProjectDetail';
|
import ProjectDetail from './ProjectDetail';
|
||||||
|
|
||||||
@@ -175,46 +176,26 @@ describe('<ProjectDetail />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('edit button should navigate to project edit', () => {
|
test('edit button should navigate to project edit', () => {
|
||||||
const context = {
|
const history = createMemoryHistory();
|
||||||
router: {
|
|
||||||
history: {
|
|
||||||
push: jest.fn(),
|
|
||||||
replace: jest.fn(),
|
|
||||||
createHref: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />, {
|
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />, {
|
||||||
context,
|
context: { router: { history } },
|
||||||
});
|
});
|
||||||
expect(wrapper.find('Button[aria-label="edit"]').length).toBe(1);
|
expect(wrapper.find('Button[aria-label="edit"]').length).toBe(1);
|
||||||
expect(context.router.history.push).not.toHaveBeenCalled();
|
|
||||||
wrapper
|
wrapper
|
||||||
.find('Button[aria-label="edit"] Link')
|
.find('Button[aria-label="edit"] Link')
|
||||||
.simulate('click', { button: 0 });
|
.simulate('click', { button: 0 });
|
||||||
expect(context.router.history.push).toHaveBeenCalledWith(
|
expect(history.location.pathname).toEqual('/projects/1/edit');
|
||||||
'/projects/1/edit'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('close button should navigate to projects list', () => {
|
test('close button should navigate to projects list', () => {
|
||||||
const context = {
|
const history = createMemoryHistory();
|
||||||
router: {
|
|
||||||
history: {
|
|
||||||
push: jest.fn(),
|
|
||||||
replace: jest.fn(),
|
|
||||||
createHref: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />, {
|
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />, {
|
||||||
context,
|
context: { router: { history } },
|
||||||
});
|
});
|
||||||
expect(wrapper.find('Button[aria-label="close"]').length).toBe(1);
|
expect(wrapper.find('Button[aria-label="close"]').length).toBe(1);
|
||||||
expect(context.router.history.push).not.toHaveBeenCalled();
|
|
||||||
wrapper
|
wrapper
|
||||||
.find('Button[aria-label="close"] Link')
|
.find('Button[aria-label="close"] Link')
|
||||||
.simulate('click', { button: 0 });
|
.simulate('click', { button: 0 });
|
||||||
expect(context.router.history.push).toHaveBeenCalledWith('/projects');
|
expect(history.location.pathname).toEqual('/projects');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user