-
Notifications
You must be signed in to change notification settings - Fork 3
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
29 changed files
with
3,240 additions
and
4,224 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
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
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
File renamed without changes.
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,2 +1,2 @@ | ||
require("../../babel-register"); | ||
module.exports = require("./rollup.config.ts"); | ||
module.exports = require("./rollup-config.ts"); |
5 changes: 0 additions & 5 deletions
5
packages/kerosene-ui/src/ShowWhen/__snapshots__/index.spec.tsx.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,39 @@ | ||
import { shallow } from "enzyme"; | ||
import { render } from "@testing-library/react"; | ||
import * as React from "react"; | ||
import ShowWhen from "."; | ||
|
||
interface Case { | ||
name: string; | ||
when: boolean; | ||
children: React.ReactNode; | ||
} | ||
const text = "Test"; | ||
|
||
const cases: Case[] = [ | ||
{ | ||
name: "Should return Test as text", | ||
when: true, | ||
children: "Test", | ||
}, | ||
{ | ||
name: "Should return Test in a <span />", | ||
when: true, | ||
children: <span>Test</span>, | ||
}, | ||
{ | ||
name: "Should return null", | ||
when: false, | ||
children: "Test", | ||
}, | ||
]; | ||
describe("ShowWhen", () => { | ||
it.each([ | ||
{ | ||
name: "Should return Test as text", | ||
when: true, | ||
children: text, | ||
}, | ||
{ | ||
name: "Should return Test in a <span />", | ||
when: true, | ||
children: <span>{text}</span>, | ||
}, | ||
{ | ||
name: "Should return null", | ||
when: false, | ||
children: text, | ||
}, | ||
])("ShowWhen %j", ({ name, when, children }) => { | ||
const result = render(<ShowWhen when={when}>{children}</ShowWhen>); | ||
|
||
test.each(cases)("ShowWhen %j", ({ name, when, children }: Case) => { | ||
const wrapper = shallow(<ShowWhen when={when}>{children}</ShowWhen>); | ||
|
||
if (when === false) { | ||
expect(wrapper.getElement()).toBeNull(); | ||
} | ||
if (when === false) { | ||
expect(result.queryByText(text)).not.toBeInTheDocument(); | ||
} | ||
|
||
if (when === true) { | ||
expect(wrapper.text()).not.toBeNull(); | ||
expect(wrapper.text()).toMatchSnapshot(name); | ||
if (when === true) { | ||
expect(result.queryByText(text)).toBeInTheDocument(); | ||
|
||
if (typeof children === "string") { | ||
expect(wrapper.text()).not.toBeNull(); | ||
expect(wrapper.text()).toEqual(children); | ||
if (typeof children !== "string") { | ||
expect(result.container.querySelector("span")).toBeInTheDocument(); | ||
} | ||
} | ||
} | ||
}); | ||
}); |
30 changes: 8 additions & 22 deletions
30
packages/kerosene-ui/src/hooks/useAbortController.spec.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 |
---|---|---|
@@ -1,38 +1,24 @@ | ||
import { mount } from "enzyme"; | ||
import * as React from "react"; | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import useAbortController from "./useAbortController"; | ||
|
||
describe("#useAbortController", () => { | ||
it("should manage a series of AbortControllers", () => { | ||
const Component = ({ | ||
resultRef, | ||
}: { | ||
resultRef: React.MutableRefObject<ReturnType<typeof useAbortController>>; | ||
}) => { | ||
const result = useAbortController(); | ||
// eslint-disable-next-line no-param-reassign | ||
resultRef.current = result; | ||
return null; | ||
}; | ||
const result = ({ current: undefined } as Partial< | ||
React.MutableRefObject<ReturnType<typeof useAbortController>> | ||
>) as React.MutableRefObject<ReturnType<typeof useAbortController>>; | ||
const root = mount(<Component resultRef={result} />); | ||
expect(result.current.ref).toEqual({ current: undefined }); | ||
const utils = renderHook(() => useAbortController()); | ||
expect(utils.result.current.ref.current).toBe(undefined); | ||
|
||
const first = result.current.next(); | ||
const first = utils.result.current.next(); | ||
expect(first).toBeInstanceOf(AbortController); | ||
expect(first.signal.aborted).toBe(false); | ||
expect(result.current.ref.current).toBe(first); | ||
expect(utils.result.current.ref.current).toBe(first); | ||
|
||
const second = result.current.next(); | ||
const second = utils.result.current.next(); | ||
expect(second).toBeInstanceOf(AbortController); | ||
expect(second.signal.aborted).toBe(false); | ||
expect(result.current.ref.current).toBe(second); | ||
expect(utils.result.current.ref.current).toBe(second); | ||
|
||
expect(first.signal.aborted).toBe(true); | ||
|
||
root.unmount(); | ||
utils.unmount(); | ||
expect(second.signal.aborted).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.