Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"eslint-config-prettier": "^2.1.0",
"eslint-plugin-prettier": "^2.0.1",
"husky": "^0.13.3",
"jest": "^19.0.2",
"jest": "^20.0.4",
"lint-staged": "^3.4.0",
"prettier": "^1.3.1"
},
Expand Down
6 changes: 3 additions & 3 deletions src/postcss/detectContainerDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { DEFINE_CONTAINER_NAME } from "../constants";

/**
* @param {Node} ruleNode
* @param {boolean} [removeDefiniton]
* @param {boolean} [removeDefinition]
*
* @returns {string|null}
*/
export default function detectContainerDefinition(
ruleNode,
removeDefiniton = true
removeDefinition = true
) {
let container = null;

Expand All @@ -24,7 +24,7 @@ export default function detectContainerDefinition(
}
}

if (removeDefiniton) {
if (removeDefinition) {
ruleNode.nodes.splice(i, 1);
}

Expand Down
16 changes: 16 additions & 0 deletions src/postcss/detectContainerDefinition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ test("Return null if no container definition was found", () => {

expect(detectContainerDefinition(ruleNode)).toBeNull();
});

test("should be able to keep container-definition when detected", () => {
const ruleNode = new Node({
selector: ".container"
})
.addNode(new Node({ type: "decl" }))
.addNode(new Node({ type: "atrule", name: DEFINE_CONTAINER_NAME }))
.addNode(new Node({ type: "decl" }));

expect(detectContainerDefinition(ruleNode, false)).toBe(".container");
expect(ruleNode.nodes.length).toBe(3);
expect(ruleNode.nodes[0].type).toBe("decl");
expect(ruleNode.nodes[1].type).toBe("atrule");
expect(ruleNode.nodes[1].name).toBe(DEFINE_CONTAINER_NAME);
expect(ruleNode.nodes[2].type).toBe("decl");
});
7 changes: 7 additions & 0 deletions src/postcss/getStylesObjectFromNode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ test("should only accept rule nodes", () => {
expect(() => {
getStylesObjectFromNode({});
}).toThrowError(/^`ruleNode` must be of type "rule".$/);

expect(
getStylesObjectFromNode({
type: "rule",
nodes: null
})
).toEqual({});
});

test("should extract all styles", () => {
Expand Down
41 changes: 25 additions & 16 deletions src/runtime/getConditionFunction.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getConditionFunction from "./getConditionFunction";

test('queries separated by a comma should act as an "or"', () => {
test('should treat multiple conditions as an "or"', () => {
// When either width or height is greater than 100
const condFn = getConditionFunction([
[["width", ">=", 100]],
Expand All @@ -22,7 +22,7 @@ test('queries separated by a comma should act as an "or"', () => {
expect(condFn2({ width: 100, height: 20 })).toBe(true);
});

test("non array conditions should return function always returning true", () => {
test("should return a function always returning true for non-array conditions", () => {
const condFn = getConditionFunction();
const condFn2 = getConditionFunction([]);

Expand All @@ -35,7 +35,7 @@ test("non array conditions should return function always returning true", () =>
expect(condFn2({ width: 99999, height: 99999 })).toBe(true);
});

test("orientation conditions", () => {
test("should work with orientation conditions", () => {
const portraitCondFn = getConditionFunction([
[["orientation", ":", "portrait"]]
]);
Expand All @@ -57,7 +57,7 @@ test("orientation conditions", () => {
expect(landscapeCondFn({ width: 10, height: 100 })).toBe(false);
});

test("width conditions", () => {
test("should work with width conditions", () => {
const ltCondFn = getConditionFunction([[["width", "<", 100]]]);
const lteCondFn = getConditionFunction([[["width", "<=", 100]]]);
const gtCondFn = getConditionFunction([[["width", ">", 100]]]);
Expand Down Expand Up @@ -92,7 +92,7 @@ test("width conditions", () => {
expect(gteCondFn({ width: 0 })).toBe(false);
});

test("height conditions", () => {
test("should work with height conditions", () => {
const ltCondFn = getConditionFunction([[["height", "<", 100]]]);
const lteCondFn = getConditionFunction([[["height", "<=", 100]]]);
const gtCondFn = getConditionFunction([[["height", ">", 100]]]);
Expand Down Expand Up @@ -127,7 +127,7 @@ test("height conditions", () => {
expect(gteCondFn({ height: 0 })).toBe(false);
});

test("aspect-ratio conditions", () => {
test("should work with aspect-ratio conditions", () => {
const ltCondFn = getConditionFunction([[["aspect-ratio", "<", 1]]]);
const lteCondFn = getConditionFunction([[["aspect-ratio", "<=", 1]]]);
const gtCondFn = getConditionFunction([[["aspect-ratio", ">", 1]]]);
Expand Down Expand Up @@ -158,7 +158,7 @@ test("aspect-ratio conditions", () => {
expect(gteCondFn({ width: 10, height: 100 })).toBe(false);
});

test("multiple conditions should work", () => {
test("should work for multiple conditions", () => {
const multiCondFn = getConditionFunction([
[
["orientation", ":", "landscape"],
Expand All @@ -174,16 +174,25 @@ test("multiple conditions should work", () => {
expect(multiCondFn({ width: 101, height: 20 })).toBe(true);
});

test("unsupported condition always returns true", () => {
const condFn = getConditionFunction([
test("should return a function always returning true for invalid conditions", () => {
const noCondFn1 = getConditionFunction([
[["something", "that's", "unrecognisable"]]
]);

expect(typeof condFn).toBe("function");
expect(condFn()).toBe(true);
expect(condFn({})).toBe(true);
expect(condFn({ width: 100, height: 100 })).toBe(true);
expect(condFn({ width: 200, height: 100 })).toBe(true);
expect(condFn({ width: 100, height: 200 })).toBe(true);
expect(condFn({ width: 0, height: 0 })).toBe(true);
const noCondFn2 = getConditionFunction([[["width", "?", 1]]]);
expect(typeof noCondFn2).toBe("function");

const noCondFn3 = getConditionFunction([[["height", "?", 1]]]);
expect(typeof noCondFn3).toBe("function");

const noCondFn4 = getConditionFunction([[["aspect-ratio", "?", 1]]]);
expect(typeof noCondFn4).toBe("function");

expect(typeof noCondFn1).toBe("function");
expect(noCondFn1()).toBe(true);
expect(noCondFn1({})).toBe(true);
expect(noCondFn1({ width: 100, height: 100 })).toBe(true);
expect(noCondFn1({ width: 200, height: 100 })).toBe(true);
expect(noCondFn1({ width: 100, height: 200 })).toBe(true);
expect(noCondFn1({ width: 0, height: 0 })).toBe(true);
});
Loading