Skip to content

Commit beaf869

Browse files
committed
Test coverage for desktop-view
test coverage for instructor-resource-tab/partners
1 parent 0fb6433 commit beaf869

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-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: 52 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,74 @@ function lengthOfView(phoneOrBigger: string) {
5859
}
5960

6061
describe('Details page', () => {
62+
const user = userEvent.setup();
63+
const saveWarn = console.warn;
64+
6165
beforeEach(() => {
6266
document.head.innerHTML = '';
6367
const el = document.createElement('meta');
6468

6569
el.setAttribute('name', 'description');
6670
document.head.appendChild(el);
6771
});
72+
console.debug = jest.fn();
6873

69-
it('renders book', async () => {
74+
it('renders book with video data', async () => {
7075
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7176
spyWindowContext.mockReturnValue({innerWidth: 1280} as any);
7277
render(<Component />);
7378
await finishedRendering();
7479
expect(lengthOfView('phone')).toBeUndefined();
75-
expect(lengthOfView('bigger')).toBe(98);
80+
expect(lengthOfView('bigger')).toBe(794);
7681

7782
const jsonLdScript = document.head.querySelector('script');
7883

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

121168
await user.click(authorToggle);
122169
expect(detailsEl?.open).toBe(true);

0 commit comments

Comments
 (0)