Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 5e64742

Browse files
committed
Simplify transit and its processing
1 parent b0744b3 commit 5e64742

File tree

4 files changed

+136
-245
lines changed

4 files changed

+136
-245
lines changed

src/processstyle.spec.ts

-113
This file was deleted.

src/processstyle.ts

-62
This file was deleted.

src/transit.spec.ts

+103-42
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,124 @@
55
* This software may be modified and distributed under the terms
66
* of the MIT license. See the LICENSE file for details.
77
*/
8-
9-
/* tslint:disable: variable-name */
10-
11-
import * as rewire from "rewire";
128
import { assert } from "chai";
9+
import { CSSProperties } from "react";
1310

14-
import * as transitModule from "./transit";
15-
import { TransitionConfig } from "./transit";
16-
17-
const rewireModule = rewire("./transit");
18-
const { transit } = rewireModule as any as typeof transitModule;
11+
import { transit, resolveTransit } from "./transit";
1912

2013
describe("transit.ts", () => {
21-
let warning: string;
22-
let resetRewire: Function;
23-
24-
beforeEach(() => {
25-
resetRewire = rewireModule.__set__("warning", (condition: any, message: string) => {
26-
if (!condition) {
27-
warning = message;
28-
}
29-
});
30-
});
31-
32-
afterEach(() => {
33-
resetRewire();
34-
warning = undefined;
35-
});
36-
3714
describe("transit", () => {
38-
it("should parse parameter object", () => {
39-
const params = { duration: 50, timing: "linear", delay: 30 };
40-
const config = transit("100px", params) as TransitionConfig;
41-
assert.strictEqual(config.value, "100px");
42-
assert.deepEqual(config.params, params);
43-
});
44-
4515
it("should parse shorthand order", () => {
46-
const config = transit("100px", 50, "linear", 30) as TransitionConfig;
16+
const config = transit("100px", 50, "linear", 30);
4717
assert.strictEqual(config.value, "100px");
4818
assert.deepEqual(config.params, { duration: 50, timing: "linear", delay: 30 });
4919
});
5020

5121
it("should use defaults", () => {
52-
const params = { duration: 30 };
53-
const config = transit("100px", params) as TransitionConfig;
22+
const config = transit("100px", 30);
5423
assert.strictEqual(config.value, "100px");
5524
assert.deepEqual(config.params, { duration: 30, timing: "ease", delay: 0 });
5625
});
26+
});
27+
describe("resolveTransit()", () => {
28+
describe("when processing style with a single transition", () => {
29+
let style: CSSProperties;
30+
let result: CSSProperties;
31+
32+
before(() => {
33+
style = {
34+
width: transit("50px", 50, "ease", 20),
35+
height: "25px",
36+
};
37+
result = resolveTransit(style);
38+
});
39+
40+
it("should turn TransitionConfig to value", () => {
41+
assert.strictEqual(result.width, "50px");
42+
});
43+
44+
it("should set transition", () => {
45+
assert.strictEqual(result.transition, "width 50ms ease 20ms");
46+
});
47+
48+
it("should leave other properties untouched", () => {
49+
assert.strictEqual(result.height, "25px");
50+
});
51+
});
52+
53+
describe("when processing style with multiple transitions", () => {
54+
let style: CSSProperties;
55+
let result: CSSProperties;
56+
57+
before(() => {
58+
style = {
59+
width: transit("50px", 120, "ease", 30),
60+
background: transit("red", 100, "linear", 20),
61+
height: "25px",
62+
};
63+
result = resolveTransit(style);
64+
});
65+
66+
it("should turn TransitionConfig to value", () => {
67+
assert.strictEqual(result.width, "50px");
68+
assert.strictEqual(result.background, "red");
69+
});
70+
71+
it("should set transition", () => {
72+
assert.strictEqual(result.transition,
73+
"width 120ms ease 30ms, background 100ms linear 20ms");
74+
});
75+
76+
it("should leave other properties untouched", () => {
77+
assert.strictEqual(result.height, "25px");
78+
});
79+
});
80+
81+
describe("when processing style with single transition and vendor prefix", () => {
82+
let style: CSSProperties;
83+
let result: CSSProperties;
84+
85+
before(() => {
86+
style = {
87+
WebkitTransform: transit("50px", 50, "ease", 20),
88+
};
89+
result = resolveTransit(style);
90+
});
91+
92+
it("should turn TransitionConfig to value", () => {
93+
assert.strictEqual(result["WebkitTransform"], "50px");
94+
});
95+
96+
it("should set transition with css prefix", () => {
97+
assert.strictEqual(result.transition, "-webkit-transform 50ms ease 20ms");
98+
});
99+
});
100+
101+
describe("when processing style with extra delay", () => {
102+
let style: CSSProperties;
103+
let result: CSSProperties;
104+
105+
before(() => {
106+
style = {
107+
width: transit("50px", 120, "ease", 30),
108+
background: transit("red", 100, "linear", 20),
109+
height: "25px",
110+
};
111+
result = resolveTransit(style, 20);
112+
});
113+
114+
it("should turn TransitionConfig to value", () => {
115+
assert.strictEqual(result.width, "50px");
116+
assert.strictEqual(result.background, "red");
117+
});
118+
119+
it("should set transition", () => {
120+
assert.strictEqual(result.transition,
121+
"width 120ms ease 50ms, background 100ms linear 40ms");
122+
});
57123

58-
describe("when providing duration of invalid type", () => {
59-
it("should log warning", () => {
60-
for (const val of [undefined, "invalid"]) {
61-
transit("100px", val as any);
62-
assert.strictEqual(warning, "[react-css-transition] Invalid parameter '%s'.");
63-
warning = undefined;
64-
}
124+
it("should leave other properties untouched", () => {
125+
assert.strictEqual(result.height, "25px");
65126
});
66127
});
67128
});

0 commit comments

Comments
 (0)