summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/composition/palette/palette.component.spec.ts
blob: efa9cd3370b3a99e024d56a21fb80d86a654d474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {NO_ERRORS_SCHEMA} from "@angular/core";
import {CompositionPaletteService} from "./services/palette.service";
import {EventListenerService} from "../../../../services/event-listener-service";
import {PaletteElementComponent} from "./palette-element/palette-element.component";
import {PaletteComponent} from "./palette.component";
import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
import {GRAPH_EVENTS} from "../../../../utils/constants";
import {KeyValuePipe} from "../../../pipes/key-value.pipe";
import {ResourceNamePipe} from "../../../pipes/resource-name.pipe";
import {LeftPaletteComponent} from "../../../../models/components/displayComponent";
import {Observable} from "rxjs/Observable";
import {leftPaletteElements} from "../../../../../jest/mocks/left-paeltte-elements.mock";
import {NgxsModule, Select} from '@ngxs/store';
import { WorkspaceState } from 'app/ng2/store/states/workspace.state';


describe('palette component', () => {

    const mockedEvent = <MouseEvent>{ target: {} }
    let fixture: ComponentFixture<PaletteComponent>;
    let eventServiceMock: Partial<EventListenerService>;
    let compositionPaletteMockService: Partial<CompositionPaletteService>;

    beforeEach(
        async(() => {
            eventServiceMock = {
                notifyObservers: jest.fn()
            }
            compositionPaletteMockService = {
                subscribeToLeftPaletteElements:  jest.fn().mockImplementation(()=>  Observable.of(leftPaletteElements)),
                getLeftPaletteElements: jest.fn().mockImplementation(()=>  leftPaletteElements)
            }
            const configure: ConfigureFn = testBed => {
                testBed.configureTestingModule({
                    declarations: [PaletteComponent, PaletteElementComponent, KeyValuePipe, ResourceNamePipe],
                    imports: [NgxsModule.forRoot([WorkspaceState])],
                    schemas: [NO_ERRORS_SCHEMA],
                    providers: [
                        {provide: CompositionPaletteService, useValue: compositionPaletteMockService},
                        {provide: EventListenerService, useValue: eventServiceMock}
                    ],
                });
            };

            configureTests(configure).then(testBed => {
                fixture = testBed.createComponent(PaletteComponent);
            });
        })
    );

    it('should match current snapshot of palette component', () => {
        expect(fixture).toMatchSnapshot();
    });

    it('should call on palette component hover in event', () => {
        let paletteObject =  <LeftPaletteComponent>{categoryType: 'COMPONENT'};
        fixture.componentInstance.onMouseOver(mockedEvent, paletteObject);
        expect(eventServiceMock.notifyObservers).toHaveBeenCalledWith(GRAPH_EVENTS.ON_PALETTE_COMPONENT_HOVER_IN, paletteObject);
    });

    it('should call on palette component hover out event', () => {
        let paletteObject =  <LeftPaletteComponent>{categoryType: 'COMPONENT'};
        fixture.componentInstance.onMouseOut(paletteObject);
        expect(eventServiceMock.notifyObservers).toHaveBeenCalledWith(GRAPH_EVENTS.ON_PALETTE_COMPONENT_HOVER_OUT);
    });

    it('should call show popup panel event', () => {
        let paletteObject =  <LeftPaletteComponent>{categoryType: 'GROUP'};
        fixture.componentInstance.onMouseOver(mockedEvent, paletteObject);
        expect(eventServiceMock.notifyObservers).toHaveBeenCalledWith(GRAPH_EVENTS.ON_PALETTE_COMPONENT_SHOW_POPUP_PANEL, paletteObject, mockedEvent.target);
    });

    it('should call  hide popup panel event', () => {
        let paletteObject =  <LeftPaletteComponent>{categoryType: 'GROUP'};
        fixture.componentInstance.onMouseOut(paletteObject);
        expect(eventServiceMock.notifyObservers).toHaveBeenCalledWith(GRAPH_EVENTS.ON_PALETTE_COMPONENT_HIDE_POPUP_PANEL);
    });

    it('should build Palette By Categories without searchText', () => {
        fixture.componentInstance.buildPaletteByCategories();
        expect(fixture.componentInstance.paletteElements["Generic"]["Network"].length).toBe(5);
        expect(fixture.componentInstance.paletteElements["Generic"]["Network"][0].searchFilterTerms).toBe("extvirtualmachineinterfacecp external port for virtual machine interface extvirtualmachineinterfacecp 3.0");
        expect(fixture.componentInstance.paletteElements["Generic"]["Network"][1].searchFilterTerms).toBe("newservice2 asdfasdfa newservice2 0.3");

        expect(fixture.componentInstance.paletteElements["Generic"]["Configuration"].length).toBe(1);
        expect(fixture.componentInstance.paletteElements["Generic"]["Configuration"][0].systemName).toBe("Extvirtualmachineinterfacecp");
    });

    it('should build Palette By Categories with searchText', () => {
        fixture.componentInstance.buildPaletteByCategories("testVal");
        expect(fixture.componentInstance.paletteElements["Generic"]["Network"].length).toBe(1);
        expect(fixture.componentInstance.paletteElements["Generic"]["Network"][0].searchFilterTerms).toBe("testVal and other values");
    });

    it('should change numbers of elements', () => {
        fixture.componentInstance.buildPaletteByCategories();
        expect(fixture.componentInstance.numberOfElements).toEqual(6);
        fixture.componentInstance.buildPaletteByCategories("testVal");
        expect(fixture.componentInstance.numberOfElements).toEqual(1);
    });
});