Skip to content

Commit 852f593

Browse files
committed
Cover instructor-resources-pane
1 parent beaf869 commit 852f593

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

src/app/pages/details/common/resource-box/resource-box-utils.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function encodeLocation(search: string) {
1818
}
1919

2020
export type ResourceData = {
21-
linkExternal: string;
22-
linkDocumentUrl: string;
21+
linkExternal?: string;
22+
linkDocumentUrl?: string;
2323
linkDocument?: {
2424
file: string;
2525
};
@@ -29,18 +29,18 @@ export type ResourceData = {
2929
heading: string;
3030
resourceCategory: string;
3131
resourceUnlocked: boolean;
32-
creatorFestResource: boolean;
32+
creatorFestResource?: boolean;
3333
description: string;
3434
comingSoonText?: string;
3535
};
3636
comingSoonText: string | null;
3737
videoReferenceNumber?: number | null;
3838
k12?: boolean;
3939
printLink: string | null;
40-
resourceUnlocked: boolean;
40+
resourceUnlocked?: boolean;
4141
lockedText?: string;
42-
resourceHeading: string;
43-
resourceDescription: string;
42+
resourceHeading?: string;
43+
resourceDescription?: string;
4444
featured?: boolean;
4545
};
4646

src/app/pages/details/phone-view/instructor-resources-pane/instructor-resources-pane.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useUserContext, {type UserStatus} from '~/contexts/user';
1010
import useWindowContext, {WindowContextProvider} from '~/contexts/window';
1111
import type {ContextValues} from '../../context';
1212
import './instructor-resources-pane.scss';
13+
import {assertNotNull} from '~/helpers/data';
1314

1415
export function InstructorResourcesPane({
1516
model,
@@ -62,7 +63,7 @@ export function InstructorResourcesPane({
6263
models={featuredModels}
6364
/>
6465
)}
65-
<a className="card filter-for-book" onClick={goToPartners}>
66+
<a className="card filter-for-book" href="/partners" onClick={goToPartners}>
6667
OpenStax Partners <FontAwesomeIcon icon={faSignOutAlt} />
6768
</a>
6869
<div
@@ -92,7 +93,7 @@ function StubUnlessDisplayed({
9293
const {innerWidth, scrollY} = useWindowContext();
9394

9495
React.useEffect(
95-
() => setY((y || ref.current?.getBoundingClientRect().y) ?? null),
96+
() => setY(y || assertNotNull(ref.current).getBoundingClientRect().y),
9697
[innerWidth, scrollY, y]
9798
);
9899

@@ -112,9 +113,6 @@ export default function LoadUserStatusThenInstructorPane({
112113
}) {
113114
const {userStatus} = useUserContext();
114115

115-
if (!userStatus) {
116-
return null;
117-
}
118116
return (
119117
<WindowContextProvider>
120118
<StubUnlessDisplayed model={model} userStatus={userStatus} />

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jest.mock('~/models/table-of-contents-html', () =>
2424
jest.fn().mockReturnValue(Promise.resolve({}))
2525
);
2626

27+
jest.spyOn(window, 'scrollBy').mockImplementation(() => null);
2728
jest.spyOn(DH, 'setPageTitleAndDescriptionFromBookData').mockReturnValue();
2829
const spyIsPolish = jest.spyOn($, 'isPolish');
2930
const spyWindowContext = jest.spyOn(WC, 'default');
@@ -152,11 +153,46 @@ describe('Details page', () => {
152153
);
153154
});
154155
it('renders only phone-view at phone width', async () => {
156+
jest.spyOn(RBU, 'useResources').mockReturnValue({
157+
bookVideoFacultyResources: [],
158+
bookFacultyResources: [
159+
{
160+
featured: true,
161+
linkText: 'Link text',
162+
comingSoonText: '',
163+
printLink: 'print-link',
164+
videoReferenceNumber: 13
165+
},
166+
{
167+
featured: false,
168+
linkText: 'Link text2',
169+
comingSoonText: '',
170+
printLink: 'print-link2',
171+
videoReferenceNumber: null,
172+
resource: {
173+
id: 1,
174+
heading: 'resource-heading',
175+
resourceCategory: 'any',
176+
resourceUnlocked: true,
177+
description: 'resource-description'
178+
}
179+
}
180+
]
181+
});
155182
spyWindowContext.mockReturnValue({innerWidth: 480} as any); // eslint-disable-line
156183
render(<Component />);
157184
await finishedRendering();
158185
expect(lengthOfView('phone')).toBe(346);
159186
expect(lengthOfView('bigger')).toBeUndefined();
187+
188+
jest.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({
189+
y: 100
190+
} as any); // eslint-disable-line
191+
await user.click(screen.getByRole('button', {name: 'Instructor resources updated'}));
192+
console.warn = jest.fn();
193+
await user.click(await screen.findByRole('link', {name: 'OpenStax Partners'}));
194+
expect(console.warn).toHaveBeenCalled();
195+
console.warn = saveWarn;
160196
});
161197
it('toggles authors at phone width', async () => {
162198
spyWindowContext.mockReturnValue({innerWidth: 480} as any); // eslint-disable-line

0 commit comments

Comments
 (0)