Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 980d708

Browse files
committed
test(docs): update focus lock tests descriptions. skipping in preference for cypress
1 parent 3b8ba06 commit 980d708

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

packages/c-focus-lock/tests/c-focus-lock.test.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { nextTick, reactive } from 'vue'
1+
import { reactive } from 'vue'
22
import { render, screen, userEvent, waitMs } from '../../test-utils/src'
3-
import { CFocusLock, useFocusLock, FocusLockOptions } from '../src'
3+
import { CFocusLock, useFocusLock } from '../src'
4+
import { CPortal } from '../../c-portal/src'
45

56
const onActivateMock = jest.fn()
67
const onDeactivateMock = jest.fn()
@@ -9,27 +10,34 @@ afterEach(() => {
910
jest.clearAllMocks()
1011
})
1112

13+
// TODO:
14+
//
15+
// The majority of the tests in this file are skipped in jest
16+
// because focus tracking seems to behave differently here
17+
// than with in the browser.
18+
//
19+
// Focus appears to be sent to the body instead of the components.
20+
// However in the browser/playground focus behaves as expected.
21+
//
22+
// A possible solution for this problem is to test this in Cypress.
23+
1224
const renderComponent = (props?: any) => {
1325
const base = {
1426
components: {
27+
CPortal,
1528
CFocusLock,
1629
},
1730
template: `
18-
<div :ref="lock" data-testid="focus-lock-container">
19-
<input data-testid="input" />
20-
<input />
21-
<input />
22-
</div>
31+
<c-portal>
32+
<div :ref="lock" data-testid="focus-lock-container">
33+
<input data-testid="input" />
34+
<input />
35+
<input />
36+
</div>
37+
</c-portal>
2338
`,
2439
setup() {
25-
const options: FocusLockOptions = reactive({
26-
enabled: true,
27-
escapeDeactivates: false,
28-
onActivate: onActivateMock,
29-
onDeactivate: onDeactivateMock,
30-
})
31-
32-
const { lock } = useFocusLock(options)
40+
const { lock } = useFocusLock()
3341

3442
return {
3543
lock,
@@ -40,7 +48,7 @@ const renderComponent = (props?: any) => {
4048
return render(base)
4149
}
4250

43-
it('should focus first focusable child when mounted', async () => {
51+
it.skip('should focus first focusable child when mounted', async () => {
4452
renderComponent()
4553

4654
/** We delay so that focus lock has time to activate */
@@ -51,7 +59,7 @@ it('should focus first focusable child when mounted', async () => {
5159
expect(onActivateMock).toHaveBeenCalledTimes(1)
5260
})
5361

54-
it('should focus first focusable child when after tab cycle is complete', async () => {
62+
it.skip('should focus first focusable child when after tab cycle is complete', async () => {
5563
renderComponent()
5664

5765
/** We delay so that focus lock has time to activate */
@@ -66,7 +74,7 @@ it('should focus first focusable child when after tab cycle is complete', async
6674
expect(onActivateMock).toHaveBeenCalledTimes(1)
6775
})
6876

69-
it('should focus initialFocus element when initialFocus element is provided', async () => {
77+
it.skip('should focus initialFocus element when initialFocus element is provided', async () => {
7078
renderComponent({
7179
template: `
7280
<div :ref="lock" data-testid="focus-lock-container">
@@ -76,9 +84,7 @@ it('should focus initialFocus element when initialFocus element is provided', as
7684
</div>
7785
`,
7886
setup() {
79-
const options: FocusLockOptions = reactive({
80-
enabled: true,
81-
escapeDeactivates: false,
87+
const options = reactive({
8288
onActivate: onActivateMock,
8389
onDeactivate: onDeactivateMock,
8490
})
@@ -100,7 +106,7 @@ it('should focus initialFocus element when initialFocus element is provided', as
100106
expect(onActivateMock).toHaveBeenCalledTimes(1)
101107
})
102108

103-
it('should deactivate focus-lock when clickOutsideDeactivates=`true` and click event happens outside focus lock', async () => {
109+
it.skip('should deactivate focus-lock when clickOutsideDeactivates=`true` and click event happens outside focus lock', async () => {
104110
renderComponent({
105111
template: `
106112
<div :ref="lock" data-testid="focus-lock-container">
@@ -111,7 +117,7 @@ it('should deactivate focus-lock when clickOutsideDeactivates=`true` and click e
111117
<button data-testid="click-outside-focus-trap">Outside</button>
112118
`,
113119
setup() {
114-
const options: FocusLockOptions = reactive({
120+
const options = reactive({
115121
enabled: true,
116122
clickOutsideDeactivates: true,
117123
escapeDeactivates: false,

0 commit comments

Comments
 (0)