-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added test to change items layers functionality
- Loading branch information
1 parent
3c60249
commit 01f27dd
Showing
4 changed files
with
81 additions
and
65 deletions.
There are no files selected for viewing
140 changes: 81 additions & 59 deletions
140
.../domain/update-item-and-children-layers/update-item-and-children-layers.execution.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 |
---|---|---|
@@ -1,89 +1,111 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { UpdateItemAndChildrenLayersExecution } from './update-item-and-children-layers.execution'; | ||
import { UpdateItemAndChildrenLayersRequest } from './update-item-and-children-layers.request'; | ||
import { FFlowMediator } from '../../infrastructure'; | ||
import { | ||
FCanvasBase, | ||
FNodeBase, | ||
GetDeepChildrenNodesAndGroupsExecution, | ||
MoveFrontElementsBeforeTargetElementExecution, | ||
SortItemLayersExecution, | ||
SortItemLayersRequest, SortItemsByParentExecution, SortNodeLayersExecution, | ||
UpdateItemAndChildrenLayersExecution | ||
} from '@foblex/flow'; | ||
import { FFlowMediator } from '@foblex/flow'; | ||
import { UpdateItemAndChildrenLayersRequest } from '@foblex/flow'; | ||
import { | ||
FComponentsStore, | ||
} from '@foblex/flow'; | ||
import { setupTestModule } from '../test-setup'; | ||
import { ISelectable } from '../../f-connection'; | ||
|
||
function getSelectableItem(hostElement: HTMLElement): ISelectable { | ||
return { | ||
fId: '1', | ||
fSelectionDisabled: false, | ||
hostElement: hostElement, | ||
select: jasmine.createSpy('select'), | ||
deselect: jasmine.createSpy('deselect'), | ||
isSelected: jasmine.createSpy('isSelected').and.returnValue(true) | ||
} | ||
} | ||
|
||
function createElementWithId(id: string): HTMLElement { | ||
function createElement(id: string): HTMLElement { | ||
const element = document.createElement('div'); | ||
element.id = id; | ||
return element; | ||
} | ||
|
||
describe('UpdateItemLayerExecution', () => { | ||
function createNode(id: string, element: HTMLElement, parentId?: string): FNodeBase { | ||
return { | ||
fId: id, | ||
fParentId: parentId, | ||
hostElement: element, | ||
} as FNodeBase; | ||
} | ||
|
||
function createCanvas(): FCanvasBase { | ||
return { | ||
fGroupsContainer: { | ||
nativeElement: document.createElement('div') as HTMLElement, | ||
}, | ||
fNodesContainer: { | ||
nativeElement: document.createElement('div') as HTMLElement, | ||
}, | ||
fConnectionsContainer: { | ||
nativeElement: document.createElement('div') as HTMLElement, | ||
} | ||
} as FCanvasBase; | ||
} | ||
|
||
describe('UpdateItemAndChildrenLayersExecution', () => { | ||
let fMediator: FFlowMediator; | ||
let fComponentsStore: FComponentsStore; | ||
|
||
beforeEach(() => { | ||
setupTestModule([ UpdateItemAndChildrenLayersExecution ]); | ||
setupTestModule([ UpdateItemAndChildrenLayersExecution, SortItemLayersExecution, SortItemsByParentExecution, SortNodeLayersExecution, GetDeepChildrenNodesAndGroupsExecution, MoveFrontElementsBeforeTargetElementExecution]); | ||
fMediator = TestBed.inject(FFlowMediator) as jasmine.SpyObj<FFlowMediator>; | ||
fComponentsStore = TestBed.inject(FComponentsStore); | ||
}); | ||
|
||
it('should move TargetElement to last position in array', () => { | ||
const itemContainer = createElementWithId('itemContainer'); | ||
const itemElement = createElementWithId('itemElement') | ||
const anotherElement = createElementWithId('anotherElement') | ||
const targetElement = createElementWithId('targetElement'); | ||
|
||
itemContainer.appendChild(anotherElement); | ||
itemContainer.appendChild(targetElement); | ||
itemContainer.appendChild(itemElement); | ||
it('should handle group container', () => { | ||
const fCanvas = createCanvas(); | ||
fComponentsStore.fCanvas = fCanvas; | ||
|
||
expect(itemContainer.children[ 1 ].id).toEqual('targetElement'); | ||
const group1 = createNode('group1', createElement('group1'), 'group2'); | ||
const group2 = createNode('group2', createElement('group2')); | ||
fCanvas.fGroupsContainer.nativeElement.append(group1.hostElement, group2.hostElement); | ||
|
||
fMediator.send(new UpdateItemAndChildrenLayersRequest(getSelectableItem(targetElement), itemContainer)); | ||
|
||
expect(itemContainer.children[ 0 ].id).toEqual('anotherElement'); | ||
expect(itemContainer.children[ 1 ].id).toEqual('itemElement'); | ||
expect(itemContainer.children[ 2 ].id).toEqual('targetElement'); | ||
}); | ||
const node4 = createNode('node4', createElement('node4'), 'node2'); | ||
const node1 = createNode('node1', createElement('node1')); | ||
const node2 = createNode('node2', createElement('node2'), 'group1'); | ||
const node3 = createNode('node3', createElement('node3')); | ||
|
||
it('should do nothing if TargetElement is already the last element', () => { | ||
const itemContainer = createElementWithId('itemContainer'); | ||
const anotherElement = createElementWithId('anotherElement') | ||
const targetElement = createElementWithId('targetElement'); | ||
fCanvas.fNodesContainer.nativeElement.append(node4.hostElement, node1.hostElement, node2.hostElement, node3.hostElement); | ||
|
||
itemContainer.appendChild(anotherElement); | ||
itemContainer.appendChild(targetElement); | ||
fComponentsStore.fNodes = [ group1, group2, node1, node2, node3, node4 ]; | ||
fMediator.send(new SortItemLayersRequest()); | ||
fMediator.send(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement)); | ||
|
||
expect(itemContainer.children[ 1 ].id).toEqual('targetElement'); | ||
expect(fCanvas.fGroupsContainer.nativeElement.children.item(0)).toEqual(group2.hostElement); | ||
expect(fCanvas.fGroupsContainer.nativeElement.children.item(1)).toEqual(group1.hostElement); | ||
|
||
fMediator.send(new UpdateItemAndChildrenLayersRequest(getSelectableItem(targetElement), itemContainer)); | ||
|
||
expect(itemContainer.children[ 0 ].id).toEqual('anotherElement'); | ||
expect(itemContainer.children[ 1 ].id).toEqual('targetElement'); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(0)).toEqual(node1.hostElement); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(1)).toEqual(node3.hostElement); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(3)).toEqual(node4.hostElement); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(2)).toEqual(node2.hostElement); | ||
}); | ||
|
||
it('should handle empty item container', () => { | ||
const itemContainer = createElementWithId('itemContainer'); | ||
const targetElement = createElementWithId('targetElement'); | ||
it('should handle group container with SortItemLayers', () => { | ||
const fCanvas = createCanvas(); | ||
fComponentsStore.fCanvas = fCanvas; | ||
|
||
fMediator.send(new UpdateItemAndChildrenLayersRequest(getSelectableItem(targetElement), itemContainer)); | ||
const group1 = createNode('group1', createElement('group1'), 'group2'); | ||
const group2 = createNode('group2', createElement('group2')); | ||
fCanvas.fGroupsContainer.nativeElement.append(group1.hostElement, group2.hostElement); | ||
|
||
expect(itemContainer.children.length).toBe(0); | ||
}); | ||
const node4 = createNode('node4', createElement('node4'), 'node2'); | ||
const node1 = createNode('node1', createElement('node1')); | ||
const node2 = createNode('node2', createElement('node2'), 'group1'); | ||
const node3 = createNode('node3', createElement('node3')); | ||
|
||
fCanvas.fNodesContainer.nativeElement.append(node4.hostElement, node1.hostElement, node2.hostElement, node3.hostElement); | ||
|
||
it('should handle item not in container', () => { | ||
const itemContainer = createElementWithId('itemContainer'); | ||
const anotherElement = createElementWithId('anotherElement') | ||
const targetElement = createElementWithId('targetElement'); | ||
fComponentsStore.fNodes = [ group1, group2, node1, node2, node3, node4 ]; | ||
|
||
itemContainer.appendChild(anotherElement); | ||
fMediator.send(new UpdateItemAndChildrenLayersRequest(group1, fCanvas.fGroupsContainer.nativeElement)); | ||
|
||
fMediator.send(new UpdateItemAndChildrenLayersRequest(getSelectableItem(targetElement), itemContainer)); | ||
expect(fCanvas.fGroupsContainer.nativeElement.children.item(0)).toEqual(group2.hostElement); | ||
expect(fCanvas.fGroupsContainer.nativeElement.children.item(1)).toEqual(group1.hostElement); | ||
|
||
expect(itemContainer.children.length).toBe(1); | ||
expect(itemContainer.children[ 0 ].id).toEqual('anotherElement'); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(0)).toEqual(node1.hostElement); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(1)).toEqual(node3.hostElement); | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(2)).toEqual(node4.hostElement); // node4 is here because we need call SortItemLayers on test Init | ||
expect(fCanvas.fNodesContainer.nativeElement.children.item(3)).toEqual(node2.hostElement); | ||
}); | ||
}); |
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
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
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