From a2f9c178a755a0a0cc7cd948d70a104ae4707483 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 2 Sep 2023 13:05:57 +0400 Subject: [PATCH] Up CssModels tests --- .../model/{CssModels.js => CssModels.ts} | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) rename test/specs/css_composer/model/{CssModels.js => CssModels.ts} (72%) diff --git a/test/specs/css_composer/model/CssModels.js b/test/specs/css_composer/model/CssModels.ts similarity index 72% rename from test/specs/css_composer/model/CssModels.js rename to test/specs/css_composer/model/CssModels.ts index e169f9e5dc..0dae63f54a 100644 --- a/test/specs/css_composer/model/CssModels.js +++ b/test/specs/css_composer/model/CssModels.ts @@ -1,17 +1,13 @@ -import CssRule from 'css_composer/model/CssRule'; -import CssRules from 'css_composer/model/CssRules'; -import Selectors from 'selector_manager/model/Selectors'; -import Selector from 'selector_manager/model/Selector'; +import CssRule from '../../../../src/css_composer/model/CssRule'; +import CssRules from '../../../../src/css_composer/model/CssRules'; +import Selectors from '../../../../src/selector_manager/model/Selectors'; +import Selector from '../../../../src/selector_manager/model/Selector'; describe('CssRule', () => { - let obj; + let obj: CssRule; beforeEach(() => { - obj = new CssRule(); - }); - - afterEach(() => { - obj = null; + obj = new CssRule({} as any); }); test('Has selectors property', () => { @@ -27,26 +23,26 @@ describe('CssRule', () => { }); test('No default selectors', () => { - expect(obj.get('selectors').length).toEqual(0); + expect(obj.getSelectors().length).toEqual(0); }); test('Compare returns true with the same selectors', () => { - var s1 = obj.get('selectors').add({ name: 'test1' }); - var s2 = obj.get('selectors').add({ name: 'test2' }); + var s1 = obj.getSelectors().add({ name: 'test1' }); + var s2 = obj.getSelectors().add({ name: 'test2' }); expect(obj.compare([s1, s2])).toEqual(true); }); test('Compare with different state', () => { - var s1 = obj.get('selectors').add({ name: 'test1' }); - var s2 = obj.get('selectors').add({ name: 'test2' }); + var s1 = obj.getSelectors().add({ name: 'test1' }); + var s2 = obj.getSelectors().add({ name: 'test2' }); obj.set('state', 'hover'); expect(obj.compare([s1, s2])).toEqual(false); expect(obj.compare([s1, s2], 'hover')).toEqual(true); }); test('Compare with different mediaText', () => { - var s1 = obj.get('selectors').add({ name: 'test1' }); - var s2 = obj.get('selectors').add({ name: 'test2' }); + var s1 = obj.getSelectors().add({ name: 'test1' }); + var s2 = obj.getSelectors().add({ name: 'test2' }); obj.set('state', 'hover'); obj.set('mediaText', '1000'); obj.set('atRuleType', 'media'); @@ -56,7 +52,7 @@ describe('CssRule', () => { }); test('toCSS returns empty if there is no style', () => { - var s1 = obj.get('selectors').add({ name: 'test1' }); + var s1 = obj.getSelectors().add({ name: 'test1' }); expect(obj.toCSS()).toEqual(''); }); @@ -66,7 +62,7 @@ describe('CssRule', () => { }); test('toCSS returns simple CSS', () => { - obj.get('selectors').add({ name: 'test1' }); + obj.getSelectors().add({ name: 'test1' }); obj.setStyle({ color: 'red' }); expect(obj.toCSS()).toEqual('.test1{color:red;}'); }); @@ -75,21 +71,21 @@ describe('CssRule', () => { const media = '(max-width: 768px)'; obj.set('atRuleType', 'media'); obj.set('mediaText', media); - obj.get('selectors').add({ name: 'test1' }); + obj.getSelectors().add({ name: 'test1' }); obj.setStyle({ color: 'red' }); expect(obj.toCSS()).toEqual(`@media ${media}{.test1{color:red;}}`); }); test('toCSS with a generic at-rule', () => { obj.set('atRuleType', 'supports'); - obj.get('selectors').add({ name: 'test1' }); + obj.getSelectors().add({ name: 'test1' }); obj.setStyle({ 'font-family': 'Open Sans' }); expect(obj.toCSS()).toEqual('@supports{.test1{font-family:Open Sans;}}'); }); test('toCSS with a generic single at-rule', () => { obj.set('atRuleType', 'font-face'); - obj.set('singleAtRule', 1); + obj.set('singleAtRule', true); obj.setStyle({ 'font-family': 'Sans' }); expect(obj.toCSS()).toEqual('@font-face{font-family:Sans;}'); }); @@ -97,7 +93,7 @@ describe('CssRule', () => { test('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.getSelectors().add({ name: 'test1' }); obj.setStyle({ 'font-family': 'Open Sans' }); expect(obj.toCSS()).toEqual('@font-face some-condition{.test1{font-family:Open Sans;}}'); }); @@ -105,7 +101,7 @@ describe('CssRule', () => { describe('CssRules', () => { test('Creates collection item correctly', () => { - var c = new CssRules(); + var c = new CssRules([], {}); var m = c.add({}); expect(m instanceof CssRule).toEqual(true); });