@centreon/js-config 24.4.29 → 24.4.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,15 @@ interface MountProps {
18
18
  Component: React.ReactNode;
19
19
  options?: object;
20
20
  }
21
+ interface Resolution {
22
+ height: number;
23
+ width: number;
24
+ }
25
+
26
+ interface MakeSnapshotWithCustomResolution {
27
+ resolution: Resolution;
28
+ title: string;
29
+ }
21
30
 
22
31
  export enum Method {
23
32
  DELETE = 'DELETE',
@@ -97,20 +106,32 @@ Cypress.Commands.add(
97
106
  }
98
107
  );
99
108
 
100
- Cypress.Commands.add('moveSortableElement', ({ element, direction }): void => {
101
- const key = `{${direction}arrow}`;
109
+ interface MoveSortableElementProps {
110
+ direction: 'up' | 'down' | 'left' | 'right';
111
+ element: Cypress.Chainable<JQuery<HTMLElement>>;
112
+ times?: number;
113
+ }
102
114
 
103
- element.type(' ', {
104
- force: true,
105
- scrollBehavior: false
106
- });
107
- element.eq(-1).type(key, {
108
- scrollBehavior: false
109
- });
110
- element.eq(-1).type(' ', {
111
- scrollBehavior: false
112
- });
113
- });
115
+ Cypress.Commands.add(
116
+ 'moveSortableElement',
117
+ ({ element, direction, times = 1 }: MoveSortableElementProps): void => {
118
+ const key = `{${direction}arrow}`;
119
+
120
+ element.type(' ', {
121
+ force: true,
122
+ scrollBehavior: false
123
+ });
124
+
125
+ Array.from({ length: times }).forEach(() => {
126
+ element.eq(-1).type(key, {
127
+ scrollBehavior: false
128
+ });
129
+ });
130
+ element.eq(-1).type(' ', {
131
+ scrollBehavior: false
132
+ });
133
+ }
134
+ );
114
135
 
