From 4671791e6a575fb22907fbb3bef2ed36fa9ac36b Mon Sep 17 00:00:00 2001 From: Bowen Tan Date: Tue, 30 Nov 2021 10:35:09 +0800 Subject: [PATCH] fix test --- packages/core/__tests__/component.spec.ts | 116 ++++++------------ .../operation/adjustComponentOrder.spec.ts | 51 ++++---- 2 files changed, 66 insertions(+), 101 deletions(-) diff --git a/packages/core/__tests__/component.spec.ts b/packages/core/__tests__/component.spec.ts index fed642e3..f25a581a 100644 --- a/packages/core/__tests__/component.spec.ts +++ b/packages/core/__tests__/component.spec.ts @@ -1,85 +1,49 @@ +import { Type } from '@sinclair/typebox'; import { createComponent } from '../src/component'; describe('component', () => { it('can create runtime component', () => { - expect( - createComponent({ - version: 'core/v1', - metadata: { - name: 'test_component', - }, - - spec: { - properties: [ - { - name: 'x', - type: 'string', - }, - ], - - acceptTraits: [ - { - name: 't1', - }, - ], - - state: { - type: 'string', + const c = createComponent({ + version: 'core/v1', + metadata: { + isDraggable: true, + isResizable: true, + displayName: 'test_component', + name: 'test_component', + exampleProperties: {}, + exampleSize: [1, 1], + }, + spec: { + properties: Type.Object({ + name: Type.String(), + type: Type.String(), + }), + state: Type.Object({ + type: Type.String(), + }), + methods: [ + { + name: 'reset', }, - - methods: [ - { - name: 'reset', + { + name: 'add', + parameters: { + type: 'number', }, - - { - name: 'add', - parameters: { - type: 'number', - }, - }, - ], - }, - }) - ).toMatchInlineSnapshot(` - Object { - "kind": "Component", - "metadata": Object { - "name": "test_component", - }, - "parsedVersion": Object { - "category": "core", - "value": "v1", - }, - "spec": Object { - "acceptTraits": Array [ - Object { - "name": "t1", - }, - ], - "methods": Array [ - Object { - "name": "reset", - }, - Object { - "name": "add", - "parameters": Object { - "type": "number", - }, - }, - ], - "properties": Array [ - Object { - "name": "x", - "type": "string", - }, - ], - "state": Object { - "type": "string", }, - }, - "version": "core/v1", - } - `); + ], + styleSlots: ['content'], + slots: [], + events: [], + }, + }); + expect(c).toMatchObject({ + ...c, + kind: 'Component', + parsedVersion: { + category: 'core', + value: 'v1', + }, + }); }); }); diff --git a/packages/editor/__tests__/operation/adjustComponentOrder.spec.ts b/packages/editor/__tests__/operation/adjustComponentOrder.spec.ts index 56f69d3e..701ea6d2 100644 --- a/packages/editor/__tests__/operation/adjustComponentOrder.spec.ts +++ b/packages/editor/__tests__/operation/adjustComponentOrder.spec.ts @@ -1,6 +1,7 @@ -import { Application } from '@sunmao-ui/core'; +import { Application, ApplicationComponent } from '@sunmao-ui/core'; import { ApplicationFixture } from '../../__fixture__/application'; import { AdjustComponentOrderLeafOperation } from '../../src/operations/leaf/component/adjustComponentOrderLeafOperation'; + describe('adjust component order operation', () => { let app: Application; let operation: AdjustComponentOrderLeafOperation; @@ -11,10 +12,10 @@ describe('adjust component order operation', () => { }); describe('move up top level component', () => { - const stack: Application[] = []; + const stack: ApplicationComponent[][] = []; beforeAll(() => { app = ApplicationFixture['adjustOrderOperation']; - stack[0] = app; + stack[0] = app.spec.components; operation = new AdjustComponentOrderLeafOperation({ componentId: 'grid_layout2', orientation: 'up', @@ -22,15 +23,15 @@ describe('adjust component order operation', () => { }); it('should do operation', () => { stack[1] = operation.do(stack[0]); - expect(stack[1].spec.components).toMatchSnapshot(); + expect(stack[1]).toMatchSnapshot(); }); it('should undo operation', () => { stack[2] = operation.undo(stack[1]); - expect(stack[2].spec.components).toEqual(stack[0].spec.components); + expect(stack[2]).toEqual(stack[0]); }); it('should redo operation', () => { stack[3] = operation.redo(stack[2]); - expect(stack[3].spec.components).toEqual(stack[1].spec.components); + expect(stack[3]).toEqual(stack[1]); }); afterAll(() => { app = undefined; @@ -39,10 +40,10 @@ describe('adjust component order operation', () => { }); describe('move down top level component', () => { - const stack: Application[] = []; + const stack: ApplicationComponent[][] = []; beforeAll(() => { app = ApplicationFixture['adjustOrderOperation']; - stack[0] = app; + stack[0] = app.spec.components; operation = new AdjustComponentOrderLeafOperation({ componentId: 'grid_layout1', orientation: 'down', @@ -50,15 +51,15 @@ describe('adjust component order operation', () => { }); it('should do operation', () => { stack[1] = operation.do(stack[0]); - expect(stack[1].spec.components).toMatchSnapshot(); + expect(stack[1]).toMatchSnapshot(); }); it('should undo operation', () => { stack[2] = operation.undo(stack[1]); - expect(stack[2].spec.components).toEqual(stack[0].spec.components); + expect(stack[2]).toEqual(stack[0]); }); it('should redo operation', () => { stack[3] = operation.redo(stack[2]); - expect(stack[3].spec.components).toEqual(stack[1].spec.components); + expect(stack[3]).toEqual(stack[1]); }); afterAll(() => { app = undefined; @@ -72,7 +73,7 @@ describe('adjust component order operation', () => { componentId: 'grid_layout1', orientation: 'up', }); - expect(operation.do(app)).toEqual(app); + expect(operation.do(app.spec.components)).toEqual(app.spec.components); expect(warnSpy).toHaveBeenCalledWith('the element cannot move up'); }); @@ -82,15 +83,15 @@ describe('adjust component order operation', () => { componentId: 'grid_layout2', orientation: 'down', }); - expect(operation.do(app)).toEqual(app); + expect(operation.do(app.spec.components)).toEqual(app.spec.components); expect(warnSpy).toHaveBeenCalledWith('the element cannot move down'); }); describe('move up child component', () => { - const stack: Application[] = []; + const stack: ApplicationComponent[][] = []; beforeAll(() => { app = ApplicationFixture['adjustOrderOperation']; - stack[0] = app; + stack[0] = app.spec.components; operation = new AdjustComponentOrderLeafOperation({ componentId: 'userInfoContainer', orientation: 'up', @@ -98,15 +99,15 @@ describe('adjust component order operation', () => { }); it('should do operation', () => { stack[1] = operation.do(stack[0]); - expect(stack[1].spec.components).toMatchSnapshot(); + expect(stack[1]).toMatchSnapshot(); }); it('should undo operation', () => { stack[2] = operation.undo(stack[1]); - expect(stack[2].spec.components).toEqual(stack[0].spec.components); + expect(stack[2]).toEqual(stack[0]); }); it('should redo operation', () => { stack[3] = operation.redo(stack[2]); - expect(stack[3].spec.components).toEqual(stack[1].spec.components); + expect(stack[3]).toEqual(stack[1]); }); afterAll(() => { app = undefined; @@ -115,10 +116,10 @@ describe('adjust component order operation', () => { }); describe('move down child component', () => { - const stack: Application[] = []; + const stack: ApplicationComponent[][] = []; beforeAll(() => { app = ApplicationFixture['adjustOrderOperation']; - stack[0] = app; + stack[0] = app.spec.components; operation = new AdjustComponentOrderLeafOperation({ componentId: 'usersTable', orientation: 'down', @@ -126,15 +127,15 @@ describe('adjust component order operation', () => { }); it('should do operation', () => { stack[1] = operation.do(stack[0]); - expect(stack[1].spec.components).toMatchSnapshot(); + expect(stack[1]).toMatchSnapshot(); }); it('should undo operation', () => { stack[2] = operation.undo(stack[1]); - expect(stack[2].spec.components).toEqual(stack[0].spec.components); + expect(stack[2]).toEqual(stack[0]); }); it('should redo operation', () => { stack[3] = operation.redo(stack[2]); - expect(stack[3].spec.components).toEqual(stack[1].spec.components); + expect(stack[3]).toEqual(stack[1]); }); afterAll(() => { app = undefined; @@ -148,7 +149,7 @@ describe('adjust component order operation', () => { componentId: 'usersTable', orientation: 'up', }); - expect(operation.do(app)).toEqual(app); + expect(operation.do(app.spec.components)).toEqual(app.spec.components); expect(warnSpy).toHaveBeenCalledWith('the element cannot move up'); }); @@ -158,7 +159,7 @@ describe('adjust component order operation', () => { componentId: 'userInfoContainer', orientation: 'down', }); - expect(operation.do(app)).toEqual(app); + expect(operation.do(app.spec.components)).toEqual(app.spec.components); expect(warnSpy).toHaveBeenCalledWith('the element cannot move down'); });