Skip to content

Commit 3328544

Browse files
committed
sort media queries by number
unit test coverage for media query hunter and some rudimentary coverage for parameter hunter
1 parent f76d3af commit 3328544

File tree

5 files changed

+207
-22
lines changed

5 files changed

+207
-22
lines changed

builder/media_hunter.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.10.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.10.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -33,8 +33,11 @@
3333
}
3434
}
3535
});
36-
//alpha sort for now, but should meet most use-cases except greater than 100ems. you are using ems right?
37-
patternlab.mediaQueries.sort();
36+
patternlab.mediaQueries.sort(function(a,b){
37+
var integerPartA = a.match(/(?:\d*\.)?\d+/g);
38+
var integerPartB = b.match(/(?:\d*\.)?\d+/g);
39+
return parseInt(a,10) > parseInt(b,10);
40+
});
3841
}
3942

4043
return {

builder/parameter_hunter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.10.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.10.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -47,7 +47,7 @@
4747
for (var prop in paramData) {
4848
if (existingData.hasOwnProperty(prop)) {
4949
existingData[prop] = paramData[prop];
50-
}
50+
}
5151
}
5252

5353
//extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally

test/files/test.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@
1111
color: green;
1212
}
1313
}
14+
15+
@media only screen and( max-width: 50em){
16+
body{
17+
color: orange;
18+
}
19+
}

test/media_hunter_tests.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
var MediaHunter = require('../builder/media_hunter');
55

6-
//all tests here run against the shipped code, and as such altering any of that can break these tests
7-
//these tests are intended to catch development regressions. one should not have a need to run tests during patternlab use.
8-
96
exports['media_query hunter basic support '] = {
107
'test media hunter finds query' : function(test){
118

@@ -28,9 +25,7 @@
2825

2926
mh.find_media_queries('./test/files', pl);
3027

31-
test.equals(pl.mediaQueries[0], '1600px');
32-
33-
console.log(pl.mediaQueries);
28+
test.equals(pl.mediaQueries[0], '35em');
3429

3530
test.done();
3631
},
@@ -43,7 +38,34 @@
4338

4439
mh.find_media_queries('./test/files', pl);
4540

46-
test.equals(pl.mediaQueries[2], '50em');
41+
test.equals(pl.mediaQueries[1], '50em');
42+
43+
test.done();
44+
},
45+
46+
'calling media hunter twice does not double add media queries' : function(test){
47+
48+
//setup pl object
49+
var pl = {};
50+
var mh = new MediaHunter();
51+
52+
mh.find_media_queries('./test/files', pl);
53+
mh.find_media_queries('./test/files', pl);
54+
55+
test.equals(pl.mediaQueries.length, 4);
56+
57+
test.done();
58+
},
59+
60+
'encountering the same breakpoint in a file does not double add' : function(test){
61+
62+
//setup pl object
63+
var pl = {};
64+
var mh = new MediaHunter();
65+
66+
mh.find_media_queries('./test/files', pl);
67+
68+
test.equals(pl.mediaQueries.length, 4);
4769

4870
test.done();
4971
}

