-
Notifications
You must be signed in to change notification settings - Fork 156
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
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
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,95 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
getTableCellRoleProps, | ||
getTableColHeaderRoleProps, | ||
getTableHeaderRowRoleProps, | ||
getTableRoleProps, | ||
getTableRowRoleProps, | ||
getTableWrapperRoleProps, | ||
} from '../table-role-helper'; | ||
|
||
test('non-scrollable table props', () => { | ||
const tableRole = 'table'; | ||
const ariaLabel = 'table'; | ||
const totalItemsCount = 5; | ||
|
||
const tableWrapper = getTableWrapperRoleProps({ tableRole, ariaLabel, isScrollable: false }); | ||
const tableProps = getTableRoleProps({ tableRole, ariaLabel, totalItemsCount }); | ||
|
||
expect(tableWrapper).toEqual({}); | ||
expect(tableProps).toEqual({ role: tableRole, 'aria-label': ariaLabel, 'aria-rowcount': 6 }); | ||
}); | ||
|
||
test('scrollable table props', () => { | ||
const tableRole = 'table'; | ||
const ariaLabel = 'table'; | ||
const totalItemsCount = 5; | ||
|
||
const tableWrapper = getTableWrapperRoleProps({ tableRole, ariaLabel, isScrollable: true }); | ||
const tableProps = getTableRoleProps({ tableRole, ariaLabel, totalItemsCount }); | ||
|
||
expect(tableWrapper).toEqual({ role: 'region', 'aria-label': ariaLabel, tabIndex: 0 }); | ||
expect(tableProps).toEqual({ role: tableRole, 'aria-label': ariaLabel, 'aria-rowcount': 6 }); | ||
}); | ||
|
||
test('non-scrollable grid props', () => { | ||
const tableRole = 'grid'; | ||
const ariaLabel = 'table'; | ||
const totalItemsCount = 5; | ||
|
||
const tableWrapper = getTableWrapperRoleProps({ tableRole, ariaLabel, isScrollable: false }); | ||
const tableProps = getTableRoleProps({ tableRole, ariaLabel, totalItemsCount }); | ||
|
||
expect(tableWrapper).toEqual({}); | ||
expect(tableProps).toEqual({ role: tableRole, 'aria-label': ariaLabel, tabIndex: -1, 'aria-rowcount': 6 }); | ||
}); | ||
|
||
test('scrollable grid props', () => { | ||
const tableRole = 'grid'; | ||
const ariaLabel = 'table'; | ||
const totalItemsCount = 5; | ||
|
||
const tableWrapper = getTableWrapperRoleProps({ tableRole, ariaLabel, isScrollable: true }); | ||
const tableProps = getTableRoleProps({ tableRole, ariaLabel, totalItemsCount }); | ||
|
||
expect(tableWrapper).toEqual({ role: 'region', 'aria-label': ariaLabel, tabIndex: 0 }); | ||
expect(tableProps).toEqual({ role: tableRole, 'aria-label': ariaLabel, tabIndex: -1, 'aria-rowcount': 6 }); | ||
}); | ||
|
||
test('table row and cell props', () => { | ||
const tableRole = 'table'; | ||
|
||
const headerRow = getTableHeaderRowRoleProps({ tableRole }); | ||
const headerCell1 = getTableColHeaderRoleProps({ tableRole, colIndex: 0, sortingStatus: 'ascending' }); | ||
const headerCell2 = getTableColHeaderRoleProps({ tableRole, colIndex: 1 }); | ||
const bodyRow = getTableRowRoleProps({ tableRole, rowIndex: 0 }); | ||
const bodyCell1 = getTableCellRoleProps({ tableRole, colIndex: 0, isRowHeader: true }); | ||
const bodyCell2 = getTableCellRoleProps({ tableRole, colIndex: 1 }); | ||
|
||
expect(headerRow).toEqual({}); | ||
expect(bodyRow).toEqual({}); | ||
expect(headerCell1).toEqual({ scope: 'col', 'aria-sort': 'ascending' }); | ||
expect(headerCell2).toEqual({ scope: 'col' }); | ||
expect(bodyCell1).toEqual({ scope: 'row' }); | ||
expect(bodyCell2).toEqual({}); | ||
}); | ||
|
||
test('grid row and cell props', () => { | ||
const tableRole = 'grid'; | ||
|
||
const headerRow = getTableHeaderRowRoleProps({ tableRole }); | ||
const headerCell1 = getTableColHeaderRoleProps({ tableRole, colIndex: 0, sortingStatus: 'ascending' }); | ||
const headerCell2 = getTableColHeaderRoleProps({ tableRole, colIndex: 1 }); | ||
const bodyRow = getTableRowRoleProps({ tableRole, rowIndex: 0 }); | ||
const bodyCell1 = getTableCellRoleProps({ tableRole, colIndex: 0, isRowHeader: true }); | ||
const bodyCell2 = getTableCellRoleProps({ tableRole, colIndex: 1 }); | ||
|
||
expect(headerRow).toEqual({ 'aria-rowindex': 1 }); | ||
expect(bodyRow).toEqual({ 'aria-rowindex': 2 }); | ||
expect(headerCell1).toEqual({ 'aria-colindex': 1, scope: 'col', 'aria-sort': 'ascending' }); | ||
expect(headerCell2).toEqual({ 'aria-colindex': 2, scope: 'col' }); | ||
expect(bodyCell1).toEqual({ 'aria-colindex': 1, scope: 'row' }); | ||
expect(bodyCell2).toEqual({ 'aria-colindex': 2 }); | ||
}); |