Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"@openstax/ts-utils": "^1.32.5",
"@playwright/test": "^1.25.0",
"@testing-library/dom": "^10.4.0",
"@types/dompurify": "^3.0.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/dompurify": "^3.0.0",
"@types/jest": "^28.1.4",
"@types/node": "^18.7.5",
"@types/node-fetch": "^2.6.2",
Expand Down
5 changes: 3 additions & 2 deletions src/components/HelpMenu/chatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const useChatController = (
popup.current = window.open(path, "_blank", options);

if (!popup.current) return;
const newWindow = popup.current;

/**
* Handles messages from the popup window.
Expand All @@ -152,7 +153,7 @@ export const useChatController = (
const { source, data: { type } } = e;

// Security: only process messages from our popup
if (source !== popup.current) return;
if (source !== newWindow) return;

if (type === "ready") init();
};
Expand All @@ -162,7 +163,7 @@ export const useChatController = (
* Cleans up event listeners when closed.
*/
const checkClosed = setInterval(() => {
if (popup.current?.closed) {
if (newWindow.closed) {
window.removeEventListener("message", handleMessage, false);
popup.current = null;
clearInterval(checkClosed);
Expand Down
193 changes: 0 additions & 193 deletions src/components/Pagination.tsx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was broken into three modules which are in the (new) Pagination directory. This file became index.tsx, with pieces extracted to be utils.ts and hooks.ts

This file was deleted.

Comment thread
RoyEJohnson marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render } from '@testing-library/react';
import { Pagination, LinkForPage } from "./Pagination";
import { Pagination, LinkForPage } from ".";
import { range } from './utils';

describe('Pagination', () => {
let root: HTMLElement;
Expand All @@ -10,11 +11,11 @@ describe('Pagination', () => {
document.body.append(root);
});

it('matches snapshot', () => {
it('matches snapshot; default href is "#"', () => {
render(<Pagination
currentPage={1} totalPages={10}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
<LinkForPage page={page} current={current} href="" />
}
/>, {container: root});
expect(document.body).toMatchSnapshot();
Expand All @@ -30,6 +31,17 @@ describe('Pagination', () => {
expect(document.body).toMatchSnapshot();
});

it('Shows paginationinfo', () => {
render(<Pagination
currentPage={5} totalPages={15} showFromEnd={1} showFromCurrent={1}
pageSize={5} totalItems={75}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
}
/>, {container: root});
expect(document.querySelector('.pagination-info')?.textContent).toBe('21-25 of 75');
});

it('grows to min size', () => {
render(<Pagination
currentPage={1} totalPages={10} showFromEnd={1} showFromCurrent={1}
Expand Down Expand Up @@ -59,4 +71,20 @@ describe('Pagination', () => {
/>, {container: root});
expect(document.body).toMatchSnapshot();
});

// This is a special case in adjustRangesToMeetMinimum
it('expands middle range to the left', () => {
render(<Pagination
currentPage={4} totalPages={10}
Page={({ page, current }) =>
<LinkForPage page={page} current={current} href="#" />
}
/>, {container: root});
});
});

describe('Pagination/utils', () => {
it('bounds-checks range', () => {
expect(range(10, 5)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Pagination, LinkForPage } from "./Pagination";
import { Pagination, LinkForPage } from ".";

export const Examples = () => {
const [currentPage, setCurrentPage] = React.useState(1);
Expand Down
Loading
Loading