-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove Enzyme to IntentRedirect tests
- Loading branch information
Showing
2 changed files
with
65 additions
and
41 deletions.
There are no files selected for viewing
22 changes: 0 additions & 22 deletions
22
test/components/intents/__snapshots__/intentRedirect.spec.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,79 @@ | ||
'use strict' | ||
|
||
/* eslint-env jest */ | ||
|
||
import '@testing-library/jest-dom' | ||
import { render } from '@testing-library/react' | ||
import { IntentRedirect } from 'ducks/components/intents/IntentRedirect' | ||
import { shallow } from 'enzyme' | ||
import React from 'react' | ||
import { MemoryRouter, Route, Routes, Navigate } from 'react-router-dom' | ||
import { useLocation } from 'react-router-dom' | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useLocation: jest.fn() | ||
useLocation: jest.fn(), | ||
Navigate: jest.fn() | ||
})) | ||
|
||
describe('IntentRedirect component', () => { | ||
it('should be rendered correctly if url search provided', () => { | ||
useLocation.mockReturnValue({ search: '?doctype=io.cozy.apps' }) | ||
const component = shallow(<IntentRedirect />).getElement() | ||
expect(component).toMatchSnapshot() | ||
describe('IntentRedirect', () => { | ||
const renderWithRouter = () => { | ||
return render( | ||
<MemoryRouter> | ||
<Routes> | ||
<Route path="*" element={<IntentRedirect />} /> | ||
</Routes> | ||
</MemoryRouter> | ||
) | ||
} | ||
Navigate.mockImplementation(({ to }) => <a data-testid="Navigate" to={to} />) | ||
|
||
it('should redirect to install page if step is install', () => { | ||
useLocation.mockReturnValue({ search: '?slug=test-app&step=install' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute('to', '/discover/test-app/install') | ||
}) | ||
|
||
it('should be rendered correctly if search for slug', () => { | ||
useLocation.mockReturnValue({ search: '?slug=mock' }) | ||
const component = shallow(<IntentRedirect />).getElement() | ||
expect(component).toMatchSnapshot() | ||
it('should redirect to install page if step is update', () => { | ||
useLocation.mockReturnValue({ search: '?slug=test-app&step=update' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute('to', '/discover/test-app/install') | ||
}) | ||
|
||
it('should redirect to uninstall page if step is uninstall', () => { | ||
useLocation.mockReturnValue({ search: '?slug=test-app&step=uninstall' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute( | ||
'to', | ||
'/discover/test-app/uninstall' | ||
) | ||
}) | ||
|
||
it('should handle search param without value', () => { | ||
useLocation.mockReturnValue({ search: '?slug=mock&doctype' }) | ||
const component = shallow(<IntentRedirect />).getElement() | ||
expect(component).toMatchSnapshot() | ||
it('should redirect to permissions page if step is permissions', () => { | ||
useLocation.mockReturnValue({ search: '?slug=test-app&step=permissions' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute( | ||
'to', | ||
'/discover/test-app/permissions' | ||
) | ||
}) | ||
|
||
it('should redirect to app page if step is not provided', () => { | ||
useLocation.mockReturnValue({ search: '?slug=test-app' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute('to', '/discover/test-app') | ||
}) | ||
|
||
it('should redirect to discover page if slug is not provided', () => { | ||
useLocation.mockReturnValue({ search: '' }) | ||
const { getByTestId } = renderWithRouter() | ||
|
||
const navigateElement = getByTestId('Navigate') | ||
expect(navigateElement).toHaveAttribute('to', '/discover/') | ||
}) | ||
}) |