test/parameter_hunter_tests.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
(function () {
2+
"use strict";
3+
4+
var ph = require('../builder/parameter_hunter');
5+
6+
exports['parameter_hunter'] = {
7+
'pattern hunter finds and extends templates' : function(test){
8+
9+
//setup current pattern from what we would have during execution
10+
var currentPattern = {
11+
"fileName": "01-sticky-comment",
12+
"subdir": "02-organisms/02-comments",
13+
"name": "02-organisms-02-comments-01-sticky-comment",
14+
"data": null,
15+
"jsonFileData": {},
16+
"patternName": "sticky-comment",
17+
"patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html",
18+
"patternGroup": "organisms",
19+
"patternSubGroup": "comments",
20+
"flatPatternPath": "02-organisms-02-comments",
21+
"key": "organisms-sticky-comment",
22+
"template": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
23+
"patternPartial": "",
24+
"lineage": [
25+
],
26+
"lineageIndex": [
27+
],
28+
"lineageR": [
29+
],
30+
"lineageRIndex": [
31+
],
32+
"patternState": "",
33+
"extendedTemplate": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"
34+
};
35+
var patternlab = {
36+
patterns: [
37+
{
38+
"fileName": "02-single-comment",
39+
"subdir": "01-molecules/06-components",
40+
"name": "01-molecules-06-components-02-single-comment",
41+
"data": null,
42+
"jsonFileData": {},
43+
"patternName": "single-comment",
44+
"patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html",
45+
"patternGroup": "molecules",
46+
"patternSubGroup": "components",
47+
"flatPatternPath": "01-molecules-06-components",
48+
"key": "molecules-single-comment",
49+
"template": "<p>{{description}}</p>",
50+
"patternPartial": "",
51+
"lineage": [
52+
],
53+
"lineageIndex": [
54+
],
55+
"lineageR": [
56+
],
57+
"lineageRIndex": [
58+
],
59+
"patternState": "",
60+
"extendedTemplate": "<p>{{description}}</p>"
61+
}
62+
],
63+
config: {
64+
debug: false
65+
},
66+
data: {
67+
description: 'Not a quote from a smart man'
68+
}
69+
};
70+
71+
var parameter_hunter = new ph();
72+
73+
parameter_hunter.find_parameters(currentPattern, patternlab);
74+
test.equals(currentPattern.extendedTemplate, '<p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>');
75+
76+
test.done();
77+
},
78+
79+
'pattern hunter finds and extends templates with mixed parameter and global data' : function(test){
80+
81+
//setup current pattern from what we would have during execution
82+
var currentPattern = {
83+
"fileName": "01-sticky-comment",
84+
"subdir": "02-organisms/02-comments",
85+
"name": "02-organisms-02-comments-01-sticky-comment",
86+
"data": null,
87+
"jsonFileData": {},
88+
"patternName": "sticky-comment",
89+
"patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html",
90+
"patternGroup": "organisms",
91+
"patternSubGroup": "comments",
92+
"flatPatternPath": "02-organisms-02-comments",
93+
"key": "organisms-sticky-comment",
94+
"template": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
95+
"patternPartial": "",
96+
"lineage": [
97+
],
98+
"lineageIndex": [
99+
],
100+
"lineageR": [
101+
],
102+
"lineageRIndex": [
103+
],
104+
"patternState": "",
105+
"extendedTemplate": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"
106+
};
107+
var patternlab = {
108+
patterns: [
109+
{
110+
"fileName": "02-single-comment",
111+
"subdir": "01-molecules/06-components",
112+
"name": "01-molecules-06-components-02-single-comment",
113+
"data": null,
114+
"jsonFileData": {},
115+
"patternName": "single-comment",
116+
"patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html",
117+
"patternGroup": "molecules",
118+
"patternSubGroup": "components",
119+
"flatPatternPath": "01-molecules-06-components",
120+
"key": "molecules-single-comment",
121+
"template": "<h1>{{foo}}</h1><p>{{description}}</p>",
122+
"patternPartial": "",
123+
"lineage": [
124+
],
125+
"lineageIndex": [
126+
],
127+
"lineageR": [
128+
],
129+
"lineageRIndex": [
130+
],
131+
"patternState": "",
132+
"extendedTemplate": "<h1>{{foo}}</h1><p>{{description}}</p>"
133+
}
134+
],
135+
config: {
136+
debug: false
137+
},
138+
data: {
139+
foo: 'Bar',
140+
description: 'Baz'
141+
}
142+
};
143+
144+
var parameter_hunter = new ph();
145+
146+
parameter_hunter.find_parameters(currentPattern, patternlab);
147+
test.equals(currentPattern.extendedTemplate, '<h1>Bar</h1><p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>');
148+
149+
test.done();
150+
},
151+
152+
};
153+
154+
}());

0 commit comments

Comments
 (0)