|
5 | 5 | * This software may be modified and distributed under the terms
|
6 | 6 | * of the MIT license. See the LICENSE file for details.
|
7 | 7 | */
|
8 |
| - |
9 |
| -/* tslint:disable: variable-name */ |
10 |
| - |
11 |
| -import * as rewire from "rewire"; |
12 | 8 | import { assert } from "chai";
|
| 9 | +import { CSSProperties } from "react"; |
13 | 10 |
|
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"; |
19 | 12 |
|
20 | 13 | 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 |
| - |
37 | 14 | 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 |
| - |
45 | 15 | it("should parse shorthand order", () => {
|
46 |
| - const config = transit("100px", 50, "linear", 30) as TransitionConfig; |
| 16 | + const config = transit("100px", 50, "linear", 30); |
47 | 17 | assert.strictEqual(config.value, "100px");
|
48 | 18 | assert.deepEqual(config.params, { duration: 50, timing: "linear", delay: 30 });
|
49 | 19 | });
|
50 | 20 |
|
51 | 21 | it("should use defaults", () => {
|
52 |
| - const params = { duration: 30 }; |
53 |
| - const config = transit("100px", params) as TransitionConfig; |
| 22 | + const config = transit("100px", 30); |
54 | 23 | assert.strictEqual(config.value, "100px");
|
55 | 24 | assert.deepEqual(config.params, { duration: 30, timing: "ease", delay: 0 });
|
56 | 25 | });
|
| 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 | + }); |
57 | 123 |
|
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"); |
65 | 126 | });
|
66 | 127 | });
|
67 | 128 | });
|
|
0 commit comments