Skip to content

Commit

Permalink
Up CssModels tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 2, 2023
1 parent 7421858 commit a2f9c17
Showing 1 changed file with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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');
Expand All @@ -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('');
});

Expand All @@ -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;}');
});
Expand All @@ -75,37 +71,37 @@ 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;}');
});

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;}}');
});
});

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);
});
Expand Down

0 comments on commit a2f9c17

Please sign in to comment.