Skip to content
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

Frontend Tests, hooks and utils #437

Merged
merged 67 commits into from
Nov 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
77602a6
install vitest
austin-bagwell Aug 9, 2023
979283b
install jsdom
austin-bagwell Aug 9, 2023
57f531c
add test config object
austin-bagwell Aug 9, 2023
351e773
add tests folder
austin-bagwell Aug 9, 2023
f448bf2
errors - updated to use boilerplate vitest code
austin-bagwell Aug 9, 2023
45ba199
wrote test to test vitest functionality. is this recursive testing?
austin-bagwell Aug 10, 2023
e15f364
add testTimeout to test config
austin-bagwell Aug 10, 2023
7d86bd3
rename tests folder to __tests__
austin-bagwell Aug 10, 2023
f4234bb
remove extra 'tests' folder
austin-bagwell Aug 11, 2023
509be7f
basic tests for utils/errors.js
austin-bagwell Aug 12, 2023
c266b7a
create 'util' folder
austin-bagwell Aug 12, 2023
cdc36f8
add hasValidationsErrors test
austin-bagwell Aug 12, 2023
b5352b9
use vitest.spy for getErrorList - still fails test
austin-bagwell Aug 12, 2023
ec19ac0
attempt to render App inside a div container
austin-bagwell Aug 12, 2023
beaf354
add testing-library/react-hooks
austin-bagwell Aug 12, 2023
082b71b
add tests for useKeyPress
austin-bagwell Aug 12, 2023
a9f66cb
added testing-library/react-hooks
austin-bagwell Aug 12, 2023
63ff2ee
fixed getErrorList 'no error passed' test
austin-bagwell Aug 13, 2023
eb0ed8f
use vi.fn() to mock functions, passing all current tests
austin-bagwell Aug 13, 2023
b78e6fb
add basic vitest skeleton, not functional
austin-bagwell Aug 19, 2023
6417aac
hook sets state with initial window size
austin-bagwell Aug 23, 2023
75d023a
reword assertion
austin-bagwell Aug 23, 2023
7fcde98
render hook as result object - not functional yet
austin-bagwell Aug 24, 2023
935392e
put render into act() for app.test - not functional
austin-bagwell Aug 24, 2023
b99bd8f
Fix App test
robert-w-gries Sep 10, 2023
8fcc5f1
simulate clicks inside & outside element
austin-bagwell Sep 10, 2023
7026a0b
remove comments
austin-bagwell Sep 10, 2023
30ab241
Merge branch 'frontend_tests' into frontend_tests
austin-bagwell Sep 10, 2023
9bd8fe6
Merge pull request #3 from robert-w-gries/frontend_tests
austin-bagwell Sep 10, 2023
9249f44
merge rob's changes into frontend_tests
austin-bagwell Sep 10, 2023
e3a30d9
import render, waitFor from react testing lib
austin-bagwell Sep 10, 2023
c65c591
test mock userAgents
austin-bagwell Sep 16, 2023
cd8852e
add test that more closely mocks implementation
austin-bagwell Sep 16, 2023
82a04d5
reword assertion
austin-bagwell Sep 16, 2023
9394816
extract isChrome to function, test Mozilla userAgent, vendor
austin-bagwell Sep 16, 2023
36286d1
add chrome param to setWindowProps
austin-bagwell Sep 16, 2023
f88a929
add iPhone safari test, rm userAgent only tests
austin-bagwell Sep 16, 2023
a3ac796
update userAgent strings with MDN examples
austin-bagwell Sep 16, 2023
fd07355
update Chrome userAgent
austin-bagwell Sep 16, 2023
0d8cf4a
basic test outline - wip
austin-bagwell Sep 16, 2023
863515e
move setWindowProps into inner scope
austin-bagwell Sep 16, 2023
754c8cf
attempt to set multiple window properties
austin-bagwell Sep 16, 2023
293d4be
WIP - initial take on rendering hook
austin-bagwell Sep 20, 2023
109568f
check portal.id
austin-bagwell Sep 20, 2023
9020f70
add first successful debounce test
austin-bagwell Sep 24, 2023
da39c4f
add test where callback not called
austin-bagwell Sep 24, 2023
838f695
reword assertion
austin-bagwell Sep 24, 2023
6adb6d2
Merge branch 'master' into frontend_tests
austin-bagwell Sep 24, 2023
2e94714
remove test for useBrowserWarning
austin-bagwell Sep 26, 2023
aae1007
wip - assertions for window properties only
austin-bagwell Oct 1, 2023
c0fbd05
mock initial window size with vi.stubGlobal
austin-bagwell Oct 3, 2023
07769d8
add resize event test
austin-bagwell Oct 3, 2023
e64d303
action not triggered after hook unmounted
austin-bagwell Oct 5, 2023
40e3ac4
action not triggered after hook unmounted
austin-bagwell Oct 5, 2023
b0671a9
remove redundant assertion
austin-bagwell Oct 5, 2023
df06504
advance timer, add assertion that checks if callack is called
austin-bagwell Oct 5, 2023
1fca00d
reword test description
austin-bagwell Oct 5, 2023
9d9d5bb
add _arg to vi.fn()
austin-bagwell Oct 5, 2023
898b933
check that callback is called with specific arg
austin-bagwell Oct 5, 2023
65874d3
wip - using stubGlobal
austin-bagwell Oct 6, 2023
5e10d51
WIP - clean comments, test only Chrome, Mozilla
austin-bagwell Oct 8, 2023
9621ff3
Fix isChrome test
robert-w-gries Oct 10, 2023
194ab0b
npm run format
robert-w-gries Oct 11, 2023
43aec74
move initial window sizing to beforeEach
austin-bagwell Oct 10, 2023
4f2fba8
use outsideElement on hook unmount test
austin-bagwell Oct 14, 2023
9a63a2b
remove act(), make final assertions more comprehensive
austin-bagwell Oct 30, 2023
5f77ff9
remove redundant assertion
austin-bagwell Nov 5, 2023
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
39 changes: 20 additions & 19 deletions src/__tests__/hooks/useOnClickOutside.test.js
austin-bagwell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vi } from 'vitest';
import { act, renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react-hooks';
import useOnClickOutside from '../../hooks/useOnClickOutside';

describe('useOnClickOutside', () => {
Expand All @@ -9,16 +9,14 @@ describe('useOnClickOutside', () => {

renderHook(() => useOnClickOutside(ref, handler));

act(() => {
const outsideElement = document.createElement('div');
document.body.appendChild(outsideElement);
const outsideElement = document.createElement('div');
document.body.appendChild(outsideElement);

const event = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
});
outsideElement.dispatchEvent(event);
const event = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
});
outsideElement.dispatchEvent(event);

expect(handler).toHaveBeenCalled();
});
Expand All @@ -29,16 +27,14 @@ describe('useOnClickOutside', () => {

renderHook(() => useOnClickOutside(ref, handler));

act(() => {
const insideElement = document.createElement('div');
ref.current.appendChild(insideElement);
const insideElement = document.createElement('div');
ref.current.appendChild(insideElement);

const event = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
});
insideElement.dispatchEvent(event);
const event = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
});
insideElement.dispatchEvent(event);

expect(handler).not.toHaveBeenCalled();
});
Expand All @@ -56,9 +52,14 @@ describe('useOnClickOutside', () => {
bubbles: true,
cancelable: true,
});
unmount();

outsideElement.dispatchEvent(event);
expect(handler).toHaveBeenCalledTimes(1);

expect(handler).not.toHaveBeenCalled();
unmount();

outsideElement.dispatchEvent(event);
expect(handler).toHaveBeenCalledTimes(1);
expect(handler).not.toHaveBeenCalledTimes(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: if you've already checked it was called once, the second assert is redundant

});
});
Loading