Skip to content

Commit

Permalink
Made aspect-ratio actually work, and improved the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeCoder committed Feb 27, 2017
1 parent 793eef4 commit b18f7b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/postcss/getConditionsFromQueryParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export default function getConditionsFromQueryParams (params) {
return conditionArr.map((condition) => {
let conditionArr = trim(condition, '()');

conditionArr = conditionArr.match(/([a-z]*)([ :><=]*)([a-z0-9]*)/i);
conditionArr = conditionArr.match(/([a-z-]*)([ :><=]*)([a-z0-9\.]*)/i);
conditionArr.shift();

conditionArr = conditionArr.map(trim);

if ([ 'landscape', 'portrait' ].indexOf(conditionArr[2]) === -1) {
conditionArr[2] = parseInt(conditionArr[2]);
conditionArr[2] = parseFloat(conditionArr[2]);
}

return conditionArr;
Expand Down
20 changes: 19 additions & 1 deletion src/postcss/getConditionsFromQueryParams.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getConditionsFromQueryParams from './getConditionsFromQueryParams';

test('single condition should work with the "<", ">", "<=", ">=" and ":" operators', () => {
test('width condition should work with the "<", ">", "<=", ">=" and ":" operators', () => {
expect(getConditionsFromQueryParams('(width >= 42px)')).toEqual([
[ 'width', '>=', 42 ],
]);
Expand All @@ -13,6 +13,24 @@ test('single condition should work with the "<", ">", "<=", ">=" and ":" operato
expect(getConditionsFromQueryParams('(width < 42px)')).toEqual([
[ 'width', '<', 42 ],
]);
});

test('aspect-ratio should work with the "<", ">", "<=", ">=" and ":" operators', () => {
expect(getConditionsFromQueryParams('(aspect-ratio >= 0.5)')).toEqual([
[ 'aspect-ratio', '>=', 0.5 ],
]);
expect(getConditionsFromQueryParams('(aspect-ratio > 0.5)')).toEqual([
[ 'aspect-ratio', '>', 0.5 ],
]);
expect(getConditionsFromQueryParams('(aspect-ratio <= 0.5)')).toEqual([
[ 'aspect-ratio', '<=', 0.5 ],
]);
expect(getConditionsFromQueryParams('(aspect-ratio < 0.5)')).toEqual([
[ 'aspect-ratio', '<', 0.5 ],
]);
});

test('orientations with the : operator', () => {
expect(getConditionsFromQueryParams('(orientation: portrait)')).toEqual([
[ 'orientation', ':', 'portrait' ],
]);
Expand Down
10 changes: 10 additions & 0 deletions src/postcss/isEmptyObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ test('should return true if object is empty', () => {
expect(isEmptyObject(obj)).toBe(false);
expect(obj.hasOwnProperty).toHaveBeenCalledTimes(1);
});

test('should not include properties from the prototype chain', () => {
const parentObj = { parentProperty: 'parent value' };
const childObj = Object.create(parentObj);

expect(isEmptyObject(childObj)).toBe(true);

childObj.childProperty = 'child value';
expect(isEmptyObject(childObj)).toBe(false);
});

0 comments on commit b18f7b3

Please sign in to comment.