-
Notifications
You must be signed in to change notification settings - Fork 265
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
1 parent
30b2b2f
commit 9a5836c
Showing
21 changed files
with
276 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import * as React from "react"; | ||
import { mount, ReactWrapper } from "enzyme"; | ||
import { css } from "@emotion/core"; | ||
import { matchers } from "jest-emotion"; | ||
expect.extend(matchers); | ||
|
||
import ClockLoader from "../src/ClockLoader"; | ||
import { LoaderSizeProps } from "../src/interfaces"; | ||
import { sizeDefaults } from "../src/helpers"; | ||
|
||
describe("ClockLoader", () => { | ||
let loader: ReactWrapper<LoaderSizeProps, null, ClockLoader>; | ||
let props: LoaderSizeProps; | ||
let defaultColor: string = "#000000"; | ||
let defaultSize: number = 50; | ||
let defaultUnit: string = "px"; | ||
|
||
it("should match snapshot", () => { | ||
loader = mount(<ClockLoader />); | ||
expect(loader).toMatchSnapshot(); | ||
}); | ||
|
||
it("should contain default props if no props are passed", () => { | ||
props = loader.props(); | ||
expect(props).toEqual(sizeDefaults(defaultSize)); | ||
}); | ||
|
||
it("should contain styles created using default props", () => { | ||
expect(loader).toHaveStyleRule("height", `${defaultSize}${defaultUnit}`); | ||
expect(loader).toHaveStyleRule("width", `${defaultSize}${defaultUnit}`); | ||
expect(loader).toHaveStyleRule("box-shadow", `inset 0px 0px 0px 2px ${defaultColor}`); | ||
}); | ||
|
||
it("should render null if loading prop is set as false", () => { | ||
loader = mount(<ClockLoader loading={false} />); | ||
expect(loader.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
it("should render the correct color based on prop", () => { | ||
let color: string = "#e2e2e2"; | ||
loader = mount(<ClockLoader color={color} />); | ||
expect(loader).not.toHaveStyleRule("box-shadow", `inset 0px 0px 0px 2px ${defaultColor}`); | ||
expect(loader).toHaveStyleRule("box-shadow", `inset 0px 0px 0px 2px ${color}`); | ||
}); | ||
|
||
describe("size prop", () => { | ||
it("should render the size with px unit when size is a number", () => { | ||
let size: number = 18; | ||
loader = mount(<ClockLoader size={size} />); | ||
expect(loader).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`); | ||
expect(loader).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`); | ||
|
||
expect(loader).toHaveStyleRule("height", `${size}${defaultUnit}`); | ||
expect(loader).toHaveStyleRule("width", `${size}${defaultUnit}`); | ||
}); | ||
|
||
it("should render the size as is when size is a string with valid css unit", () => { | ||
let size: string = "18px"; | ||
loader = mount(<ClockLoader size={size} />); | ||
expect(loader).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`); | ||
expect(loader).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`); | ||
|
||
expect(loader).toHaveStyleRule("height", `${size}`); | ||
expect(loader).toHaveStyleRule("width", `${size}`); | ||
}); | ||
|
||
it("should render the size with default unit of px when the unit is incorrect", () => { | ||
let length: number = 18; | ||
let unit: string = "ad"; | ||
let size: string = `${length}${unit}`; | ||
loader = mount(<ClockLoader size={size} />); | ||
expect(loader).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`); | ||
expect(loader).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`); | ||
|
||
expect(loader).toHaveStyleRule("height", `${length}${defaultUnit}`); | ||
expect(loader).toHaveStyleRule("width", `${length}${defaultUnit}`); | ||
}); | ||
}); | ||
|
||
describe("css prop", () => { | ||
it("should render the css override if a valid css string is passed in", () => { | ||
loader = mount(<ClockLoader css={"position: absolute; overflow: scroll;"} />); | ||
expect(loader).not.toHaveStyleRule("position", "relative"); | ||
expect(loader).toHaveStyleRule("position", "absolute"); | ||
expect(loader).toHaveStyleRule("overflow", "scroll"); | ||
}); | ||
|
||
it("should render the css override if the result of the emotion css function is passed in", () => { | ||
loader = mount( | ||
<ClockLoader | ||
css={css` | ||
position: absolute; | ||
overflow: scroll; | ||
`} | ||
/> | ||
); | ||
expect(loader).not.toHaveStyleRule("position", "relative"); | ||
expect(loader).toHaveStyleRule("position", "absolute"); | ||
expect(loader).toHaveStyleRule("overflow", "scroll"); | ||
}); | ||
}); | ||
}); |
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,70 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ClockLoader should match snapshot 1`] = ` | ||
@keyframes animation-0 { | ||
100% { | ||
-webkit-transform: rotate(360deg); | ||
-ms-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
@keyframes animation-0 { | ||
100% { | ||
-webkit-transform: rotate(360deg); | ||
-ms-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
.emotion-0 { | ||
position: relative; | ||
width: 50px; | ||
height: 50px; | ||
background-color: transparent; | ||
box-shadow: inset 0px 0px 0px 2px #000000; | ||
border-radius: 50%; | ||
} | ||
.emotion-0:after, | ||
.emotion-0:before { | ||
position: absolute; | ||
content: ""; | ||
background-color: #000000; | ||
} | ||
.emotion-0:after { | ||
width: 20.833333333333336px; | ||
height: 2px; | ||
top: 24px; | ||
left: 24px; | ||
-webkit-transform-origin: 1px 1px; | ||
-ms-transform-origin: 1px 1px; | ||
transform-origin: 1px 1px; | ||
-webkit-animation: animation-0 2s linear infinite; | ||
animation: animation-0 2s linear infinite; | ||
} | ||
.emotion-0:before { | ||
width: 16.666666666666668px; | ||
height: 2px; | ||
top: 24px; | ||
left: 24px; | ||
-webkit-transform-origin: 1px 1px; | ||
-ms-transform-origin: 1px 1px; | ||
transform-origin: 1px 1px; | ||
-webkit-animation: animation-0 8s linear infinite; | ||
animation: animation-0 8s linear infinite; | ||
} | ||
<Loader | ||
color="#000000" | ||
css="" | ||
loading={true} | ||
size={50} | ||
> | ||
<div | ||
className="emotion-0" | ||
/> | ||
</Loader> | ||
`; |
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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.