Browse Source

Update checkNode and add more tests

pull/1446/head
Artur Arseniev 8 years ago
parent
commit
baaaa6bbfd
  1. 7
      src/parser/model/ParserCss.js
  2. 59
      test/specs/parser/model/ParserCss.js

7
src/parser/model/ParserCss.js

@ -31,9 +31,9 @@ module.exports = (config = {}) => ({
const nodes = []; const nodes = [];
const selsParsed = parseSelector(selectors); const selsParsed = parseSelector(selectors);
const classSets = selsParsed.result; const classSets = selsParsed.result;
const selectorsAdd = selsParsed.add.join(', ');
const opts = { const opts = {
atRule: node.atRule, atRule: node.atRule,
selectorsAdd: selsParsed.add.join(', '),
mediaText: node.params mediaText: node.params
}; };
@ -45,6 +45,11 @@ module.exports = (config = {}) => ({
nodes.push(createNode([], style, opts)); nodes.push(createNode([], style, opts));
} }
if (selectorsAdd) {
const lastNode = nodes[nodes.length - 1];
lastNode.selectorsAdd = selectorsAdd;
}
node = nodes; node = nodes;
} }

59
test/specs/parser/model/ParserCss.js

@ -4,7 +4,7 @@ const Selector = require('selector_manager/model/Selector');
module.exports = { module.exports = {
run() { run() {
describe.only('ParserCss', () => { describe('ParserCss', () => {
let obj; let obj;
let config; let config;
let customParser; let customParser;
@ -436,20 +436,61 @@ module.exports = {
}); });
test('Check node with a rule containing id', () => { test('Check node with a rule containing id', () => {
const style = { color: 'blue' }; const style = { border: '1px solid black !important' };
expect( expect(
obj.checkNode({ obj.checkNode({
selectors: '#main', selectors: '#main:hover',
style: { border: '1px solid black' } style
}) })
).toEqual([ ).toEqual([
{ {
atRuleType: 'media', selectors: ['#main'],
selectors: ['class-test', 'class2'],
selectorsAdd: 'div > span',
style: style,
state: 'hover', state: 'hover',
mediaText: 'screen and (min-width: 480px)' style: style
}
]);
});
test('Check node with multiple class selectors', () => {
const style = {
border: '1px solid black !important',
'background-repeat': 'repeat-y, no-repeat'
};
expect(
obj.checkNode({
selectors:
'.class1, .class1.class2:hover, div > .test:hover, span.test2',
style
})
).toEqual([
{
selectors: ['class1'],
style: style
},
{
selectors: ['class1', 'class2'],
state: 'hover',
selectorsAdd: 'div > .test:hover, span.test2',
style: style
}
]);
});
test('Check node with a rule containing CSS variables', () => {
const style = {
'--some-color': 'red',
'--some-width': '55px'
};
expect(
obj.checkNode({
selectors: ':root',
style
})
).toEqual([
{
selectors: [],
selectorsAdd: ':root',
style: style
} }
]); ]);
}); });

Loading…
Cancel
Save