aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/composition/palette/palette.component.spec.ts
blob: e96102bd9b444cf1fa07f942751baf86f19aeb67 (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
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 {KeyValuePipe} from "../../../pipes/key-value.pipe";
import {ResourceNamePipe} from "../../../pipes/resource-name.pipe";
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 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);
    });
});