|
| 1 | +import { BranchedStep } from 'sequential-workflow-model'; |
1 | 2 | import { createComponentContextStub, createStepStub } from '../test-tools/stubs'; |
2 | 3 | import { DragStepView } from './drag-step-behavior-view'; |
3 | 4 |
|
4 | 5 | describe('DragStepView', () => { |
5 | | - it('creates view', () => { |
6 | | - const appendChildSpy = spyOn(document.body, 'appendChild').and.stub(); |
| 6 | + let appendChildSpy: jasmine.Spy; |
| 7 | + let removeChildSpy: jasmine.Spy; |
| 8 | + |
| 9 | + beforeEach(() => { |
| 10 | + appendChildSpy = spyOn(document.body, 'appendChild').and.callThrough(); |
| 11 | + removeChildSpy = spyOn(document.body, 'removeChild').and.callThrough(); |
| 12 | + }); |
7 | 13 |
|
| 14 | + it('creates view', () => { |
8 | 15 | const step = createStepStub(); |
9 | 16 | const componentContext = createComponentContextStub(); |
10 | 17 |
|
11 | 18 | const component = DragStepView.create(step, 'light', componentContext); |
12 | 19 |
|
13 | 20 | expect(component).toBeDefined(); |
14 | 21 | expect(appendChildSpy).toHaveBeenCalled(); |
| 22 | + expect(document.body.getElementsByClassName('sqd-drag').length).toBe(1); |
| 23 | + |
| 24 | + component.remove(); |
| 25 | + |
| 26 | + expect(removeChildSpy).toHaveBeenCalled(); |
| 27 | + expect(document.body.getElementsByClassName('sqd-drag').length).toBe(0); |
| 28 | + }); |
| 29 | + |
| 30 | + it('does not create any placeholder', () => { |
| 31 | + const step: BranchedStep = { |
| 32 | + id: 'f00', |
| 33 | + componentType: 'switch', // This component should have at least 2 placeholders if it is not rendered as a preview. |
| 34 | + name: 'Foo', |
| 35 | + properties: {}, |
| 36 | + branches: { |
| 37 | + true: [], |
| 38 | + false: [] |
| 39 | + }, |
| 40 | + type: 'foo' |
| 41 | + }; |
| 42 | + const componentContext = createComponentContextStub(); |
| 43 | + const createForGapSpy = spyOn(componentContext.services.placeholder, 'createForGap').and.callThrough(); |
| 44 | + const createForAreaSpy = spyOn(componentContext.services.placeholder, 'createForArea').and.callThrough(); |
| 45 | + |
| 46 | + const component = DragStepView.create(step, 'light', componentContext); |
| 47 | + |
| 48 | + expect(component).toBeDefined(); |
| 49 | + expect(appendChildSpy).toHaveBeenCalled(); |
| 50 | + expect(createForGapSpy).not.toHaveBeenCalled(); |
| 51 | + expect(createForAreaSpy).not.toHaveBeenCalled(); |
| 52 | + |
| 53 | + component.remove(); |
| 54 | + |
| 55 | + expect(removeChildSpy).toHaveBeenCalled(); |
15 | 56 | }); |
16 | 57 | }); |
0 commit comments