From a0d6e46f1e86afa4f8be1a5bb087b78c982e67c9 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 11 Jan 2023 16:25:03 +0400 Subject: [PATCH] Update style manager tests --- .../model/{Models.js => Models.ts} | 40 ++++++++----------- test/specs/style_manager/model/Properties.js | 2 +- 2 files changed, 18 insertions(+), 24 deletions(-) rename test/specs/style_manager/model/{Models.js => Models.ts} (83%) diff --git a/test/specs/style_manager/model/Models.js b/test/specs/style_manager/model/Models.ts similarity index 83% rename from test/specs/style_manager/model/Models.js rename to test/specs/style_manager/model/Models.ts index 8676b830a..318ea60ef 100644 --- a/test/specs/style_manager/model/Models.js +++ b/test/specs/style_manager/model/Models.ts @@ -1,7 +1,7 @@ -import Sector from 'style_manager/model/Sector'; -import Property from 'style_manager/model/Property'; -import PropertyNumber from 'style_manager/model/PropertyNumber'; -import Editor from 'editor/model/Editor'; +import Sector from '../../../../src/style_manager/model/Sector'; +import Property from '../../../../src/style_manager/model/Property'; +import PropertyNumber from '../../../../src/style_manager/model/PropertyNumber'; +import Editor from '../../../../src/editor/model/Editor'; describe('Sector', () => { let em; @@ -25,7 +25,7 @@ describe('Sector', () => { }; em = new Editor({ styleManager: { - sectors: [{ id: 'sector-1' }], + sectors: [{ id: 'sector-1', name: 's' }], }, }); sm = em.get('StyleManager'); @@ -48,7 +48,8 @@ describe('Sector', () => { test('Init with properties', () => { obj = new Sector({ - properties: [{}, {}], + name: 'test', + properties: [{ property: '1' }, { property: '2' }], }); expect(obj.get('properties').length).toEqual(2); }); @@ -112,16 +113,12 @@ describe('Sector', () => { }); describe('Property', () => { - var obj; + let obj: Property; beforeEach(() => { obj = new Property(); }); - afterEach(() => { - obj = null; - }); - test('Has property field', () => { expect(obj.has('property')).toEqual(true); }); @@ -137,34 +134,30 @@ describe('Property', () => { }); test('parseValue with function and functionName', () => { - obj = new Property({ functionName: 'fn' }); + obj = new Property({ functionName: 'fn', property: 'test' }); const result = { value: 'testValue', functionName: 'fn' }; expect(obj.parseValue('fn(testValue)')).toEqual(result); expect(obj.parseValue('fn(testValue')).toEqual(result); }); test('Parse correctly a value with !important', () => { - const result = { value: 'red', important: 1 }; + const result = { value: 'red', important: true }; expect(obj.parseValue('red !important ')).toEqual(result); }); test('getFullValue', () => { - obj = new Property({ functionName: 'fn', value: 'red' }); + obj = new Property({ functionName: 'fn', value: 'red', property: 'test' }); expect(obj.getFullValue()).toEqual('fn(red)'); - obj = new Property({ functionName: 'fn', value: '#123', important: 1 }); + obj = new Property({ functionName: 'fn', value: '#123', important: true, property: 'test' }); expect(obj.getFullValue()).toEqual('fn(#123) !important'); }); }); describe('PropertyNumber', () => { - var obj; + let obj: PropertyNumber; beforeEach(() => { - obj = new PropertyNumber({ units: ['px', 'deg'] }); - }); - - afterEach(() => { - obj = null; + obj = new PropertyNumber({ units: ['px', 'deg'], property: 'test' }); }); test('parseValue with units', () => { @@ -176,20 +169,21 @@ describe('PropertyNumber', () => { obj = new PropertyNumber({ units: ['px', 'deg'], functionName: 'test', + property: 'test', }); const result = { value: 55, unit: 'deg', functionName: 'test' }; expect(obj.parseValue('test(55deg)')).toEqual(result); }); test('parse input value with min', () => { - obj = new PropertyNumber({ units: ['px'], min: 10 }); + obj = new PropertyNumber({ units: ['px'], min: 10, property: 'test' }); const result = { value: 10, unit: 'px' }; expect(obj.parseValue('1px')).toEqual(result); expect(obj.parseValue('15px')).toEqual({ value: 15, unit: 'px' }); }); test('parse input value with max', () => { - obj = new PropertyNumber({ units: ['px'], max: 100 }); + obj = new PropertyNumber({ units: ['px'], max: 100, property: 'test' }); const result = { value: 100, unit: 'px' }; expect(obj.parseValue('200px')).toEqual(result); expect(obj.parseValue('95px')).toEqual({ value: 95, unit: 'px' }); diff --git a/test/specs/style_manager/model/Properties.js b/test/specs/style_manager/model/Properties.js index 3936cf74d..48a3b6d72 100644 --- a/test/specs/style_manager/model/Properties.js +++ b/test/specs/style_manager/model/Properties.js @@ -499,7 +499,7 @@ describe('StyleManager properties logic', () => { }); test('Has no selected layer', () => { - expect(compTypeProp.getSelectedLayer()).toBe(null); + expect(compTypeProp.getSelectedLayer()).toBe(undefined); }); test('getLayersFromStyle returns correct values', () => {