Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
deletidev committed Jan 15, 2024
1 parent 1b825a1 commit 6893313
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/pods/edit-table/edit-table.bussines-move-down-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,73 +38,74 @@ 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,
y: 0,
};

// 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,
y: 0,
};
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,
y: 0,
};

// 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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
168 changes: 168 additions & 0 deletions src/pods/edit-table/edit-table.bussines-move-up-field.spec.ts
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);
});
});

0 comments on commit 6893313

Please sign in to comment.