-
Notifications
You must be signed in to change notification settings - Fork 356
Remove withRouter (1/n)
#3007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Remove withRouter (1/n)
#3007
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d9f468b
Functionalize RandomKawaii
taneliang 44cd5ce
Functionalize KeyboardShortcuts
taneliang e125590
Functionalize ScrollToTop
taneliang 93bcb64
Functionalize AppShell
taneliang 6573396
Functionalize LessonTimetable
taneliang f5ccc16
Functionalize ModRegNotification
taneliang 4559d71
Add React Testing Library
taneliang 6b38102
Rewrite GlobalSearchContainer tests with RTL
taneliang 34c8bff
Introduce __TEST__ global var
taneliang 8846526
Test GlobalSearchContainer wrapped in withRouter and connect HOCs
taneliang 87ec3ac
Functionalize GlobalSearchContainer
taneliang 08d7e1f
Define new useMediaQuery hook to replace makeResponsive HOC
taneliang 2008c60
Make mockDom mock more robust; mock matchMedia in GlobalSearchContain…
taneliang aea48bb
Replace makeResponsive -> useMediaQuery in GlobalSearchContainer
taneliang 19e9e08
Fix LessonTimetable type error
taneliang b31bc83
Add @testing-library/* to Renovate test group
taneliang 10e4f49
Fix nits in css.ts
taneliang d925401
Migrate ScrollToTop from enzyme -> RTL
taneliang 6b84a2c
Fix nits
taneliang b675711
Split GlobalSearchContainer show many results test
taneliang 02e91a6
Fix review comments
taneliang fb67e1f
Define new, simpler useScrollToTopEffect hook to replace ScrollToTop
taneliang 2e4f29a
Nit: clarify useScrollToTopEffect useEffect comment
taneliang 8b0cf98
Nit: further clarify useScrollToTopEffect comments
taneliang f019ae1
Fix review comments
taneliang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,49 @@ | ||
| export default function mockDom() { | ||
| const nativeScrollTo = window.scrollTo; | ||
| const nativePerformance = window.performance; | ||
| const nativeMatchMedia = window.matchMedia; | ||
| const nativeScrollIntoView = Element.prototype.scrollIntoView; | ||
|
|
||
| export function mockDom() { | ||
| // Mock some of the DOM environment functions that are missing from JSDom | ||
| window.scrollTo = jest.fn(); | ||
|
|
||
| if (!window.performance) { | ||
| (window as any).performance = { now: jest.fn() }; | ||
| // @ts-expect-error We insist | ||
| window.performance = { now: jest.fn() }; | ||
| } | ||
|
|
||
| if (!window.matchMedia) { | ||
| (window as any).matchMedia = jest.fn(() => ({ matches: jest.fn(), addListener: jest.fn() })); | ||
| mockWindowMatchMedia(); | ||
| } | ||
|
|
||
| // JSDom does not stub scrollIntoView - https://github.com/jsdom/jsdom/issues/1695 | ||
| if (!Element.prototype.scrollIntoView) { | ||
| Element.prototype.scrollIntoView = jest.fn(); | ||
| } | ||
| } | ||
|
|
||
| export function mockDomReset() { | ||
| window.scrollTo = nativeScrollTo; | ||
|
|
||
| // @ts-expect-error We insist | ||
| window.performance = nativePerformance; | ||
|
|
||
| window.matchMedia = nativeMatchMedia; | ||
|
|
||
| Element.prototype.scrollIntoView = nativeScrollIntoView; | ||
| } | ||
|
|
||
| export function mockWindowMatchMedia(overrides: Partial<typeof window.matchMedia> = {}) { | ||
| // Source: https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | ||
| window.matchMedia = jest.fn((query) => ({ | ||
| matches: true, | ||
| media: query, | ||
| onchange: null, | ||
| addListener: jest.fn(), // deprecated | ||
| removeListener: jest.fn(), // deprecated | ||
| addEventListener: jest.fn(), | ||
| removeEventListener: jest.fn(), | ||
| dispatchEvent: jest.fn(), | ||
| ...overrides, | ||
| })); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,18 @@ | ||
| // Define media breakpoints | ||
| import json2mq, { QueryObject } from 'json2mq'; | ||
| import { entries } from 'lodash'; | ||
| import type { QueryObject } from 'json2mq'; | ||
|
|
||
| export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; | ||
|
|
||
| const breakpoints: { [breakpoint: string]: number } = { | ||
| // NOTE: Keep in sync with Bootstrap's breakpoints. | ||
| // Breakpoints at time of writing: https://getbootstrap.com/docs/4.5/layout/overview/ | ||
| const breakpoints = Object.freeze({ | ||
| xs: 0, | ||
| sm: 576, | ||
| md: 768, | ||
| lg: 992, | ||
| xl: 1200, | ||
| }; | ||
| }); | ||
| type Breakpoint = keyof typeof breakpoints; | ||
|
|
||
| function nextBreakpoint(size: Breakpoint): number | null | undefined { | ||
| const breakpointEntries = entries(breakpoints); | ||
| function nextBreakpoint(size: Breakpoint): number | null { | ||
|
taneliang marked this conversation as resolved.
Outdated
|
||
| const breakpointEntries = Object.entries(breakpoints); | ||
| const nextBreakpointIndex = | ||
| breakpointEntries.findIndex(([breakpoint]) => breakpoint === size) + 1; | ||
| if (nextBreakpointIndex >= breakpointEntries.length) return null; | ||
|
|
@@ -22,7 +21,7 @@ function nextBreakpoint(size: Breakpoint): number | null | undefined { | |
|
|
||
| export function breakpointDown(size: Breakpoint): QueryObject { | ||
| const nextSize = nextBreakpoint(size); | ||
| if (nextSize == null) return { all: true }; | ||
| if (nextSize === null) return { all: true }; | ||
| return { maxWidth: nextSize - 1 }; | ||
| } | ||
|
|
||
|
|
@@ -34,10 +33,6 @@ export function touchScreenOnly(): QueryObject { | |
| return { pointer: 'coarse' }; | ||
| } | ||
|
|
||
| export function queryMatch(query: QueryObject) { | ||
| return window.matchMedia(json2mq(query)); | ||
| } | ||
|
Comment on lines
-37
to
-39
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code originally used in module search before we moved to Elasticsearch |
||
|
|
||
| export function supportsCSSVariables() { | ||
| // Safari does not support supports('--var', 'red') | ||
| return CSS.supports && CSS.supports('(--var: red)'); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.