From b3b79c1970be9f625c2ea564b9e7beef4ce39180 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 23 Jan 2024 22:46:00 +0400 Subject: [PATCH] Up PropertySelectView --- ...rtySelectView.js => PropertySelectView.ts} | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) rename test/specs/style_manager/view/{PropertySelectView.js => PropertySelectView.ts} (67%) diff --git a/test/specs/style_manager/view/PropertySelectView.js b/test/specs/style_manager/view/PropertySelectView.ts similarity index 67% rename from test/specs/style_manager/view/PropertySelectView.js rename to test/specs/style_manager/view/PropertySelectView.ts index aa6c3aa7c..13b3f5cfa 100644 --- a/test/specs/style_manager/view/PropertySelectView.js +++ b/test/specs/style_manager/view/PropertySelectView.ts @@ -1,30 +1,29 @@ -import PropertySelectView from 'style_manager/view/PropertySelectView'; -import Property from 'style_manager/model/PropertyRadio'; -import Editor from 'editor/model/Editor'; -import DomComponents from 'dom_components'; -import Component from 'dom_components/model/Component'; +import PropertySelectView from '../../../../src/style_manager/view/PropertySelectView'; +import Property from '../../../../src/style_manager/model/PropertyRadio'; +import Editor from '../../../../src/editor/model/Editor'; +import DomComponents from '../../../../src/dom_components'; +import Component from '../../../../src/dom_components/model/Component'; describe('PropertySelectView', () => { - let em; - let dcomp; - let compOpts; - var component; - var fixtures; - var target; - var model; - var view; - var options; - var propName = 'testprop'; - var propValue = 'test1value'; - var defValue = 'test2value'; - var options = [ - { value: 'test1value', style: 'test:style' }, - { name: 'test2', value: 'test2value' }, + let em: Editor; + let dcomp: Editor['Components']; + let compOpts: any; + let component: Component; + let fixtures: HTMLElement; + let target: Component; + let model: Property; + let view: PropertySelectView; + const propName = 'testprop'; + const propValue = 'test1value'; + const defValue = 'test2value'; + let options: any = [ + { id: 'test1value', style: 'test:style' }, + { id: 'test2', value: 'test2value' }, ]; beforeEach(() => { em = new Editor({}); - dcomp = new DomComponents(em); + dcomp = em.Components; compOpts = { em, componentTypes: dcomp.componentTypes }; target = new Component({}, compOpts); component = new Component({}, compOpts); @@ -38,43 +37,39 @@ describe('PropertySelectView', () => { ); view = new PropertySelectView({ model }); document.body.innerHTML = '
'; - fixtures = document.body.firstChild; + fixtures = document.body.firstChild as HTMLElement; view.render(); fixtures.appendChild(view.el); }); afterEach(() => { - //view.remove(); // strange errors ??? - }); - - afterAll(() => { - component = null; + em.destroy(); }); test('Rendered correctly', () => { - var prop = view.el; + const prop = view.el; expect(fixtures.querySelector('.property')).toBeTruthy(); expect(prop.querySelector('.label')).toBeTruthy(); expect(prop.querySelector('.field')).toBeTruthy(); }); test('Select rendered', () => { - var prop = view.el; + const prop = view.el; expect(prop.querySelector('select')).toBeTruthy(); }); test('Options rendered', () => { - var select = view.el.querySelector('select'); + const select = view.el.querySelector('select')!; expect(select.children.length).toEqual(options.length); }); test('Options rendered correctly', () => { - var select = view.el.querySelector('select'); - var children = select.children; - expect(children[0].value).toEqual(options[0].value); - expect(children[1].value).toEqual(options[1].value); - expect(children[0].textContent).toEqual(options[0].value); - expect(children[1].textContent).toEqual(options[1].name); + const select = view.el.querySelector('select')!; + const children = select.children; + expect((children[0] as any).value).toEqual(options[0].id); + expect((children[1] as any).value).toEqual(options[1].id); + expect(children[0].textContent).toEqual(options[0].id); + expect(children[1].textContent).toEqual(options[1].id); expect(children[0].getAttribute('style')).toEqual(options[0].style); expect(children[1].getAttribute('style')).toEqual(null); }); @@ -106,7 +101,7 @@ describe('PropertySelectView', () => { describe('Init property', () => { beforeEach(() => { - component = new Component(); + component = new Component({}, compOpts); model = new Property({ type: 'select', list: options, @@ -132,7 +127,7 @@ describe('PropertySelectView', () => { { value: 'test2value', name: 'test2' }, { value: '', name: 'TestDef' }, ]; - component = new Component(); + component = new Component({}, compOpts); model = new Property({ type: 'select', list: options,