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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture } from '@angular/core/testing';
import { PluginsConfiguration } from 'app/models';
import { Observable } from 'rxjs';
import { Mock } from 'ts-mockery';
import { ConfigureFn, configureTests } from '../../../../../jest/test-config.helper';
import { MenuItem, MenuItemGroup } from '../../../../utils/menu-handler';
import { SdcConfigToken } from '../../../config/sdc-config.config';
import { AuthenticationService } from '../../../services/authentication.service';
import { TranslateModule } from '../../../shared/translator/translate.module';
import { TranslateService } from '../../../shared/translator/translate.service';
import { TopNavComponent } from './top-nav.component';
describe('artifact form component', () => {
let fixture: ComponentFixture<TopNavComponent>;
let translateServiceMock: Partial<TranslateService>;
let mockStateService;
let authServiceMock;
const designerUser = {
email: 'designer@sdc.com',
firstName: 'Carlos',
fullName: 'Carlos Santana',
lastLoginTime: 1555587266566,
lastName: 'Santana',
role: 'DESIGNER',
status: 'ACTIVE',
userId: 'cs0008'
};
const pluginDisplayOptions = {
displayName : '',
displayContext : new Array<string>(),
displayRoles : new Array<string>()
};
let roleToReturn = designerUser;
const map1 = new Map();
map1.otherValue = pluginDisplayOptions;
const map2 = new Map();
pluginDisplayOptions.displayRoles = ['DESIGNER'];
pluginDisplayOptions.displayName = 'DCAE-DS';
map2.tab = pluginDisplayOptions;
PluginsConfiguration.plugins =
[
{pluginId: 'DCAED', pluginDiscoveryUrl: 'DCAED_discoveryURL', pluginSourceUrl: 'DCAED_sourceURL', pluginStateUrl: 'DCAED_stateURL', pluginDisplayOptions: map1, isOnline: true},
{pluginId: 'DCAE-DS', pluginDiscoveryUrl: 'DCAE-DS_discoveryURL', pluginSourceUrl: 'DCAE-DS_sourceURL', pluginStateUrl: 'DCAE-DS_stateURL', pluginDisplayOptions: map2, isOnline: true}
];
beforeEach(
async(() => {
authServiceMock = {
getLoggedinUser: jest.fn().mockImplementation(() => {
return roleToReturn;
})
};
mockStateService = {
go: jest.fn(),
includes: jest.fn(() => true),
current : {
name : 'plugins'
},
params : {}
};
translateServiceMock = {
languageChangedObservable: Mock.of<Observable<string>>( {
subscribe : jest.fn().mockImplementation((cb) => {
cb();
})
}),
translate: jest.fn((str: string) => {
if (str === 'TOP_MENU_HOME_BUTTON') {
return 'HOME';
} else if (str === 'TOP_MENU_CATALOG_BUTTON') {
return 'CATALOG';
} else if (str === 'TOP_MENU_ON_BOARD_BUTTON') {
return 'ONBOARD';
} else {
return 'TBD...';
}
})
};
const configure: ConfigureFn = (testBed) => {
testBed.configureTestingModule({
declarations: [TopNavComponent],
imports: [TranslateModule],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: TranslateService, useValue: translateServiceMock},
{provide: '$state', useValue: mockStateService},
{provide: AuthenticationService, useValue: authServiceMock},
{provide: SdcConfigToken, useValue: {csarFileExtension: 'csar', toscaFileExtension: 'yaml,yml'}},
],
});
};
configureTests(configure).then((testBed) => {
fixture = testBed.createComponent(TopNavComponent);
});
})
);
it('should match current snapshot of top-nav component', () => {
expect(fixture).toMatchSnapshot();
});
it('Once a Designer logged in, Menu Items will contain HOME, CATALOG, ONBOARD & DCAE-DS; HOME will be selected', () => {
// topLvlSelectedIndex = 1 => Ignore the inner call to _getTopLvlSelectedIndexByState.
fixture.componentInstance.topLvlSelectedIndex = 0;
fixture.componentInstance.ngOnInit();
expect(fixture.componentInstance.topLvlMenu.itemClick).toBe(true);
expect(fixture.componentInstance.topLvlMenu.menuItems.length).toBe(4);
expect(fixture.componentInstance.topLvlMenu.menuItems[0]).toEqual({
action: 'goToState',
blockedForTypes: null,
callback: null,
params: null,
state: 'dashboard',
text: 'HOME'
});
expect(fixture.componentInstance.topLvlMenu.menuItems[1]).toEqual({
action: 'goToState',
blockedForTypes: null,
callback: null,
params: null,
state: 'catalog',
text: 'CATALOG'
});
expect(fixture.componentInstance.topLvlMenu.menuItems[2]).toEqual({
action: 'goToState',
blockedForTypes: null,
callback: null,
params: null,
state: 'onboardVendor',
text: 'ONBOARD'
});
expect(fixture.componentInstance.topLvlMenu.menuItems[3]).toEqual({
action: 'goToState',
blockedForTypes: null,
callback: null,
params:
{path: 'DCAE-DS_stateURL'},
state: 'plugins',
text: 'DCAE-DS'
});
expect(fixture.componentInstance.topLvlMenu.selectedIndex).toBe(0);
});
});
|