@centreon/js-config 23.10.54 → 23.10.55
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.
- package/cypress/component/commands.tsx +20 -6
- package/cypress/component/configuration.js +11 -9
- package/cypress/component/disableCssTransitions.ts +19 -0
- package/cypress/component/enableVisualTesting.ts +1 -1
- package/cypress/e2e/commands/monitoring.ts +75 -0
- package/cypress/e2e/commands.ts +270 -32
- package/cypress/e2e/configuration.ts +30 -32
- package/cypress/e2e/esbuild-preprocessor.ts +26 -0
- package/cypress/e2e/plugins.ts +21 -119
- package/cypress/e2e/reporter-config.js +13 -0
- package/cypress/e2e/tasks.ts +105 -0
- package/eslint/base.typescript.eslintrc.js +15 -3
- package/eslint/lambda/typescript.eslintrc.js +48 -0
- package/jest/index.js +5 -1
- package/jest/lambda/typescript.js +49 -0
- package/package.json +18 -5
- package/tsconfig/index.json +5 -4
- package/tsconfig/lambda/tsconfig.json +14 -0
- package/webpack/base/globalConfig.js +71 -0
- package/webpack/base/index.js +14 -57
|
@@ -4,13 +4,15 @@ import React from 'react';
|
|
|
4
4
|
import { mount } from 'cypress/react18';
|
|
5
5
|
import { equals, isNil } from 'ramda';
|
|
6
6
|
|
|
7
|
-
import { Box } from '@mui/material';
|
|
7
|
+
import { Box, CssBaseline } from '@mui/material';
|
|
8
8
|
|
|
9
9
|
import { ThemeProvider } from '@centreon/ui';
|
|
10
10
|
|
|
11
11
|
import '@testing-library/cypress/add-commands';
|
|
12
12
|
import 'cypress-msw-interceptor';
|
|
13
13
|
|
|
14
|
+
import disableMotion from './disableCssTransitions';
|
|
15
|
+
|
|
14
16
|
interface MountProps {
|
|
15
17
|
Component: React.ReactNode;
|
|
16
18
|
options?: object;
|
|
@@ -24,7 +26,7 @@ export enum Method {
|
|
|
24
26
|
PUT = 'PUT'
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
Cypress.Commands.add('mount', ({ Component, options }) => {
|
|
29
|
+
Cypress.Commands.add('mount', ({ Component, options = {} }) => {
|
|
28
30
|
const wrapped = (
|
|
29
31
|
<ThemeProvider>
|
|
30
32
|
<Box
|
|
@@ -36,11 +38,10 @@ Cypress.Commands.add('mount', ({ Component, options }) => {
|
|
|
36
38
|
>
|
|
37
39
|
{Component}
|
|
38
40
|
</Box>
|
|
41
|
+
<CssBaseline />
|
|
39
42
|
</ThemeProvider>
|
|
40
43
|
);
|
|
41
44
|
|
|
42
|
-
document.getElementsByTagName('body')[0].setAttribute('style', 'margin:0px');
|
|
43
|
-
|
|
44
45
|
return mount(wrapped, options);
|
|
45
46
|
});
|
|
46
47
|
|
|
@@ -128,15 +129,28 @@ Cypress.Commands.add(
|
|
|
128
129
|
}
|
|
129
130
|
);
|
|
130
131
|
|
|
132
|
+
Cypress.Commands.add('makeSnapshot', (title?: string) => {
|
|
133
|
+
cy.viewport(1280, 590);
|
|
134
|
+
cy.matchImageSnapshot(title);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
Cypress.Commands.add('cssDisableMotion', (): void => {
|
|
138
|
+
Cypress.on('window:before:load', (cyWindow) => {
|
|
139
|
+
disableMotion(cyWindow);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
131
143
|
declare global {
|
|
132
144
|
namespace Cypress {
|
|
133
145
|
interface Chainable {
|
|
146
|
+
cssDisableMotion: () => Cypress.Chainable;
|
|
134
147
|
interceptAPIRequest: <T extends object>(
|
|
135
148
|
props: InterceptAPIRequestProps<T>
|
|
136
149
|
) => Cypress.Chainable;
|
|
137
150
|
interceptRequest: (method, path, mock, alias) => Cypress.Chainable;
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
makeSnapshot: (title?: string) => void;
|
|
152
|
+
mount: ({ Component, options }: MountProps) => Cypress.Chainable;
|
|
153
|
+
moveSortableElement: ({ element, direction }) => void;
|
|
140
154
|
moveSortableElementUsingAriaLabel: ({ ariaLabel, direction }) => void;
|
|
141
155
|
waitForRequest: (alias) => Cypress.Chainable;
|
|
142
156
|
}
|
|
@@ -4,28 +4,30 @@ const {
|
|
|
4
4
|
addMatchImageSnapshotPlugin
|
|
5
5
|
} = require('@simonsmith/cypress-image-snapshot/plugin');
|
|
6
6
|
|
|
7
|
-
module.exports = ({
|
|
7
|
+
module.exports = ({
|
|
8
|
+
webpackConfig,
|
|
9
|
+
cypressFolder,
|
|
10
|
+
specPattern,
|
|
11
|
+
env,
|
|
12
|
+
useVite = false,
|
|
13
|
+
excludeSpecPattern
|
|
14
|
+
}) => {
|
|
8
15
|
const mainCypressFolder = cypressFolder || 'cypress';
|
|
9
16
|
|
|
10
17
|
return defineConfig({
|
|
11
18
|
component: {
|
|
12
19
|
devServer: {
|
|
13
|
-
bundler: 'webpack',
|
|
20
|
+
bundler: useVite ? 'vite' : 'webpack',
|
|
14
21
|
framework: 'react',
|
|
15
22
|
webpackConfig
|
|
16
23
|
},
|
|
24
|
+
excludeSpecPattern,
|
|
17
25
|
setupNodeEvents: (on, config) => {
|
|
18
26
|
addMatchImageSnapshotPlugin(on, config);
|
|
19
27
|
|
|
20
28
|
on('before:browser:launch', (browser, launchOptions) => {
|
|
21
29
|
if (browser.name === 'chrome' && browser.isHeadless) {
|
|
22
|
-
launchOptions.args
|
|
23
|
-
if (arg === '--headless') {
|
|
24
|
-
return '--headless=new';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return arg;
|
|
28
|
-
});
|
|
30
|
+
launchOptions.args.push('--headless=new');
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
return launchOptions;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const disableMotion = (win): void => {
|
|
2
|
+
const injectedStyleEl = win.document.getElementById('__cy_disable_motion__');
|
|
3
|
+
if (injectedStyleEl) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
win.document.head.insertAdjacentHTML(
|
|
7
|
+
'beforeend',
|
|
8
|
+
`
|
|
9
|
+
<style id="__cy_disable_motion__">
|
|
10
|
+
/* Disable CSS transitions. */
|
|
11
|
+
*, *::before, *::after { -webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; -ms-transition: none !important; transition: none !important; }
|
|
12
|
+
/* Disable CSS animations. */
|
|
13
|
+
*, *::before, *::after { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; -ms-animation: none !important; animation: none !important; }
|
|
14
|
+
</style>
|
|
15
|
+
`.trim()
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default disableMotion;
|
|
@@ -13,7 +13,7 @@ const enableVisualTesting = (cypressFolder = 'cypress'): void => {
|
|
|
13
13
|
capture: 'viewport',
|
|
14
14
|
customDiffConfig: { threshold: 0.01 },
|
|
15
15
|
customSnapshotsDir: `${cypressFolder}/visual-testing-snapshots`,
|
|
16
|
-
failureThreshold: 0.
|
|
16
|
+
failureThreshold: 0.07,
|
|
17
17
|
failureThresholdType: 'percent'
|
|
18
18
|
});
|
|
19
19
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
|
|
3
|
+
const apiBase = '/centreon/api';
|
|
4
|
+
const apiActionV1 = `${apiBase}/index.php`;
|
|
5
|
+
|
|
6
|
+
const getStatusNumberFromString = (status: string): number => {
|
|
7
|
+
const statuses = {
|
|
8
|
+
critical: '2',
|
|
9
|
+
down: '1',
|
|
10
|
+
ok: '0',
|
|
11
|
+
unknown: '3',
|
|
12
|
+
unreachable: '2',
|
|
13
|
+
up: '0',
|
|
14
|
+
warning: '1'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
if (status in statuses) {
|
|
18
|
+
return statuses[status];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
throw new Error(`Status ${status} does not exist`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
interface SubmitResult {
|
|
25
|
+
host: string;
|
|
26
|
+
output: string;
|
|
27
|
+
perfdata?: string | null;
|
|
28
|
+
service?: string | null;
|
|
29
|
+
status: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Cypress.Commands.add(
|
|
33
|
+
'submitResults',
|
|
34
|
+
(results: Array<SubmitResult>): Cypress.Chainable => {
|
|
35
|
+
results.forEach(
|
|
36
|
+
({ host, output, perfdata = '', service = null, status }) => {
|
|
37
|
+
const timestampNow = Math.floor(Date.now() / 1000) - 15;
|
|
38
|
+
const updatetime = timestampNow.toString();
|
|
39
|
+
|
|
40
|
+
const result = {
|
|
41
|
+
host,
|
|
42
|
+
output,
|
|
43
|
+
perfdata,
|
|
44
|
+
service,
|
|
45
|
+
status: getStatusNumberFromString(status),
|
|
46
|
+
updatetime
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
cy.request({
|
|
50
|
+
body: {
|
|
51
|
+
results: [result]
|
|
52
|
+
},
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
'centreon-auth-token': window.localStorage.getItem('userTokenApiV1')
|
|
56
|
+
},
|
|
57
|
+
method: 'POST',
|
|
58
|
+
url: `${apiActionV1}?action=submit&object=centreon_submit_results`
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return cy.wrap(null);
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
declare global {
|
|
68
|
+
namespace Cypress {
|
|
69
|
+
interface Chainable {
|
|
70
|
+
submitResults: (props: Array<SubmitResult>) => Cypress.Chainable;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {};
|
package/cypress/e2e/commands.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
2
|
|
|
3
3
|
import './commands/configuration';
|
|
4
|
+
import './commands/monitoring';
|
|
5
|
+
|
|
6
|
+
import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector';
|
|
7
|
+
|
|
8
|
+
installLogsCollector({ enableExtendedCollector: true });
|
|
4
9
|
|
|
5
10
|
const apiLoginV2 = '/centreon/authentication/providers/configurations/local';
|
|
6
11
|
|
|
@@ -23,7 +28,7 @@ Cypress.Commands.add('getWebVersion', (): Cypress.Chainable => {
|
|
|
23
28
|
|
|
24
29
|
Cypress.Commands.add('getIframeBody', (): Cypress.Chainable => {
|
|
25
30
|
return cy
|
|
26
|
-
.get('iframe#main-content')
|
|
31
|
+
.get('iframe#main-content', { timeout: 10000 })
|
|
27
32
|
.its('0.contentDocument.body')
|
|
28
33
|
.should('not.be.empty')
|
|
29
34
|
.then(cy.wrap);
|
|
@@ -39,6 +44,13 @@ Cypress.Commands.add(
|
|
|
39
44
|
}
|
|
40
45
|
);
|
|
41
46
|
|
|
47
|
+
Cypress.Commands.add(
|
|
48
|
+
'clickSubRootMenuItem',
|
|
49
|
+
(page: string): Cypress.Chainable => {
|
|
50
|
+
return cy.get('div[data-cy="collapse"]').eq(1).contains(page).click();
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
42
54
|
interface NavigateToProps {
|
|
43
55
|
page: string;
|
|
44
56
|
rootItemNumber: number;
|
|
@@ -51,8 +63,13 @@ Cypress.Commands.add(
|
|
|
51
63
|
if (subMenu) {
|
|
52
64
|
cy.hoverRootMenuItem(rootItemNumber)
|
|
53
65
|
.contains(subMenu)
|
|
54
|
-
.trigger('mouseover'
|
|
55
|
-
|
|
66
|
+
.trigger('mouseover')
|
|
67
|
+
.get('.MuiCollapse-wrapper')
|
|
68
|
+
.find('div[data-cy="collapse"]')
|
|
69
|
+
.should('be.visible')
|
|
70
|
+
.and('contain', page);
|
|
71
|
+
|
|
72
|
+
cy.clickSubRootMenuItem(page);
|
|
56
73
|
|
|
57
74
|
return;
|
|
58
75
|
}
|
|
@@ -85,29 +102,41 @@ Cypress.Commands.add(
|
|
|
85
102
|
|
|
86
103
|
interface CopyFromContainerProps {
|
|
87
104
|
destination: string;
|
|
105
|
+
name?: string;
|
|
88
106
|
source: string;
|
|
89
107
|
}
|
|
90
108
|
|
|
91
109
|
Cypress.Commands.add(
|
|
92
110
|
'copyFromContainer',
|
|
93
|
-
(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
(
|
|
112
|
+
{
|
|
113
|
+
name = Cypress.env('dockerName'),
|
|
114
|
+
source,
|
|
115
|
+
destination
|
|
116
|
+
}: CopyFromContainerProps,
|
|
117
|
+
options?: Partial<Cypress.ExecOptions>
|
|
118
|
+
) => {
|
|
119
|
+
return cy.exec(`docker cp ${name}:${source} "${destination}"`, options);
|
|
97
120
|
}
|
|
98
121
|
);
|
|
99
122
|
|
|
100
123
|
interface CopyToContainerProps {
|
|
101
124
|
destination: string;
|
|
125
|
+
name?: string;
|
|
102
126
|
source: string;
|
|
103
127
|
}
|
|
104
128
|
|
|
105
129
|
Cypress.Commands.add(
|
|
106
130
|
'copyToContainer',
|
|
107
|
-
(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
131
|
+
(
|
|
132
|
+
{
|
|
133
|
+
name = Cypress.env('dockerName'),
|
|
134
|
+
source,
|
|
135
|
+
destination
|
|
136
|
+
}: CopyToContainerProps,
|
|
137
|
+
options?: Partial<Cypress.ExecOptions>
|
|
138
|
+
) => {
|
|
139
|
+
return cy.exec(`docker cp ${source} ${name}:${destination}`, options);
|
|
111
140
|
}
|
|
112
141
|
);
|
|
113
142
|
|
|
@@ -118,7 +147,7 @@ interface LoginByTypeOfUserProps {
|
|
|
118
147
|
|
|
119
148
|
Cypress.Commands.add(
|
|
120
149
|
'loginByTypeOfUser',
|
|
121
|
-
({ jsonName, loginViaApi }): Cypress.Chainable => {
|
|
150
|
+
({ jsonName = 'admin', loginViaApi = false }): Cypress.Chainable => {
|
|
122
151
|
if (loginViaApi) {
|
|
123
152
|
return cy
|
|
124
153
|
.fixture(`users/${jsonName}.json`)
|
|
@@ -135,12 +164,15 @@ Cypress.Commands.add(
|
|
|
135
164
|
.visit(`${Cypress.config().baseUrl}`)
|
|
136
165
|
.wait('@getNavigationList');
|
|
137
166
|
}
|
|
167
|
+
|
|
138
168
|
cy.visit(`${Cypress.config().baseUrl}`)
|
|
139
169
|
.fixture(`users/${jsonName}.json`)
|
|
140
170
|
.then((credential) => {
|
|
141
|
-
cy.getByLabel({ label: 'Alias', tag: 'input' }).type(
|
|
171
|
+
cy.getByLabel({ label: 'Alias', tag: 'input' }).type(
|
|
172
|
+
`{selectAll}{backspace}${credential.login}`
|
|
173
|
+
);
|
|
142
174
|
cy.getByLabel({ label: 'Password', tag: 'input' }).type(
|
|
143
|
-
credential.password
|
|
175
|
+
`{selectAll}{backspace}${credential.password}`
|
|
144
176
|
);
|
|
145
177
|
})
|
|
146
178
|
.getByLabel({ label: 'Connect', tag: 'button' })
|
|
@@ -210,9 +242,20 @@ interface StartContainerProps {
|
|
|
210
242
|
Cypress.Commands.add(
|
|
211
243
|
'startContainer',
|
|
212
244
|
({ name, image, portBindings }: StartContainerProps): Cypress.Chainable => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
245
|
+
cy.log(`Starting container ${name} from image ${image}`);
|
|
246
|
+
|
|
247
|
+
return cy.task(
|
|
248
|
+
'startContainer',
|
|
249
|
+
{ image, name, portBindings },
|
|
250
|
+
{ timeout: 600000 } // 10 minutes because docker pull can be very slow
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
Cypress.Commands.add(
|
|
256
|
+
'createDirectory',
|
|
257
|
+
(directoryPath: string): Cypress.Chainable => {
|
|
258
|
+
return cy.task('createDirectory', directoryPath);
|
|
216
259
|
}
|
|
217
260
|
);
|
|
218
261
|
|
|
@@ -227,7 +270,7 @@ Cypress.Commands.add(
|
|
|
227
270
|
'startWebContainer',
|
|
228
271
|
({
|
|
229
272
|
name = Cypress.env('dockerName'),
|
|
230
|
-
os = '
|
|
273
|
+
os = Cypress.env('WEB_IMAGE_OS'),
|
|
231
274
|
useSlim = true,
|
|
232
275
|
version = Cypress.env('WEB_IMAGE_VERSION')
|
|
233
276
|
}: StartWebContainerProps = {}): Cypress.Chainable => {
|
|
@@ -242,12 +285,13 @@ Cypress.Commands.add(
|
|
|
242
285
|
portBindings: [{ destination: 4000, source: 80 }]
|
|
243
286
|
})
|
|
244
287
|
.then(() => {
|
|
245
|
-
const baseUrl = 'http://
|
|
288
|
+
const baseUrl = 'http://127.0.0.1:4000';
|
|
246
289
|
|
|
247
290
|
Cypress.config('baseUrl', baseUrl);
|
|
248
291
|
|
|
249
|
-
return cy.
|
|
250
|
-
|
|
292
|
+
return cy.task(
|
|
293
|
+
'waitOn',
|
|
294
|
+
`${baseUrl}/centreon/api/latest/platform/installation/status`
|
|
251
295
|
);
|
|
252
296
|
})
|
|
253
297
|
.visit('/') // this is necessary to refresh browser cause baseUrl has changed (flash appears in video)
|
|
@@ -274,25 +318,41 @@ Cypress.Commands.add(
|
|
|
274
318
|
|
|
275
319
|
return cy
|
|
276
320
|
.visitEmptyPage()
|
|
277
|
-
.
|
|
321
|
+
.createDirectory(logDirectory)
|
|
278
322
|
.copyFromContainer({
|
|
279
323
|
destination: `${logDirectory}/broker`,
|
|
324
|
+
name,
|
|
280
325
|
source: '/var/log/centreon-broker'
|
|
281
326
|
})
|
|
282
327
|
.copyFromContainer({
|
|
283
328
|
destination: `${logDirectory}/engine`,
|
|
329
|
+
name,
|
|
284
330
|
source: '/var/log/centreon-engine'
|
|
285
331
|
})
|
|
286
|
-
.execInContainer({
|
|
287
|
-
command: `bash -e <<EOF
|
|
288
|
-
chmod 777 /var/log/centreon/centreon-web.log > /dev/null 2>&1 || :
|
|
289
|
-
EOF`,
|
|
290
|
-
name
|
|
291
|
-
})
|
|
292
332
|
.copyFromContainer({
|
|
293
333
|
destination: `${logDirectory}/centreon`,
|
|
334
|
+
name,
|
|
294
335
|
source: '/var/log/centreon'
|
|
295
336
|
})
|
|
337
|
+
.then(() => {
|
|
338
|
+
if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
|
|
339
|
+
return cy.copyFromContainer({
|
|
340
|
+
destination: `${logDirectory}/php`,
|
|
341
|
+
name,
|
|
342
|
+
source: '/var/log/php-fpm'
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return cy.copyFromContainer(
|
|
347
|
+
{
|
|
348
|
+
destination: `${logDirectory}/php8.1-fpm-centreon-error.log`,
|
|
349
|
+
name,
|
|
350
|
+
source: '/var/log/php8.1-fpm-centreon-error.log'
|
|
351
|
+
},
|
|
352
|
+
{ failOnNonZeroExit: false }
|
|
353
|
+
);
|
|
354
|
+
})
|
|
355
|
+
.exec(`chmod -R 755 "${logDirectory}"`)
|
|
296
356
|
.stopContainer({ name });
|
|
297
357
|
}
|
|
298
358
|
);
|
|
@@ -304,6 +364,8 @@ interface StopContainerProps {
|
|
|
304
364
|
Cypress.Commands.add(
|
|
305
365
|
'stopContainer',
|
|
306
366
|
({ name }: StopContainerProps): Cypress.Chainable => {
|
|
367
|
+
cy.log(`Stopping container ${name}`);
|
|
368
|
+
|
|
307
369
|
cy.exec(`docker logs ${name}`).then(({ stdout }) => {
|
|
308
370
|
cy.writeFile(
|
|
309
371
|
`cypress/results/logs/${Cypress.spec.name.replace(
|
|
@@ -321,21 +383,192 @@ Cypress.Commands.add(
|
|
|
321
383
|
}
|
|
322
384
|
);
|
|
323
385
|
|
|
386
|
+
interface Dashboard {
|
|
387
|
+
description?: string;
|
|
388
|
+
name: string;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
Cypress.Commands.add(
|
|
392
|
+
'insertDashboardList',
|
|
393
|
+
(fixtureFile: string): Cypress.Chainable => {
|
|
394
|
+
return cy.fixture(fixtureFile).then((dashboardList) => {
|
|
395
|
+
cy.wrap(
|
|
396
|
+
Promise.all(
|
|
397
|
+
dashboardList.map((dashboardBody: Dashboard) =>
|
|
398
|
+
cy.insertDashboard({ ...dashboardBody })
|
|
399
|
+
)
|
|
400
|
+
)
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
Cypress.Commands.add(
|
|
407
|
+
'insertDashboard',
|
|
408
|
+
(dashboardBody: Dashboard): Cypress.Chainable => {
|
|
409
|
+
return cy.request({
|
|
410
|
+
body: {
|
|
411
|
+
...dashboardBody
|
|
412
|
+
},
|
|
413
|
+
method: 'POST',
|
|
414
|
+
url: '/centreon/api/latest/configuration/dashboards'
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
Cypress.Commands.add(
|
|
420
|
+
'insertDashboardWithWidget',
|
|
421
|
+
(dashboardBody, patchBody) => {
|
|
422
|
+
cy.request({
|
|
423
|
+
body: {
|
|
424
|
+
...dashboardBody
|
|
425
|
+
},
|
|
426
|
+
method: 'POST',
|
|
427
|
+
url: '/centreon/api/latest/configuration/dashboards'
|
|
428
|
+
}).then((response) => {
|
|
429
|
+
const dashboardId = response.body.id;
|
|
430
|
+
cy.waitUntil(
|
|
431
|
+
() => {
|
|
432
|
+
return cy
|
|
433
|
+
.request({
|
|
434
|
+
method: 'GET',
|
|
435
|
+
url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
|
|
436
|
+
})
|
|
437
|
+
.then((getResponse) => {
|
|
438
|
+
return getResponse.body && getResponse.body.id === dashboardId;
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
timeout: 10000
|
|
443
|
+
}
|
|
444
|
+
);
|
|
445
|
+
cy.request({
|
|
446
|
+
body: patchBody,
|
|
447
|
+
method: 'PATCH',
|
|
448
|
+
url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
interface ShareDashboardToUserProps {
|
|
455
|
+
dashboardName: string;
|
|
456
|
+
role: string;
|
|
457
|
+
userName: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
interface ListingRequestResult {
|
|
461
|
+
body: {
|
|
462
|
+
result: Array<{
|
|
463
|
+
id: number;
|
|
464
|
+
}>;
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
interface PatchDashboardBody {
|
|
469
|
+
panels: Array<{
|
|
470
|
+
layout: {
|
|
471
|
+
height: number;
|
|
472
|
+
min_height: number;
|
|
473
|
+
min_width: number;
|
|
474
|
+
width: number;
|
|
475
|
+
x: number;
|
|
476
|
+
y: number;
|
|
477
|
+
};
|
|
478
|
+
name: string;
|
|
479
|
+
widget_settings: {
|
|
480
|
+
options: {
|
|
481
|
+
description: {
|
|
482
|
+
content: string;
|
|
483
|
+
enabled: boolean;
|
|
484
|
+
};
|
|
485
|
+
name: string;
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
widget_type: string;
|
|
489
|
+
}>;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
Cypress.Commands.add(
|
|
493
|
+
'shareDashboardToUser',
|
|
494
|
+
({ dashboardName, userName, role }: ShareDashboardToUserProps): void => {
|
|
495
|
+
Promise.all([
|
|
496
|
+
cy.request({
|
|
497
|
+
method: 'GET',
|
|
498
|
+
url: `/centreon/api/latest/configuration/users?search={"name":"${userName}"}`
|
|
499
|
+
}),
|
|
500
|
+
cy.request({
|
|
501
|
+
method: 'GET',
|
|
502
|
+
url: `/centreon/api/latest/configuration/dashboards?search={"name":"${dashboardName}"}`
|
|
503
|
+
})
|
|
504
|
+
]).then(
|
|
505
|
+
([retrievedUser, retrievedDashboard]: [
|
|
506
|
+
ListingRequestResult,
|
|
507
|
+
ListingRequestResult
|
|
508
|
+
]) => {
|
|
509
|
+
const userId = retrievedUser.body.result[0].id;
|
|
510
|
+
const dashboardId = retrievedDashboard.body.result[0].id;
|
|
511
|
+
|
|
512
|
+
cy.request({
|
|
513
|
+
body: {
|
|
514
|
+
id: userId,
|
|
515
|
+
role: `${role}`
|
|
516
|
+
},
|
|
517
|
+
method: 'POST',
|
|
518
|
+
url: `/centreon/api/latest/configuration/dashboards/${dashboardId}/access_rights/contacts`
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
Cypress.Commands.add('getTimeFromHeader', (): Cypress.Chainable => {
|
|
526
|
+
return cy
|
|
527
|
+
.get('header div[data-cy="clock"]', { timeout: 10000 })
|
|
528
|
+
.should('be.visible')
|
|
529
|
+
.then(($time) => {
|
|
530
|
+
const headerTime = $time.children()[1].textContent;
|
|
531
|
+
if (headerTime?.match(/\d+:\d+/)) {
|
|
532
|
+
cy.log(`header time is : ${headerTime}`);
|
|
533
|
+
|
|
534
|
+
return cy.wrap(headerTime);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
throw new Error(`header time is not displayed`);
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
|
|
324
541
|
declare global {
|
|
325
542
|
namespace Cypress {
|
|
326
543
|
interface Chainable {
|
|
327
|
-
|
|
328
|
-
|
|
544
|
+
clickSubRootMenuItem: (page: string) => Cypress.Chainable;
|
|
545
|
+
copyFromContainer: (
|
|
546
|
+
props: CopyFromContainerProps,
|
|
547
|
+
options?: Partial<Cypress.ExecOptions>
|
|
548
|
+
) => Cypress.Chainable;
|
|
549
|
+
copyToContainer: (
|
|
550
|
+
props: CopyToContainerProps,
|
|
551
|
+
options?: Partial<Cypress.ExecOptions>
|
|
552
|
+
) => Cypress.Chainable;
|
|
553
|
+
createDirectory: (directoryPath: string) => Cypress.Chainable;
|
|
329
554
|
execInContainer: ({
|
|
330
555
|
command,
|
|
331
556
|
name
|
|
332
557
|
}: ExecInContainerProps) => Cypress.Chainable;
|
|
333
558
|
getIframeBody: () => Cypress.Chainable;
|
|
559
|
+
getTimeFromHeader: () => Cypress.Chainable;
|
|
334
560
|
getWebVersion: () => Cypress.Chainable;
|
|
335
561
|
hoverRootMenuItem: (rootItemNumber: number) => Cypress.Chainable;
|
|
562
|
+
insertDashboard: (dashboard: Dashboard) => Cypress.Chainable;
|
|
563
|
+
insertDashboardList: (fixtureFile: string) => Cypress.Chainable;
|
|
564
|
+
insertDashboardWithWidget: (
|
|
565
|
+
dashboard: Dashboard,
|
|
566
|
+
patch: PatchDashboardBody
|
|
567
|
+
) => Cypress.Chainable;
|
|
568
|
+
|
|
336
569
|
loginByTypeOfUser: ({
|
|
337
|
-
jsonName
|
|
338
|
-
loginViaApi
|
|
570
|
+
jsonName,
|
|
571
|
+
loginViaApi
|
|
339
572
|
}: LoginByTypeOfUserProps) => Cypress.Chainable;
|
|
340
573
|
moveSortableElement: (direction: string) => Cypress.Chainable;
|
|
341
574
|
navigateTo: ({
|
|
@@ -343,6 +576,11 @@ declare global {
|
|
|
343
576
|
rootItemNumber,
|
|
344
577
|
subMenu
|
|
345
578
|
}: NavigateToProps) => Cypress.Chainable;
|
|
579
|
+
shareDashboardToUser: ({
|
|
580
|
+
dashboardName,
|
|
581
|
+
userName,
|
|
582
|
+
role
|
|
583
|
+
}: ShareDashboardToUserProps) => Cypress.Chainable;
|
|
346
584
|
startContainer: ({
|
|
347
585
|
name,
|
|
348
586
|
image
|