Skip to content

Commit b98f9e2

Browse files
authored
Implemented missing core tests
1 parent 5646886 commit b98f9e2

12 files changed

+418
-10
lines changed

src/column/Column.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import * as _React from "react";
33
import * as _StyledComponents from "styled-components";
44
// -------------------------------------------------------------------
55
import "../utils/bootstrap";
6+
import { InterpolationValue } from "styled-components";
7+
import ColumnProperties from "./ColumnProperties";
8+
import ColumnOrder from "./ColumnOrder";
9+
import ColumnSize from "./ColumnSize";
10+
import renderOrder from "./renderOrder";
11+
import renderSize from "./renderSize";
612
import {
713
breakpoints,
814
BreakpointValue,
915
BreakpointValues,
1016
PropertyValue
1117
} from "../media";
12-
import { InterpolationValue } from "styled-components";
13-
import { render } from "../utils";
1418
import { gutterWidth, styled, Theme } from "../theme";
15-
import ColumnProperties from "./ColumnProperties";
16-
import ColumnOrder from "./ColumnOrder";
17-
import ColumnSize from "./ColumnSize";
18-
import renderOrder from "./renderOrder";
19-
import renderSize from "./renderSize";
19+
import { render } from "../utils";
2020

2121
const Column = styled.div`
2222
position: relative;

src/column/renderOrder.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import renderOrder from "./renderOrder";
2+
3+
describe("renderOrder", () => {
4+
it("should render css for flex order (input: 'first')", () => {
5+
// arrange
6+
const input = "first";
7+
8+
// act
9+
const output = renderOrder(input);
10+
11+
// assert
12+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
13+
"-webkit-box-ordinal-group:0;-ms-flex-order:-1;order:-1;"
14+
);
15+
});
16+
17+
it("should render css for flex order (input: 0)", () => {
18+
// arrange
19+
const input = 0;
20+
21+
// act
22+
const output = renderOrder(input);
23+
24+
// assert
25+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
26+
"-webkit-box-ordinal-group:0;-ms-flex-order:-1;order:-1;"
27+
);
28+
});
29+
30+
it("should render css for flex order (input: 5)", () => {
31+
// arrange
32+
const input = 5;
33+
34+
// act
35+
const output = renderOrder(input);
36+
37+
// assert
38+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
39+
"-webkit-box-ordinal-group:5;-ms-flex-order:4;order:4;"
40+
);
41+
});
42+
43+
it("should render css for flex order (input: 'last')", () => {
44+
// arrange
45+
const input = "last";
46+
47+
// act
48+
const output = renderOrder(input);
49+
50+
// assert
51+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
52+
"-webkit-box-ordinal-group:13;-ms-flex-order:12;order:12;"
53+
);
54+
});
55+
56+
it("should render css for flex order (input: 13)", () => {
57+
// arrange
58+
const input = 13;
59+
60+
// act
61+
const output = renderOrder(input);
62+
63+
// assert
64+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
65+
"-webkit-box-ordinal-group:13;-ms-flex-order:12;order:12;"
66+
);
67+
});
68+
});

src/column/renderSize.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import renderSize from "./renderSize";
2+
3+
describe("renderSize", () => {
4+
it("should render css for flex size (input: 'auto')", () => {
5+
// arrange
6+
const input = "auto";
7+
8+
// act
9+
const output = renderSize(input);
10+
11+
// assert
12+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
13+
"-ms-flex-preferred-size:0;flex-basis:0;-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1;max-width:100%;"
14+
);
15+
});
16+
17+
it("should render css for flex size (input: 'none')", () => {
18+
// arrange
19+
const input = "none";
20+
21+
// act
22+
const output = renderSize(input);
23+
24+
// assert
25+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
26+
"-webkit-box-flex:0;-ms-flex:00auto;flex:00auto;width:auto;max-width:none;"
27+
);
28+
});
29+
30+
it("should render css for flex size (input: undefined)", () => {
31+
// arrange
32+
const input = undefined;
33+
34+
// act
35+
const output = renderSize(input);
36+
37+
// assert
38+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe("");
39+
});
40+
41+
it("should render css for flex size (input: 6)", () => {
42+
// arrange
43+
const input = 6;
44+
45+
// act
46+
const output = renderSize(input);
47+
48+
// assert
49+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe(
50+
"-webkit-box-flex:0;-ms-flex:0050.000000%;flex:0050.000000%;max-width:50.000000%;"
51+
);
52+
});
53+
});

src/container/renderWidth.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import renderWidth from "./renderWidth";
2+
3+
describe("renderWidth", () => {
4+
it("should render container width (input: 500)", () => {
5+
// arrange
6+
const input = 500;
7+
8+
// act
9+
const output = renderWidth(input);
10+
11+
// assert
12+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe("max-width:500px;");
13+
});
14+
15+
it("should render container width (input: undefined)", () => {
16+
// arrange
17+
const input = undefined;
18+
19+
// act
20+
const output = renderWidth(input);
21+
22+
// assert
23+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe("");
24+
});
25+
});

src/container/width.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import defaultWidth from "./defaultWidth";
2+
import width from "./width";
3+
4+
describe("width", () => {
5+
it("should get container width from the props", () => {
6+
// arrange
7+
const input = {
8+
width: { xs: 50 },
9+
theme: {
10+
containerWidth: { md: 100 }
11+
}
12+
};
13+
14+
// act
15+
const output = width(input);
16+
17+
// assert
18+
expect({ xs: 50 }).toEqual(output);
19+
});
20+
21+
it("should get container width from the theme", () => {
22+
// arrange
23+
const input = {
24+
theme: {
25+
containerWidth: { md: 100 }
26+
}
27+
};
28+
29+
// act
30+
const output = width(input);
31+
32+
// assert
33+
expect({ md: 100 }).toEqual(output);
34+
});
35+
36+
it("should get default container width (input: {})", () => {
37+
// arrange
38+
const input = {};
39+
40+
// act
41+
const output = width(input);
42+
43+
// assert
44+
expect(defaultWidth).toEqual(output);
45+
});
46+
47+
it("should get default container width (input: undefined)", () => {
48+
// arrange
49+
const input = undefined;
50+
51+
// act
52+
const output = width(input);
53+
54+
// assert
55+
expect(defaultWidth).toEqual(output);
56+
});
57+
});

src/container/width.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ import ContainerProperties from "./ContainerProperties";
33
import { BreakpointValues } from "../media";
44

55
export default (props?: ContainerProperties): BreakpointValues<number> => {
6-
return props!.width || props!.theme!.containerWidth || defaultWidth;
6+
return (
7+
(props &&
8+
(props!.width || (props.theme && props!.theme!.containerWidth))) ||
9+
defaultWidth
10+
);
711
};

src/media/breakpoints.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import breakpoints from "./breakpoints";
2+
import defaultBreakpoints from "./defaultBreakpoints";
3+
4+
describe("breakpoints", () => {
5+
it("should get breakpoints from the theme", () => {
6+
// arrange
7+
const input = {
8+
breakpoints: { phone: 30, tablet: 60 }
9+
};
10+
11+
// act
12+
const output = breakpoints(input);
13+
14+
// assert
15+
expect({ phone: 30, tablet: 60 }).toEqual(output);
16+
});
17+
18+
it("should get default breakpoints (input: {})", () => {
19+
// arrange
20+
const input = {};
21+
22+
// act
23+
const output = breakpoints(input);
24+
25+
// assert
26+
expect(defaultBreakpoints).toEqual(output);
27+
});
28+
29+
it("should get default breakpoints (input: undefined)", () => {
30+
// arrange
31+
const input = undefined;
32+
33+
// act
34+
const output = breakpoints(input);
35+
36+
// assert
37+
expect(defaultBreakpoints).toEqual(output);
38+
});
39+
});

src/media/breakpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import defaultBreakpoints from "./defaultBreakpoints";
33
import { Theme } from "../theme";
44

55
export default (theme?: Theme): BreakpointMap => {
6-
return theme!.breakpoints || defaultBreakpoints;
6+
return (theme && theme!.breakpoints) || defaultBreakpoints;
77
};

src/row/renderNoGutter.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Module mocks must mocked before importing modules
2+
jest.mock("../utils/bootstrap", () => jest.fn());
3+
4+
import renderNoGutter from "./renderNoGutter";
5+
6+
describe("renderNoGutter", () => {
7+
it("should render container width (input: true)", () => {
8+
// arrange
9+
const input = true;
10+
11+
// act
12+
const output = renderNoGutter(input);
13+
14+
// assert
15+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toMatch(
16+
/margin\-right:0;margin\-left:0;>.*?{padding\-right:0;padding\-left:0;}/gi
17+
);
18+
});
19+
20+
it("should render container width (input: false)", () => {
21+
// arrange
22+
const input = false;
23+
24+
// act
25+
const output = renderNoGutter(input);
26+
27+
// assert
28+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe("");
29+
});
30+
31+
it("should render container width (input: undefined)", () => {
32+
// arrange
33+
const input = undefined;
34+
35+
// act
36+
const output = renderNoGutter(input);
37+
38+
// assert
39+
expect(output.replace(/\n|\r|\s|\t/gi, "")).toBe("");
40+
});
41+
});

0 commit comments

Comments
 (0)