From 4f3af7415d8780b674e4792723a0221ac3e6068c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 8 Oct 2023 11:26:34 +0400 Subject: [PATCH] Up pages tests --- src/pages/index.ts | 2 +- test/specs/pages/{index.js => index.ts} | 79 ++++++++++++------------- 2 files changed, 38 insertions(+), 43 deletions(-) rename test/specs/pages/{index.js => index.ts} (81%) diff --git a/src/pages/index.ts b/src/pages/index.ts index d8dec1b62a..3d71538ec5 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -182,7 +182,7 @@ export default class PageManager extends ItemManagerModule { - let editor; - let em; - let domc; - let initCmpLen; - let pm; + let editor: Editor; + let em: EditorModel; + let domc: Editor['Components']; + let initCmpLen = 0; + let pm: Editor['Pages']; beforeAll(() => { - editor = new Editor({ pageManager: true }); + editor = new Editor({ pageManager: {} }); em = editor.getModel(); - domc = em.get('DomComponents'); - pm = em.get('PageManager'); + domc = em.Components; + pm = em.Pages; pm.onLoad(); initCmpLen = Object.keys(domc.allById()).length; }); afterAll(() => { editor.destroy(); - pm = 0; - em = 0; - domc = 0; }); - beforeEach(() => {}); - afterEach(() => {}); - test('Pages module exists', () => { expect(pm).toBeTruthy(); }); @@ -58,7 +54,7 @@ describe('Pages', () => { test('Adding new page with selection', () => { const name = 'Test page'; - const page = pm.add({ name }, { select: 1 }); + const page = pm.add({ name }, { select: true })!; expect(page.id).toBeTruthy(); expect(page.get('name')).toBe(name); expect(pm.getSelected()).toBe(page); @@ -69,8 +65,15 @@ describe('Pages', () => { }); describe('Init with pages', () => { - let idPage1, idComp1, idComp2, comp1, comp2, initPages, allbyId; - const createCompDef = id => ({ + let idPage1 = 'page-1'; + let idComp1 = 'comp1'; + let idComp2 = 'comp2'; + let comp1: ComponentDefinition; + let comp2: ComponentDefinition; + let initPages; + let allbyId: ReturnType; + + const createCompDef = (id: string): ComponentDefinition => ({ attributes: { id, class: id, @@ -78,10 +81,8 @@ describe('Pages', () => { }, components: `Component ${id}`, }); + beforeAll(() => { - idPage1 = 'page-1'; - idComp1 = 'comp1'; - idComp2 = 'comp2'; comp1 = createCompDef(idComp1); comp2 = createCompDef(idComp2); initPages = [ @@ -124,9 +125,6 @@ describe('Pages', () => { afterAll(() => { editor.destroy(); - pm = 0; - em = 0; - domc = 0; }); test('Pages are created correctly', () => { @@ -153,26 +151,23 @@ describe('Pages', () => { }); describe('Managing pages', () => { - let editor; - let em; - let domc; - let initCmpLen; - let pm; + let editor: Editor; + let em: EditorModel; + let domc: Editor['Components']; + let initCmpLen = 0; + let pm: Editor['Pages']; beforeEach(() => { - editor = new Editor({ pageManager: true }); + editor = new Editor({ pageManager: {} }); em = editor.getModel(); - domc = em.get('DomComponents'); - pm = em.get('PageManager'); + domc = em.Components; + pm = em.Pages; editor.getModel().loadOnStart(); initCmpLen = Object.keys(domc.allById()).length; }); afterEach(() => { editor.destroy(); - pm = 0; - em = 0; - domc = 0; }); test('Add page', () => { @@ -203,8 +198,8 @@ describe('Managing pages', () => { test('Remove page', () => { const eventRm = jest.fn(); em.on(pm.events.remove, eventRm); - const page = pm.add({}); - pm.remove(page.id); + const page = pm.add({})!; + pm.remove(`${page.id}`); expect(pm.getAll().length).toBe(1); expect(eventRm).toBeCalledTimes(1); }); @@ -213,8 +208,8 @@ describe('Managing pages', () => { em.on(pm.events.removeBefore, (p, c, opts) => { opts.abort = 1; }); - const page = pm.add({}); - pm.remove(page.id); + const page = pm.add({})!; + pm.remove(`${page.id}`); expect(pm.getAll().length).toBe(2); }); @@ -223,15 +218,15 @@ describe('Managing pages', () => { opts.abort = 1; complete(); }); - const page = pm.add({}); - pm.remove(page.id); + const page = pm.add({})!; + pm.remove(`${page.id}`); expect(pm.getAll().length).toBe(1); }); test('Change page', () => { const event = jest.fn(); em.on(pm.events.update, event); - const page = pm.add({}); + const page = pm.add({})!; const up = { name: 'Test' }; const opts = { myopts: 1 }; page.set(up, opts);