Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.11 #371

Merged
merged 47 commits into from
Feb 22, 2021
Merged

0.11 #371

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
54f9d4a
Update emotion to v11 (#329)
davidhu2000 Dec 30, 2020
3d97436
Update changelog for 0.11.0-alpha.1
davidhu2000 Dec 30, 2020
be6d99b
bump package.json version to 0.11.0-alpha.1
davidhu2000 Dec 30, 2020
c8f346b
Update readme usage section to use @emotion for plugin with emotion@11
davidhu2000 Dec 31, 2020
395b5af
Update changelog/ version for 0.11.0-alpha.2
davidhu2000 Dec 31, 2020
3404dda
Merge branch 'master' into 0.11
davidhu2000 Jan 2, 2021
c885778
Remove typo in tsconfig.build.json
davidhu2000 Jan 2, 2021
ba7e921
Merge branch 'master' into 0.11
davidhu2000 Jan 2, 2021
ca85022
Merge branch 'master' into 0.11
davidhu2000 Feb 13, 2021
836b4b9
Add speed multiplier to BarLoader (#364)
davidhu2000 Feb 21, 2021
26dd19f
clean up barLoader defaultProps (#365)
davidhu2000 Feb 21, 2021
d97fbbd
Update changelog for 0.11.0-alpha.4 and bump versino
davidhu2000 Feb 21, 2021
15609ff
Add clean command to alpha/beta publish
davidhu2000 Feb 21, 2021
b498240
Merge branch 'master' into 0.11
davidhu2000 Feb 21, 2021
8d96b2a
Refactor common specs to a helper (#366)
davidhu2000 Feb 21, 2021
4594814
Refactor speedMultiplierSpecs into common spec (#367)
davidhu2000 Feb 21, 2021
cb3b85a
Pulseloader speed multiplier (#368)
davidhu2000 Feb 21, 2021
6248014
Update changelog for 0.11.0-alpha.45and bump version
davidhu2000 Feb 21, 2021
7a602dc
create css prop shared specs (#369)
davidhu2000 Feb 21, 2021
33d160e
Add cssSpecs to BarLoader
davidhu2000 Feb 21, 2021
25cff86
Add macher extend to allow toHaveStyleRule
davidhu2000 Feb 21, 2021
7a8ef92
create shared length spec (#370)
davidhu2000 Feb 21, 2021
56bb844
Refactor BeatLoader to use shared specs for size and margin
davidhu2000 Feb 21, 2021
246a0bb
Refactors BounceLoader tests to used shared specs
davidhu2000 Feb 21, 2021
dbd5a46
Refactored CircleLoader tests to used shared specs
davidhu2000 Feb 21, 2021
5e98482
Refactor ClimbingBoxLoader to use shared specs
davidhu2000 Feb 21, 2021
1fab885
Refactor ClipLoader to use shared specs
davidhu2000 Feb 21, 2021
ba7eafb
Refactor to use shared spec: ClockLoader
davidhu2000 Feb 21, 2021
7cf59dd
Refactor to use shared spec: DotLoader
davidhu2000 Feb 21, 2021
b7ce735
Refactor to use shared spec: FadeLoader
davidhu2000 Feb 21, 2021
5f6a6bc
Refactor to use shared spec: GridLoader
davidhu2000 Feb 21, 2021
c363367
Refactor to use shared spec: HashLoader
davidhu2000 Feb 21, 2021
32a96c9
Fix typing issue on FadeLoader tests
davidhu2000 Feb 21, 2021
4a48755
Refactor to use shared spec: MoonLoader
davidhu2000 Feb 21, 2021
623d841
Refactor to use shared spec: PacmanLoader
davidhu2000 Feb 21, 2021
2e0ddb0
Clean up unused import in PacmanLoader
davidhu2000 Feb 22, 2021
00fa6a0
Refactor to use shared spec: PropagateLoader
davidhu2000 Feb 22, 2021
f7522c0
Refactor to use shared spec: PuffLoader
davidhu2000 Feb 22, 2021
3dda072
Refactor to use shared spec: PulseLoader
davidhu2000 Feb 22, 2021
59b8248
Update speedMultiplierSpecs describe block
davidhu2000 Feb 22, 2021
9624740
Refactor to use shared spec: RingLoader
davidhu2000 Feb 22, 2021
ff18bf6
Refactor to use shared spec: RiseLoader
davidhu2000 Feb 22, 2021
2ee0167
Refactor to use shared spec: RotateLoader
davidhu2000 Feb 22, 2021
1febdbf
Refactor to use shared spec: ScaleLoader
davidhu2000 Feb 22, 2021
5da92f7
Refactor to use shared spec: SkewLoader
davidhu2000 Feb 22, 2021
d2580eb
Refactor to use shared spec: SquareLoader
davidhu2000 Feb 22, 2021
0b39c07
Refactor to use shared spec: SyncLoader
davidhu2000 Feb 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"presets": ["@babel/preset-react", "@babel/preset-env"],
"plugins": [
"emotion",
"@emotion",
"@babel/plugin-transform-react-jsx",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-typescript"
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "@emotion"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## 0.11.0-alpha.5

- Implement `speedMultipler` prop to `PulseLoader`. This is done to test the API for a single loader before adding to the rest.

## 0.11.0-alpha.4

- Clean up `BarLoader` by marking the props using `Required` utility to avoid having to do `width || Loader.defaultProps.width`.

## 0.11.0-alpha.3

- Implement `speedMultipler` prop to `BarLoader`. This is done to test the API for a single loader before adding to the rest.

## 0.11.0-alpha.2

- Update readme usage section to use `@emotion` for `.babelrc` plugins

## 0.11.0-alpha.1

- updated emotion to v11. [PR #329](https://github.com/davidhu2000/react-spinners/pull/329)

## 0.10.6

- **bugfix**: Fixed MoonLoader display issue [#342](https://github.com/davidhu2000/react-spinners/pull/342)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ Each loader accepts a `loading` prop as a boolean. The loader will render `null`
```
{
"presets": ["@babel/preset-react", "@babel/preset-env"],
"plugins": ["emotion"]
"plugins": ["@emotion"]
}
```

### Example

```js
import { useState } from "react";
import { css } from "@emotion/core";
import { css } from "@emotion/react";
import ClipLoader from "react-spinners/ClipLoader";

// Can be a string as well. Need to ensure each key-value pair ends with ;
Expand Down Expand Up @@ -89,7 +89,7 @@ export default App;

```js
import React from "react";
import { css } from "@emotion/core";
import { css } from "@emotion/react";
import ClipLoader from "react-spinners/ClipLoader";

// Can be a string as well. Need to ensure each key-value pair ends with ;
Expand Down
133 changes: 41 additions & 92 deletions __tests__/BarLoader-tests.tsx
Original file line number Diff line number Diff line change
@@ -1,121 +1,70 @@
import * as React from "react";
import { mount, ReactWrapper } from "enzyme";
import { matchers } from "jest-emotion";
import { matchers } from "@emotion/jest";
expect.extend(matchers);

import BarLoader from "../src/BarLoader";
import { LoaderHeightWidthProps } from "../src/interfaces";
import { commonSpecs, cssSpecs, lengthSpecs, speedMultiplierSpecs } from "./sharedSpecs/";
import { heightWidthDefaults } from "../src/helpers";

describe("BarLoader", () => {
let loader: ReactWrapper<LoaderHeightWidthProps, null, BarLoader>;
let props: LoaderHeightWidthProps;
const defaultColor = "#000000";
const defaultHeight = 4;
const defaultWidth = 100;
const defaultUnit = "px";
const defaultSpeed = 2.1;
const defaultDelay = 1.15;

it("should match snapshot", () => {
loader = mount(<BarLoader />);
expect(loader).toMatchSnapshot();
});

it("should contain default props if no props are passed", () => {
props = loader.props();
expect(props).toEqual(heightWidthDefaults(defaultHeight, defaultWidth));
});
commonSpecs(BarLoader, heightWidthDefaults(defaultHeight, defaultWidth));
cssSpecs(BarLoader);

it("should contain styles created using default props", () => {
const loader = mount(<BarLoader />);
expect(loader).toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
expect(loader).toHaveStyleRule("width", `${defaultWidth}${defaultUnit}`);
expect(loader).toHaveStyleRule("background-color", "rgba(0,0,0,0.2)");
expect(loader).toHaveStyleRule("background-color", "rgba(0, 0, 0, 0.2)");
expect(loader.find("span span")).toHaveStyleRule("background-color", defaultColor);
expect(loader.find("span span")).toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
});

it("should render null if loading prop is set as false", () => {
loader = mount(<BarLoader loading={false} />);
expect(loader.isEmptyRender()).toBe(true);
});

it("should render the correct color based on passed in prop", () => {
const color = "#e2e2e2";
loader = mount(<BarLoader color={color} />);
expect(loader).not.toHaveStyleRule("background-color", "rgba(0,0,0,0.2)");
expect(loader).toHaveStyleRule("background-color", "rgba(226,226,226,0.2)");
const loader = mount(<BarLoader color={color} />);
expect(loader).not.toHaveStyleRule("background-color", "rgba(0, 0, 0, 0.2)");
expect(loader).toHaveStyleRule("background-color", "rgba(226, 226, 226, 0.2)");
expect(loader.find("span span")).toHaveStyleRule("background-color", color);
});

describe("height prop", () => {
it("should render the height with px unit when size is a number", () => {
const height = 10;
loader = mount(<BarLoader height={height} />);
expect(loader).not.toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
expect(loader).toHaveStyleRule("height", `${height}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule(
"height",
`${defaultHeight}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("height", `${height}${defaultUnit}`);
});

it("should render the height as is when height is a string with valid css unit", () => {
const height = "18%";
loader = mount(<BarLoader height={height} />);
expect(loader).not.toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
expect(loader).toHaveStyleRule("height", `${height}`);
expect(loader.find("span span")).not.toHaveStyleRule(
"height",
`${defaultHeight}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("height", `${height}`);
});

it("should render the height with default unit of px when the unit is incorrect", () => {
const length = 18;
const unit = "ad";
const height = `${length}${unit}`;
loader = mount(<BarLoader height={height} />);
expect(loader).not.toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
expect(loader).toHaveStyleRule("height", `${length}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule(
"height",
`${defaultHeight}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("height", `${length}${defaultUnit}`);
});
});

describe("width prop", () => {
it("should render the width with px unit when size is a number", () => {
const width = 10;
loader = mount(<BarLoader width={10} />);
expect(loader).not.toHaveStyleRule("width", `${defaultWidth}${defaultUnit}`);
expect(loader).toHaveStyleRule("width", `${width}${defaultUnit}`);
});
const heightExpectStatements = (loader: ReactWrapper, length: number, unit?: string) => {
expect(loader).not.toHaveStyleRule("height", `${defaultHeight}${defaultUnit}`);
expect(loader).toHaveStyleRule("height", `${length}${unit || defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule(
"height",
`${defaultHeight}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("height", `${length}${unit || defaultUnit}`);
};
lengthSpecs(BarLoader, "height", heightExpectStatements);

it("should render the height as is when height is a string with valid css unit", () => {
const width = "18%";
loader = mount(<BarLoader width={width} />);
expect(loader).not.toHaveStyleRule("width", `${defaultWidth}${defaultUnit}`);
expect(loader).toHaveStyleRule("width", `${width}`);
});
const widthExpectStatements = (loader: ReactWrapper, length: number, unit?: string) => {
expect(loader).not.toHaveStyleRule("width", `${defaultWidth}${defaultUnit}`);
expect(loader).toHaveStyleRule("width", `${length}${unit || defaultUnit}`);
};
lengthSpecs(BarLoader, "width", widthExpectStatements);

it("should render the width with default unit of px when the unit is incorrect", () => {
const length = 18;
const unit = "ad";
const width = `${length}${unit}`;
loader = mount(<BarLoader width={width} />);
expect(loader).not.toHaveStyleRule("width", `${defaultWidth}${defaultUnit}`);
expect(loader).toHaveStyleRule("width", `${length}${defaultUnit}`);
});
});

it("should render the css override based on props", () => {
loader = mount(<BarLoader css={"position: absolute; overflow: scroll;"} />);
expect(loader).not.toHaveStyleRule("position", "relative");
expect(loader).toHaveStyleRule("position", "absolute");
expect(loader).not.toHaveStyleRule("overflow", "hidden");
expect(loader).toHaveStyleRule("overflow", "scroll");
});
const speedMultiplierExpectStatements = (loader: ReactWrapper, multiplier: number) => {
expect(loader.find("span span").at(0)).toHaveStyleRule(
"animation",
expect.stringContaining(`${defaultSpeed * multiplier}s`)
);
expect(loader.find("span span").at(1)).toHaveStyleRule(
"animation",
expect.stringContaining(`${defaultSpeed * multiplier}s`)
);
expect(loader.find("span span").at(1)).toHaveStyleRule(
"animation",
expect.stringContaining(`${defaultDelay * multiplier}s`)
);
};
speedMultiplierSpecs(BarLoader, speedMultiplierExpectStatements);
});
112 changes: 22 additions & 90 deletions __tests__/BeatLoader-tests.tsx
Original file line number Diff line number Diff line change
@@ -1,117 +1,49 @@
import * as React from "react";
import { mount, ReactWrapper } from "enzyme";
import { matchers } from "jest-emotion";
import { matchers } from "@emotion/jest";
expect.extend(matchers);

import BeatLoader from "../src/BeatLoader";
import { LoaderSizeMarginProps } from "../src/interfaces";
import { sizeMarginDefaults } from "../src/helpers";
import { commonSpecs, cssSpecs, lengthSpecs } from "./sharedSpecs";

describe("BeatLoader", () => {
let loader: ReactWrapper<LoaderSizeMarginProps, null, BeatLoader>;
let props: LoaderSizeMarginProps;
const defaultColor = "#000000";
const defaultSize = 15;
const defaultMargin = 2;
const defaultUnit = "px";

it("should match snapshot", () => {
loader = mount(<BeatLoader />);
expect(loader).toMatchSnapshot();
});

it("should contain default props if no props are passed", () => {
props = loader.props();
expect(props).toEqual(sizeMarginDefaults(defaultSize));
});
commonSpecs(BeatLoader, sizeMarginDefaults(defaultSize));
cssSpecs(BeatLoader);

it("should contain styles created using default props", () => {
props = loader.props();
const loader = mount(<BeatLoader />);
expect(loader.find("span span")).toHaveStyleRule("height", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("width", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("margin", `${defaultMargin}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("background-color", defaultColor);
});

it("should render null if loading prop is set as false", () => {
loader = mount(<BeatLoader loading={false} />);
expect(loader.isEmptyRender()).toBe(true);
});

it("should render the correct color based on prop", () => {
loader = mount(<BeatLoader color="#e2e2e2" />);
const loader = mount(<BeatLoader color="#e2e2e2" />);
expect(loader.find("span span")).not.toHaveStyleRule("background-color", defaultColor);
expect(loader.find("span span")).toHaveStyleRule("background-color", "#e2e2e2");
});

describe("size prop", () => {
it("should render the size with px unit when size is a number", () => {
const size = 18;
loader = mount(<BeatLoader size={18} />);
expect(loader.find("span span")).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("height", `${size}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("width", `${size}${defaultUnit}`);
});

it("should render the size as is when size is a string with valid css unit", () => {
const size = "18px";
loader = mount(<BeatLoader size={size} />);
expect(loader.find("span span")).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("height", `${size}`);
expect(loader.find("span span")).toHaveStyleRule("width", `${size}`);
});

it("should render the size with default unit of px when the unit is incorrect", () => {
const length = 18;
const unit = "ad";
const size = `${length}${unit}`;
loader = mount(<BeatLoader size={size} />);
expect(loader.find("span span")).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("height", `${length}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("width", `${length}${defaultUnit}`);
});
});

describe("margin prop", () => {
it("should render the margin with px unit when margin is a number", () => {
const margin = 18;
loader = mount(<BeatLoader margin={18} />);
expect(loader.find("span span")).not.toHaveStyleRule(
"margin",
`${defaultMargin}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("margin", `${margin}${defaultUnit}`);
});

it("should render the margin as is when margin is a string with valid css unit", () => {
const margin = "18px";
loader = mount(<BeatLoader margin={margin} />);
expect(loader.find("span span")).not.toHaveStyleRule(
"margin",
`${defaultMargin}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("margin", `${margin}`);
});

it("should render the margin with default unit of px when the unit is incorrect", () => {
const length = 18;
const unit = "ad";
const margin = `${length}${unit}`;
loader = mount(<BeatLoader margin={margin} />);
expect(loader.find("span span")).not.toHaveStyleRule(
"margin",
`${defaultMargin}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("margin", `${length}${defaultUnit}`);
});
});

it("should render the css override based on props", () => {
loader = mount(<BeatLoader css={"position: absolute; overflow: scroll;"} />);
expect(loader).toHaveStyleRule("position", "absolute");
expect(loader).toHaveStyleRule("overflow", "scroll");
});
const sizeExpectStatements = (loader: ReactWrapper, length: number, unit?: string) => {
expect(loader.find("span span")).not.toHaveStyleRule("height", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).not.toHaveStyleRule("width", `${defaultSize}${defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("height", `${length}${unit || defaultUnit}`);
expect(loader.find("span span")).toHaveStyleRule("width", `${length}${unit || defaultUnit}`);
};
lengthSpecs(BeatLoader, "size", sizeExpectStatements);

const marginExpectStatements = (loader: ReactWrapper, length: number, unit?: string) => {
expect(loader.find("span span")).not.toHaveStyleRule(
"margin",
`${defaultMargin}${defaultUnit}`
);
expect(loader.find("span span")).toHaveStyleRule("margin", `${length}${unit || defaultUnit}`);
};
lengthSpecs(BeatLoader, "margin", marginExpectStatements);
});
Loading