Skip to content

Commit

Permalink
test: Lines routing test (#1367)
Browse files Browse the repository at this point in the history
* test: Lines routing test

Added an example test which uses MemoryRouter to allow for testing of "to" buttons

* build: Bump dependency on stripes-erm-testing to 3.0.0
  • Loading branch information
EthanFreestone authored Nov 5, 2024
1 parent f89b838 commit 1dd4346
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@folio/stripes-acq-components": "^6.0.0",
"@folio/stripes-cli": "^3.2.0",
"@folio/stripes-erm-components": "^9.2.0",
"@folio/stripes-erm-testing": "^2.2.1",
"@folio/stripes-erm-testing": "^3.0.0",
"@formatjs/cli": "^6.1.3",
"classnames": ">=2.2.6",
"core-js": "^3.6.1",
Expand Down
97 changes: 82 additions & 15 deletions src/components/AgreementSections/Lines/Lines.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@

import { waitFor } from '@folio/jest-config-stripes/testing-library/react';
import { Accordion, Button, MultiColumnList, renderWithIntl } from '@folio/stripes-erm-testing';
import { MemoryRouter } from 'react-router-dom';
import { Accordion, Button, renderWithIntl } from '@folio/stripes-erm-testing';
import { MemoryRouter, Switch, Route } from 'react-router-dom';
import translationsProperties from '../../../../test/helpers';
import Lines from './Lines';
import { agreement, handlers } from './testResources';

jest.mock('../CoveredEResourcesList', () => () => (
<div>CoveredEResourcesList</div>
));

jest.mock('../LinesList', () => () => (
<div>LinesList</div>
));

describe('Lines', () => {
let renderComponent;
beforeEach(() => {
renderWithIntl(
renderComponent = renderWithIntl(
/* EXAMPLE testing "to" redirects using memory router */
<MemoryRouter>
<Lines
agreement={agreement}
handlers={handlers}
/>
<Switch>
<Route path="/erm/agreements/:agreementId/line/create">
Create agreement line
</Route>
<Route path="/erm/agreementLines">
View agreement lines
</Route>
<Route path="/">
<Lines
agreement={agreement}
handlers={handlers}
/>
</Route>
</Switch>
</MemoryRouter>,
translationsProperties
);
Expand All @@ -23,10 +43,27 @@ describe('Lines', () => {
await Accordion('Agreement lines').exists();
});

describe('Actions menu', () => {
test('renders LinesList component', async () => {
const { getByText } = renderComponent;
await waitFor(() => {
expect(getByText('LinesList')).toBeInTheDocument();
});
});

test('renders CoveredEResourcesList component', async () => {
const { getByText } = renderComponent;
await waitFor(() => {
expect(getByText('CoveredEResourcesList')).toBeInTheDocument();
});
});

test('actions menu exists', async () => {
await Button('Actions').exists();
});

describe('opening actions menu', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('Actions').exists();
await Button('Actions').click();
});
});
Expand All @@ -42,13 +79,43 @@ describe('Lines', () => {
await Button('View in agreement lines search').exists();
});
});
});

test('renders Lines list MCL', async () => {
await MultiColumnList('agreement-lines').exists();
});
test('renders ColumnManagerMenu component', async () => {
const { getByText } = renderComponent;
await waitFor(() => {
expect(getByText('ColumnManagerMenu')).toBeInTheDocument();
});
});


describe('clicking new agreement line button', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('New agreement line').click();
});
});

test('redirected to agreement line screen', async () => {
const { getByText } = renderComponent;
await waitFor(async () => {
expect(getByText('Create agreement line')).toBeInTheDocument();
});
});
});

describe('clicking view in agreement lines search button', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('View in agreement lines search').click();
});
});

test('renders covered e-resources MCL', async () => {
await MultiColumnList('eresources-covered').exists();
test('redirected to agreement line screen', async () => {
const { getByText } = renderComponent;
await waitFor(async () => {
expect(getByText('View agreement lines')).toBeInTheDocument();
});
});
});
});
});

0 comments on commit 1dd4346

Please sign in to comment.