From 47987b9cbc196d85a5a41e7eb1f19f9b65f815c8 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 24 Jan 2018 14:38:10 +0100 Subject: [PATCH] Update ParserCSS, set some property conditionally --- src/parser/model/ParserCss.js | 15 +++++++++------ test/specs/css_composer/model/CssModels.js | 12 +++++++++++- test/specs/parser/model/ParserCss.js | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/parser/model/ParserCss.js b/src/parser/model/ParserCss.js index a287eb6aa..5b6a8b945 100644 --- a/src/parser/model/ParserCss.js +++ b/src/parser/model/ParserCss.js @@ -133,7 +133,9 @@ module.exports = config => ({ // For each group of selectors for (var k = 0, len3 = sels.length; k < len3; k++) { var selArr = sels[k]; - var model = { singleAtRule, atRuleType }; + var model = {}; + singleAtRule && (model.singleAtRule = singleAtRule); + atRuleType && (model.atRuleType = atRuleType); //Isolate state from selector var stateArr = selArr[selArr.length - 1].split(/:(.+)/); @@ -156,14 +158,15 @@ module.exports = config => ({ if (lastRule) { lastRule.selectorsAdd = selsAddStr; } else { - result.push({ - singleAtRule, - atRuleType, + const model = { selectors: [], selectorsAdd: selsAddStr, - mediaText: condition, style - }); + }; + singleAtRule && (model.singleAtRule = singleAtRule); + atRuleType && (model.atRuleType = atRuleType); + condition && (model.mediaText = condition); + result.push(model); } } } diff --git a/test/specs/css_composer/model/CssModels.js b/test/specs/css_composer/model/CssModels.js index d7c423969..f97bcce06 100644 --- a/test/specs/css_composer/model/CssModels.js +++ b/test/specs/css_composer/model/CssModels.js @@ -5,7 +5,7 @@ var Selector = require('selector_manager/model/Selector'); module.exports = { run() { - describe.only('CssRule', () => { + describe('CssRule', () => { let obj; beforeEach(() => { @@ -89,6 +89,16 @@ module.exports = { `@font-face{.test1{font-family:Open Sans;}}` ); }); + + it('toCSS with a generic at-rule and condition', () => { + obj.set('atRuleType', 'font-face'); + obj.set('mediaText', 'some-condition'); + obj.get('selectors').add({ name: 'test1' }); + obj.setStyle({ 'font-family': 'Open Sans' }); + expect(obj.toCSS()).toEqual( + `@font-face some-condition{.test1{font-family:Open Sans;}}` + ); + }); }); describe('CssRules', () => { diff --git a/test/specs/parser/model/ParserCss.js b/test/specs/parser/model/ParserCss.js index f0e439580..262f945fb 100644 --- a/test/specs/parser/model/ParserCss.js +++ b/test/specs/parser/model/ParserCss.js @@ -2,7 +2,7 @@ const ParserCss = require('parser/model/ParserCss'); module.exports = { run() { - describe('ParserCss', () => { + describe.only('ParserCss', () => { var obj; beforeEach(() => {