Skip to content

Commit a6b0c84

Browse files
authored
Merge pull request #1140 from Hydraner/feature/exclude-tags
Implement exclude tags feature.
2 parents 2f36604 + f5c7ef2 commit a6b0c84

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
'use strict';
22

3+
const _ = require('lodash');
4+
35
const uikitExcludePattern = (pattern, uikit) => {
46
const state = pattern.patternState;
5-
return uikit.excludedPatternStates.includes(state);
7+
const tags = _.isArray(pattern.tags) ? pattern.tags : [pattern.tags];
8+
9+
return (
10+
_.includes(uikit.excludedPatternStates, state) ||
11+
_.intersection(uikit.excludedTags, tags).length > 0
12+
);
613
};
714
module.exports = uikitExcludePattern;

packages/core/test/uikitExcludePattern_tests.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,51 @@ tap.test(
5151
test.end();
5252
}
5353
);
54+
55+
tap.test(
56+
'uikitExcludePattern - returns false when uikit has no excluded tags',
57+
test => {
58+
//arrange
59+
const uikit = { excludedTags: [] };
60+
const pattern = { tags: 'foo-tag' };
61+
62+
//act
63+
const result = uikitExcludePattern(pattern, uikit);
64+
65+
//assert
66+
test.false(result);
67+
test.end();
68+
}
69+
);
70+
71+
tap.test(
72+
'uikitExcludePattern - returns false pattern does not have same tags as uikit exclusions',
73+
test => {
74+
//arrange
75+
const uikit = { excludedTags: ['bat-tag'] };
76+
const pattern = { tags: 'foo-tag' };
77+
78+
//act
79+
const result = uikitExcludePattern(pattern, uikit);
80+
81+
//assert
82+
test.false(result);
83+
test.end();
84+
}
85+
);
86+
87+
tap.test(
88+
'uikitExcludePattern - returns true when uikit has same tags as pattern',
89+
test => {
90+
//arrange
91+
const uikit = { excludedTags: ['bar-tag', 'foo-tag'] };
92+
const pattern = { tags: 'foo-tag' };
93+
94+
//act
95+
const result = uikitExcludePattern(pattern, uikit);
96+
97+
//assert
98+
test.true(result);
99+
test.end();
100+
}
101+
);

0 commit comments

Comments
 (0)