115
136
  Cypress.Commands.add(
116
137
  'moveSortableElementUsingAriaLabel',
@@ -137,6 +158,15 @@ Cypress.Commands.add('makeSnapshot', (title?: string) => {
137
158
  cy.matchImageSnapshot(title);
138
159
  });
139
160
 
161
+ Cypress.Commands.add(
162
+ 'makeSnapshotWithCustomResolution',
163
+ ({ title, resolution }: MakeSnapshotWithCustomResolution) => {
164
+ const { width, height } = resolution;
165
+ cy.viewport(width, height);
166
+ cy.matchImageSnapshot(title);
167
+ }
168
+ );
169
+
140
170
  Cypress.Commands.add('cssDisableMotion', (): void => {
141
171
  Cypress.on('window:before:load', (cyWindow) => {
142
172
  disableMotion(cyWindow);
@@ -148,13 +178,22 @@ declare global {
148
178
  interface Chainable {
149
179
  adjustViewport: () => Cypress.Chainable;
150
180
  cssDisableMotion: () => Cypress.Chainable;
181
+ getRequestCalls: (alias) => Cypress.Chainable;
151
182
  interceptAPIRequest: <T extends object>(
152
183
  props: InterceptAPIRequestProps<T>
153
184
  ) => Cypress.Chainable;
154
185
  interceptRequest: (method, path, mock, alias) => Cypress.Chainable;
155
186
  makeSnapshot: (title?: string) => void;
187
+ makeSnapshotWithCustomResolution: ({
188
+ title,
189
+ resolution
190
+ }: MakeSnapshotWithCustomResolution) => Cypress.Chainable;
156
191
  mount: ({ Component, options }: MountProps) => Cypress.Chainable;
157
- moveSortableElement: ({ element, direction }) => void;
192
+ moveSortableElement: ({
193
+ element,
194
+ direction,
195
+ times
196
+ }: MoveSortableElementProps) => void;
158
197
  moveSortableElementUsingAriaLabel: ({ ariaLabel, direction }) => void;
159
198
  waitForRequest: (alias) => Cypress.Chainable;
160
199
  }
@@ -3,6 +3,7 @@ const { defineConfig } = require('cypress');
3
3
  const {
4
4
  addMatchImageSnapshotPlugin
5
5
  } = require('@simonsmith/cypress-image-snapshot/plugin');
6
+ const cypressCodeCoverageTask = require('@cypress/code-coverage/task');
6
7
 
7
8
  module.exports = ({
8
9
  webpackConfig,
@@ -25,9 +26,12 @@ module.exports = ({
25
26
  setupNodeEvents: (on, config) => {
26
27
  addMatchImageSnapshotPlugin(on, config);
27
28
 
29
+ cypressCodeCoverageTask(on, config);
30
+
28
31
  on('before:browser:launch', (browser, launchOptions) => {
29
32
  if (browser.name === 'chrome' && browser.isHeadless) {
30
33
  launchOptions.args.push('--headless=new');
34
+ launchOptions.args.push('--force-color-profile=srgb');
31
35
  }
32
36
 
33
37
  return launchOptions;
@@ -37,8 +41,17 @@ module.exports = ({
37
41
  supportFile: `${mainCypressFolder}/support/component.tsx`
38
42
  },
39
43
  env: {
40
- ...env,
41
- baseUrl: 'http://localhost:9092'
44
+ baseUrl: 'http://localhost:9092',
45
+ codeCoverage: {
46
+ exclude: [
47
+ 'cypress/**/*.*',
48
+ 'packages/**',
49
+ 'node_modules',
50
+ '**/*.js',
51
+ '**/*.spec.tsx'
52
+ ]
53
+ },
54
+ ...env
42
55
  },
43
56
  reporter: 'mochawesome',
44
57
  reporterOptions: {
@@ -0,0 +1,36 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const filePath = process.argv[2];
5
+
6
+ const { error: logError } = console;
7
+
8
+ try {
9
+ const outFile = fs.readFileSync(path.resolve(filePath)).toString();
10
+ const outFileJson = JSON.parse(outFile);
11
+
12
+ const coveragesWithoutNodeModules = Object.entries(outFileJson)
13
+ .map(([key, value]) => {
14
+ if (key.includes('node_modules')) {
15
+ return undefined;
16
+ }
17
+
18
+ return [key, value];
19
+ })
20
+ .filter((v) => v);
21
+
22
+ const finalOutJson = coveragesWithoutNodeModules.reduce(
23
+ (acc, [key, value]) => ({
24
+ ...acc,
25
+ [key]: value
26
+ }),
27
+ {}
28
+ );
29
+
30
+ fs.writeFileSync(
31
+ path.resolve(filePath),
32
+ JSON.stringify(finalOutJson, null, 2)
33
+ );
34
+ } catch (error) {
35
+ logError(error.message);
36
+ }
@@ -138,6 +138,102 @@ Cypress.Commands.add(
138
138
  }
139
139
  );
140
140
 
141
+ interface Contact {
142
+ admin?: boolean;
143
+ alias?: string | null;
144
+ authenticationType?: 'local' | 'ldap';
145
+ email: string;
146
+ enableNotifications?: boolean;
147
+ GUIAccess?: boolean;
148
+ language?: string;
149
+ name: string;
150
+ password: string;
151
+ }
152
+
153
+ Cypress.Commands.add(
154
+ 'addContact',
155
+ ({
156
+ admin = true,
157
+ alias = null,
158
+ authenticationType = 'local',
159
+ email,
160
+ enableNotifications = true,
161
+ GUIAccess = true,
162
+ language = 'en_US',
163
+ name,
164
+ password
165
+ }: Contact): Cypress.Chainable => {
166
+ const contactAdmin = admin ? 1 : 0;
167
+ const contactAlias = alias === null ? name : alias;
168
+ const contactEnableNotifications = enableNotifications ? 1 : 0;
169
+ const contactGUIAccess = GUIAccess ? 1 : 0;
170
+
171
+ return cy
172
+ .executeActionViaClapi({
173
+ bodyContent: {
174
+ action: 'ADD',
175
+ object: 'CONTACT',
176
+ values: `${name};${contactAlias};${email};${password};${contactAdmin};${contactGUIAccess};${language};${authenticationType}`
177
+ }
178
+ })
179
+ .then(() => {
180
+ const contactParams = {
181
+ enable_notifications: contactEnableNotifications
182
+ };
183
+ Object.entries(contactParams).map(([paramName, paramValue]) => {
184
+ if (paramValue === null) {
185
+ return null;
186
+ }
187
+
188
+ return cy.executeActionViaClapi({
189
+ bodyContent: {
190
+ action: 'SETPARAM',
191
+ object: 'CONTACT',
192
+ values: `${name};${paramName};${paramValue}`
193
+ }
194
+ });
195
+ });
196
+
197
+ return cy.wrap(null);
198
+ });
199
+ }
200
+ );
201
+
202
+ interface ContactGroup {
203
+ alias?: string | null;
204
+ contacts: string[];
205
+ name: string;
206
+ }
207
+
208
+ Cypress.Commands.add(
209
+ 'addContactGroup',
210
+ ({ alias = null, contacts, name }: ContactGroup): Cypress.Chainable => {
211
+ const contactGroupAlias = alias === null ? name : alias;
212
+
213
+ return cy
214
+ .executeActionViaClapi({
215
+ bodyContent: {
216
+ action: 'ADD',
217
+ object: 'CG',
218
+ values: `${name};${contactGroupAlias}`
219
+ }
220
+ })
221
+ .then(() => {
222
+ contacts.map((contact) => {
223
+ return cy.executeActionViaClapi({
224
+ bodyContent: {
225
+ action: 'ADDCONTACT',
226
+ object: 'CG',
227
+ values: `${name};${contact}`
228
+ }
229
+ });
230
+ });
231
+
232
+ return cy.wrap(null);
233
+ });
234
+ }
235
+ );
236
+
141
237
  interface Host {
142
238
  activeCheckEnabled?: boolean;
143
239
  address?: string;
@@ -208,6 +304,26 @@ Cypress.Commands.add(
208
304
  }
209
305
  );
210
306
 
307
+ interface HostGroup {
308
+ alias?: string | null;
309
+ name: string;
310
+ }
311
+
312
+ Cypress.Commands.add(
313
+ 'addHostGroup',
314
+ ({ alias = null, name }: HostGroup): Cypress.Chainable => {
315
+ const hostGroupAlias = alias === null ? name : alias;
316
+
317
+ return cy.executeActionViaClapi({
318
+ bodyContent: {
319
+ action: 'ADD',
320
+ object: 'HG',
321
+ values: `${name};${hostGroupAlias}`
322
+ }
323
+ });
324
+ }
325
+ );
326
+
211
327
  interface ServiceTemplate {
212
328
  activeCheckEnabled?: boolean;
213
329
  checkCommand?: string | null;
@@ -329,6 +445,45 @@ Cypress.Commands.add(
329
445
  }
330
446
  );
331
447
 
448
+ interface ServiceGroup {
449
+ alias?: string | null;
450
+ hostsAndServices: string[][];
451
+ name: string;
452
+ }
453
+
454
+ Cypress.Commands.add(
455
+ 'addServiceGroup',
456
+ ({
457
+ alias = null,
458
+ hostsAndServices,
459
+ name
460
+ }: ServiceGroup): Cypress.Chainable => {
461
+ const serviceGroupAlias = alias === null ? name : alias;
462
+
463
+ return cy
464
+ .executeActionViaClapi({
465
+ bodyContent: {
466
+ action: 'ADD',
467
+ object: 'SG',
468
+ values: `${name};${serviceGroupAlias}`
469
+ }
470
+ })
471
+ .then(() => {
472
+ hostsAndServices.map((hostAndService) => {
473
+ return cy.executeActionViaClapi({
474
+ bodyContent: {
475
+ action: 'ADDSERVICE',
476
+ object: 'SG',
477
+ values: `${name};${hostAndService[0]},${hostAndService[1]}`
478
+ }
479
+ });
480
+ });
481
+
482
+ return cy.wrap(null);
483
+ });
484
+ }
485
+ );
486
+
332
487
  Cypress.Commands.add(
333
488
  'applyPollerConfiguration',
334
489
  (pollerName = 'Central'): Cypress.Chainable => {
@@ -345,8 +500,12 @@ declare global {
345
500
  namespace Cypress {
346
501
  interface Chainable {
347
502
  addCheckCommand: (props: CheckCommand) => Cypress.Chainable;
503
+ addContact: (props: Contact) => Cypress.Chainable;
504
+ addContactGroup: (props: ContactGroup) => Cypress.Chainable;
348
505
  addHost: (props: Host) => Cypress.Chainable;
506
+ addHostGroup: (props: HostGroup) => Cypress.Chainable;
349
507
  addService: (props: Service) => Cypress.Chainable;
508
+ addServiceGroup: (props: ServiceGroup) => Cypress.Chainable;
350
509
  addServiceTemplate: (props: ServiceTemplate) => Cypress.Chainable;
351
510
  addTimePeriod: (props: TimePeriod) => Cypress.Chainable;
352
511
  applyPollerConfiguration: (props?: string) => Cypress.Chainable;