Skip to content

Commit 65d1634

Browse files
committed
Test coverage for desktop-view
test coverage for instructor-resource-tab/partners
1 parent 5008c10 commit 65d1634

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

src/app/pages/details/desktop-view/instructor-resource-tab/partners/partners.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {useNavigate} from 'react-router-dom';
33
import PartnerCard from '~/components/partner-card/partner-card';
4+
import {assertNotNull} from '~/helpers/data';
45
import './partners.scss';
56

67
type PartnerBlurb = {
@@ -32,12 +33,10 @@ export default function Partners({
3233
(event: React.MouseEvent<HTMLAnchorElement>) => {
3334
const destUrl = event.currentTarget.getAttribute('href');
3435

35-
if (destUrl) {
36-
navigate(destUrl, {
37-
book: bookAbbreviation,
38-
redirect: true
39-
} as never);
40-
}
36+
navigate(assertNotNull(destUrl), {
37+
book: bookAbbreviation,
38+
redirect: true
39+
} as never);
4140
event.preventDefault();
4241
},
4342
[navigate, bookAbbreviation]

test/src/data/details-college-algebra.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,19 @@ const details = {
13131313
},
13141314
"partner_list_label": "Technology Partners",
13151315
"partner_page_link_text": "See all partners",
1316-
"videos": [],
1316+
"videos": [
1317+
{
1318+
"type": "video",
1319+
"value": [
1320+
{
1321+
"title": "Interface",
1322+
"description": "<p data-block-key=\"ftocg\">As the world’s largest producer of carpet tile and other flooring materials, Interface is everywhere. Their modular products foster a great degree of creativity and innovation in interior design and function, and allow their clients to have a positive impact on the world around them. Interface’s sustainability principles and initiatives -- Mission Zero and Climate Take Back -- have led to powerful community engagement and revolutionary technological enhancements.<br/><br/>This video is part of the OpenStax Business series, which showcases entrepreneurs and businesses with a focus on purpose, principles, and best business practices. It can be used with any OpenStax business textbook.</p>",
1323+
"embed": "<script src=\"https://fast.wistia.com/embed/medias/hyb2pj6nrg.jsonp\" async></script><script src=\"https://fast.wistia.com/assets/external/E-v1.js\" async></script><div class=\"wistia_embed wistia_async_hyb2pj6nrg\" style=\"height:360px;position:relative;width:640px\"><div class=\"wistia_swatch\" style=\"height:100%;left:0;opacity:0;overflow:hidden;position:absolute;top:0;transition:opacity 200ms;width:100%;\"><img src=\"https://fast.wistia.com/embed/medias/hyb2pj6nrg/swatch\" style=\"filter:blur(5px);height:100%;object-fit:contain;width:100%;\" alt=\"\" aria-hidden=\"true\" onload=\"this.parentNode.style.opacity=1;\" /></div></div>"
1324+
}
1325+
],
1326+
"id": "28d0ee63-04e0-4128-ba2b-9239b7da5e4e"
1327+
}
1328+
],
13171329
"promote_image": null,
13181330
"last_updated_pdf": null,
13191331
"featured_resources_header": null

test/src/pages/details/details.test.tsx

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ShellContextProvider from '~/../../test/helpers/shell-context';
88
import * as DH from '~/helpers/use-document-head';
99
import $ from '~/helpers/$';
1010
import * as WC from '~/contexts/window';
11+
import * as RBU from '~/pages/details/common/resource-box/resource-box-utils';
1112

1213
// Tamp down meaningless errors
1314
jest.mock('~/models/rex-release', () =>
@@ -27,10 +28,10 @@ jest.spyOn(DH, 'setPageTitleAndDescriptionFromBookData').mockReturnValue();
2728
const spyIsPolish = jest.spyOn($, 'isPolish');
2829
const spyWindowContext = jest.spyOn(WC, 'default');
2930

30-
function Component() {
31+
function Component({path='/details/books/college-algebra'}) {
3132
return (
3233
<ShellContextProvider>
33-
<MemoryRouter initialEntries={['/details/books/college-algebra']}>
34+
<MemoryRouter initialEntries={[path]}>
3435
<Routes>
3536
<Route
3637
path="/details/books/:title"
@@ -58,27 +59,70 @@ function lengthOfView(phoneOrBigger: string) {
5859
}
5960

6061
describe('Details page', () => {
62+
const user = userEvent.setup();
63+
6164
beforeEach(() => {
6265
document.head.innerHTML = '';
6366
const el = document.createElement('meta');
6467

6568
el.setAttribute('name', 'description');
6669
document.head.appendChild(el);
6770
});
71+
console.debug = jest.fn();
6872

69-
it('renders book', async () => {
73+
it('renders book with video data', async () => {
7074
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7175
spyWindowContext.mockReturnValue({innerWidth: 1280} as any);
7276
render(<Component />);
7377
await finishedRendering();
7478
expect(lengthOfView('phone')).toBeUndefined();
75-
expect(lengthOfView('bigger')).toBe(98);
79+
expect(lengthOfView('bigger')).toBe(794);
7680

7781
const jsonLdScript = document.head.querySelector('script');
7882

7983
expect(jsonLdScript?.textContent).toEqual(
8084
expect.stringContaining('mainEntity')
8185
);
86+
const tabs = screen.getAllByRole('tab');
87+
88+
expect(tabs).toHaveLength(4);
89+
// These do not seem to update the tab state as expected, though they
90+
// do exercise some code.
91+
await user.click(tabs[1]);
92+
});
93+
it('renders with Student tab selected', async () => {
94+
const mockLocation = jest.spyOn(window, 'location', 'get').mockReturnValue({
95+
...window.location,
96+
search: '?Student%20resources'
97+
});
98+
99+
render(<Component path='/details/books/biology-2e' />);
100+
const tabs = await screen.findAllByRole('tab');
101+
102+
expect(tabs[2].getAttribute('aria-selected')).toBe('true');
103+
await user.click(tabs[1]);
104+
mockLocation.mockRestore();
105+
});
106+
it('renders with Instructor tab selected', async () => {
107+
jest.spyOn(RBU, 'useResources').mockReturnValue({
108+
bookVideoFacultyResources: [],
109+
bookFacultyResources: []
110+
});
111+
const mockLocation = jest.spyOn(window, 'location', 'get').mockReturnValue({
112+
...window.location,
113+
search: '?Instructor%20resources'
114+
});
115+
116+
render(<Component />);
117+
await finishedRendering();
118+
const tabs = screen.getAllByRole('tab');
119+
120+
expect(tabs[1].getAttribute('aria-selected')).toBe('true');
121+
await user.click(tabs[2]);
122+
123+
screen.getByRole('heading', {name: 'Technology Partners'});
124+
await user.click(screen.getByRole('link', {name: 'MagicBox E-Reader'}));
125+
mockLocation.mockRestore();
82126
});
83127
it('renders Polish book', async () => {
84128
spyIsPolish.mockReturnValue(true);
@@ -116,7 +160,6 @@ describe('Details page', () => {
116160
await finishedRendering();
117161
const authorToggle = await screen.findByText('Authors');
118162
const detailsEl = authorToggle.closest('details');
119-
const user = userEvent.setup();
120163

121164
await user.click(authorToggle);
122165
expect(detailsEl?.open).toBe(true);

0 commit comments

Comments
 (0)