-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Atlassian
authored and
AFP Repo Bot
committed
Dec 9, 2024
1 parent
005051e
commit e5fc976
Showing
13 changed files
with
240 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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,10 +1,14 @@ | ||
import * as liveRegion from '../../src'; | ||
import { screen } from '@testing-library/dom'; | ||
|
||
import { getLiveRegion } from './_utils'; | ||
import * as liveRegion from '../../src'; | ||
|
||
describe('DOM node', () => { | ||
it('should have role="alert"', () => { | ||
beforeEach(() => { | ||
liveRegion.cleanup(); | ||
}); | ||
|
||
it('should have role="status"', () => { | ||
liveRegion.announce('a message'); | ||
expect(getLiveRegion()).toHaveAttribute('role', 'alert'); | ||
expect(screen.getByRole('status')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Delay until the text content of the live region is updated. | ||
* | ||
* This value was reached through some experimentation, and may need tweaking in the future. | ||
*/ | ||
export const announceDelay = 1000; |
This file contains 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
52 changes: 52 additions & 0 deletions
52
packages/react-beautiful-dnd-migration/__tests__/unit/live-region.test.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { screen } from '@testing-library/dom'; | ||
|
||
import * as liveRegion from '../../src/drag-drop-context/live-region'; | ||
|
||
describe('live region', () => { | ||
beforeEach(() => { | ||
liveRegion.cleanup(); | ||
}); | ||
|
||
describe('announce', () => { | ||
it('should create a live region with role="alert"', () => { | ||
liveRegion.announce('a message'); | ||
expect(screen.getByRole('alert')).toHaveTextContent('a message'); | ||
}); | ||
|
||
it('should reuse an existing live region', () => { | ||
liveRegion.announce(''); | ||
const node = screen.getByRole('alert'); | ||
|
||
const msg1 = 'message #1'; | ||
liveRegion.announce(msg1); | ||
expect(node).toHaveTextContent(msg1); | ||
|
||
const msg2 = 'message #2'; | ||
liveRegion.announce(msg2); | ||
expect(node).toHaveTextContent(msg2); | ||
}); | ||
|
||
it('should not create more than one node at a time', () => { | ||
liveRegion.announce('one message'); | ||
liveRegion.announce('two message'); | ||
liveRegion.announce('red message'); | ||
liveRegion.announce('blue message'); | ||
|
||
expect(screen.getAllByRole('alert')).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('cleanup', () => { | ||
it('should do nothing if a node does not exist', () => { | ||
const snapshot = document.documentElement.outerHTML; | ||
liveRegion.cleanup(); | ||
expect(document.documentElement.outerHTML).toEqual(snapshot); | ||
}); | ||
|
||
it('should remove the live region node if it exists', () => { | ||
liveRegion.announce('a message'); | ||
liveRegion.cleanup(); | ||
expect(screen.queryByRole('alert')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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 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
Oops, something went wrong.