-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added additional tests to bump test coverage
....
- Loading branch information
Showing
8 changed files
with
454 additions
and
1 deletion.
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
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,48 @@ | ||
import React, { ReactElement, useRef } from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { DATA_RMD_NOSCROLL } from "@react-md/utils"; | ||
|
||
import { FixedDialog, FixedDialogProps } from "../FixedDialog"; | ||
|
||
const noop = (): void => {}; | ||
|
||
function Test({ | ||
id = "dialog", | ||
"aria-label": ariaLabel = "Label", | ||
onRequestClose = noop, | ||
visible = false, | ||
children, | ||
...props | ||
}: Partial<FixedDialogProps>): ReactElement { | ||
const fixedTo = useRef<HTMLButtonElement>(null); | ||
return ( | ||
<> | ||
<button type="button" ref={fixedTo}> | ||
Fixed To | ||
</button> | ||
<FixedDialog | ||
{...props} | ||
id={id} | ||
aria-label={ariaLabel} | ||
visible={visible} | ||
onRequestClose={onRequestClose} | ||
fixedTo={fixedTo} | ||
> | ||
{children} | ||
</FixedDialog> | ||
</> | ||
); | ||
} | ||
|
||
describe("FixedDialog", () => { | ||
it("should disable the overlay and scroll lock behavior by default", () => { | ||
const onRequestClose = jest.fn(); | ||
const { baseElement } = render( | ||
<Test visible onRequestClose={onRequestClose} /> | ||
); | ||
|
||
expect(baseElement).toMatchSnapshot(); | ||
expect(document.body).not.toHaveAttribute(DATA_RMD_NOSCROLL); | ||
expect(onRequestClose).not.toBeCalled(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/dialog/src/__tests__/__snapshots__/FixedDialog.tsx.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FixedDialog should disable the overlay and scroll lock behavior by default 1`] = ` | ||
<body> | ||
<div> | ||
<button | ||
type="button" | ||
> | ||
Fixed To | ||
</button> | ||
</div> | ||
<span | ||
class="rmd-overlay rmd-overlay--visible rmd-overlay--clickable rmd-dialog-overlay appear appear-active" | ||
id="dialog-overlay" | ||
tabindex="-1" | ||
/> | ||
<div | ||
aria-label="Label" | ||
aria-modal="true" | ||
class="rmd-dialog rmd-dialog--fixed" | ||
id="dialog" | ||
role="dialog" | ||
tabindex="-1" | ||
/> | ||
</body> | ||
`; |
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,56 @@ | ||
import React, { ReactElement } from "react"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import { Table, TableProps } from "../Table"; | ||
import { TableHeader } from "../TableHeader"; | ||
import { TableRow } from "../TableRow"; | ||
import { TableCell } from "../TableCell"; | ||
import { TableBody } from "../TableBody"; | ||
import { TableContainer } from "../TableContainer"; | ||
|
||
function Test(props: TableProps): ReactElement { | ||
return ( | ||
<Table {...props}> | ||
<TableHeader> | ||
<TableRow> | ||
<TableCell header>Header</TableCell> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell>Cell 1</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
); | ||
} | ||
|
||
describe("Table", () => { | ||
it("should render correctly", () => { | ||
const { container, rerender } = render(<Test />); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<Test dense hAlign="right" />); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<Test lineWrap disableHover disableBorders />); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<Test vAlign="top" fullWidth />); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender( | ||
<TableContainer> | ||
<Test /> | ||
</TableContainer> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender( | ||
<TableContainer className="test"> | ||
<Test /> | ||
</TableContainer> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
225 changes: 225 additions & 0 deletions
225
packages/table/src/__tests__/__snapshots__/Table.tsx.snap
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,225 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Table should render correctly 1`] = ` | ||
<div> | ||
<table | ||
class="rmd-table" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header rmd-table-cell--no-wrap" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered rmd-tr--hoverable" | ||
> | ||
<td | ||
class="rmd-table-cell rmd-table-cell--no-wrap" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
`; | ||
|
||
exports[`Table should render correctly 2`] = ` | ||
<div> | ||
<table | ||
class="rmd-table rmd-table--dense" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header rmd-table-cell--right rmd-table-cell--no-wrap" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered rmd-tr--hoverable" | ||
> | ||
<td | ||
class="rmd-table-cell rmd-table-cell--right rmd-table-cell--no-wrap" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
`; | ||
|
||
exports[`Table should render correctly 3`] = ` | ||
<div> | ||
<table | ||
class="rmd-table" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr" | ||
> | ||
<td | ||
class="rmd-table-cell" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
`; | ||
|
||
exports[`Table should render correctly 4`] = ` | ||
<div> | ||
<table | ||
class="rmd-table rmd-table--full-width" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header rmd-table-cell--top rmd-table-cell--vertical rmd-table-cell--no-wrap" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered rmd-tr--hoverable" | ||
> | ||
<td | ||
class="rmd-table-cell rmd-table-cell--top rmd-table-cell--vertical rmd-table-cell--no-wrap" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
`; | ||
|
||
exports[`Table should render correctly 5`] = ` | ||
<div> | ||
<div | ||
class="rmd-table-container" | ||
> | ||
<table | ||
class="rmd-table" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header rmd-table-cell--no-wrap" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered rmd-tr--hoverable" | ||
> | ||
<td | ||
class="rmd-table-cell rmd-table-cell--no-wrap" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Table should render correctly 6`] = ` | ||
<div> | ||
<div | ||
class="rmd-table-container test" | ||
> | ||
<table | ||
class="rmd-table" | ||
> | ||
<thead | ||
class="rmd-thead" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered" | ||
> | ||
<th | ||
class="rmd-table-cell rmd-table-cell--header rmd-table-cell--no-wrap" | ||
scope="col" | ||
> | ||
Header | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="rmd-tbody" | ||
> | ||
<tr | ||
class="rmd-tr rmd-tr--bordered rmd-tr--hoverable" | ||
> | ||
<td | ||
class="rmd-table-cell rmd-table-cell--no-wrap" | ||
> | ||
Cell 1 | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
`; |
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,27 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import { SrOnly } from "../SrOnly"; | ||
|
||
describe("SrOnly", () => { | ||
it("should render correctly", () => { | ||
const { container, rerender } = render(<SrOnly>Some Text</SrOnly>); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<SrOnly focusable>Some Text</SrOnly>); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<SrOnly tabIndex={-1}>Some Text</SrOnly>); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender( | ||
<SrOnly tabIndex={-1} focusable> | ||
Some Text | ||
</SrOnly> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
|
||
rerender(<SrOnly component="div">Some Text</SrOnly>); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.