-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
203 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |