From 6893313e9a27dc3d58bece8a15c6833cec2a1d76 Mon Sep 17 00:00:00 2001 From: LeticiadelaOsa Date: Mon, 15 Jan 2024 19:33:26 +0100 Subject: [PATCH] test --- ...dit-table.bussines-move-down-field.spec.ts | 69 +++---- .../edit-table.bussines-move-up-field.spec.ts | 168 ++++++++++++++++++ 2 files changed, 203 insertions(+), 34 deletions(-) create mode 100644 src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts diff --git a/src/pods/edit-table/edit-table.bussines-move-down-field.spec.ts b/src/pods/edit-table/edit-table.bussines-move-down-field.spec.ts index 486f858d..777a228d 100644 --- a/src/pods/edit-table/edit-table.bussines-move-down-field.spec.ts +++ b/src/pods/edit-table/edit-table.bussines-move-down-field.spec.ts @@ -38,7 +38,18 @@ describe('moveDownField', () => { id: '1', fields: [ { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, - { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, ], tableName: 'MyTable', x: 0, @@ -46,14 +57,25 @@ describe('moveDownField', () => { }; // Act - const updateTable = moveDownField(table, '1'); + const updateTable = moveDownField(table, '11'); // Assert const expected: TableVm = { id: '1', fields: [ - { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, ], tableName: 'MyTable', x: 0, @@ -61,24 +83,14 @@ describe('moveDownField', () => { }; expect(updateTable).toEqual(expected); }); + it('should not move a field if is the last field', () => { // Arrange const table: TableVm = { id: '1', fields: [ { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, - { - id: '2', - PK: false, - FK: false, - name: 'Field2', - type: 'object', - children: [ - { id: '11', PK: false, FK: false, name: 'Field1', type: 'string' }, - { id: '22', PK: false, FK: false, name: 'Field2', type: 'string' }, - ], - }, - { id: '3', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, ], tableName: 'MyTable', x: 0, @@ -86,25 +98,14 @@ describe('moveDownField', () => { }; // Act - const updateTable = moveDownField(table, '11'); + const updateTable = moveDownField(table, '2'); // Assert const expected: TableVm = { id: '1', fields: [ { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, - { - id: '2', - PK: false, - FK: false, - name: 'Field2', - type: 'object', - children: [ - { id: '22', PK: false, FK: false, name: 'Field2', type: 'string' }, - { id: '11', PK: false, FK: false, name: 'Field1', type: 'string' }, - ], - }, - { id: '3', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, ], tableName: 'MyTable', x: 0, @@ -126,11 +127,11 @@ describe('moveDownField', () => { name: 'Field2', type: 'object', children: [ - { id: '11', PK: false, FK: false, name: 'Field1', type: 'string' }, - { id: '22', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, ], }, - { id: '3', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, ], tableName: 'MyTable', x: 0, @@ -152,11 +153,11 @@ describe('moveDownField', () => { name: 'Field2', type: 'object', children: [ - { id: '11', PK: false, FK: false, name: 'Field1', type: 'string' }, - { id: '22', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, ], }, - { id: '3', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, ], tableName: 'MyTable', x: 0, diff --git a/src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts b/src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts new file mode 100644 index 00000000..b1016266 --- /dev/null +++ b/src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts @@ -0,0 +1,168 @@ +import { moveUpField } from './edit-table.business'; +import { TableVm } from './edit-table.vm'; + +describe('moveDownField', () => { + it('should move a field to up level', () => { + // Arrange + const table: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + + //Act + const updateTable = moveUpField(table, '2'); + + //Assert + const expected: TableVm = { + id: '1', + fields: [ + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + expect(updateTable).toEqual(expected); + }); + + it('should move a field to up level even if it is nested', () => { + // Arrange + const table: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + + // Act + const updateTable = moveUpField(table, '22'); + + // Assert + const expected: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + expect(updateTable).toEqual(expected); + }); + + it('should not move a field if is the first field', () => { + // Arrange + const table: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + + //Act + const updateTable = moveUpField(table, '1'); + + //Assert + const expected: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { id: '2', PK: false, FK: false, name: 'Field2', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + expect(updateTable).toEqual(expected); + }); + + it('should not move a field if it is the first field even if it is nested', () => { + // Arrange + const table: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + + // Act + const updateTable = moveUpField(table, '11'); + + // Assert + const expected: TableVm = { + id: '1', + fields: [ + { id: '1', PK: false, FK: false, name: 'Field1', type: 'string' }, + { + id: '2', + PK: false, + FK: false, + name: 'Field2', + type: 'object', + children: [ + { id: '11', PK: false, FK: false, name: 'Field11', type: 'string' }, + { id: '22', PK: false, FK: false, name: 'Field22', type: 'string' }, + ], + }, + { id: '3', PK: false, FK: false, name: 'Field3', type: 'string' }, + ], + tableName: 'MyTable', + x: 0, + y: 0, + }; + expect(updateTable).toEqual(expected); + }); +});