@centreon/js-config 24.4.9 → 24.4.10
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 +53 -19
- package/cypress/component/configuration.js +28 -12
- package/cypress/component/disableCssTransitions.ts +19 -0
- package/cypress/component/enableVisualTesting.ts +1 -1
- package/cypress/e2e/commands/configuration.ts +3 -1
- package/cypress/e2e/commands/monitoring.ts +75 -0
- package/cypress/e2e/commands.ts +298 -59
- 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 -2
- package/jest/lambda/typescript.js +49 -0
- package/package.json +61 -45
- package/tsconfig/index.json +5 -4
- package/tsconfig/lambda/node20.tsconfig.json +12 -0
- package/tsconfig/lambda/tsconfig.json +14 -0
- package/webpack/base/globalConfig.js +76 -0
- package/webpack/base/index.js +20 -59
|
@@ -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
|
|
|
@@ -95,20 +96,32 @@ Cypress.Commands.add(
|
|
|
95
96
|
}
|
|
96
97
|
);
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
interface MoveSortableElementProps {
|
|
100
|
+
direction: 'up' | 'down' | 'left' | 'right';
|
|
101
|
+
element: Cypress.Chainable<JQuery<HTMLElement>>;
|
|
102
|
+
times?: number;
|
|
103
|
+
}
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
105
|
+
Cypress.Commands.add(
|
|
106
|
+
'moveSortableElement',
|
|
107
|
+
({ element, direction, times = 1 }: MoveSortableElementProps): void => {
|
|
108
|
+
const key = `{${direction}arrow}`;
|
|
109
|
+
|
|
110
|
+
element.type(' ', {
|
|
111
|
+
force: true,
|
|
112
|
+
scrollBehavior: false
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
Array.from({ length: times }).forEach(() => {
|
|
116
|
+
element.eq(-1).type(key, {
|
|
117
|
+
scrollBehavior: false
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
element.eq(-1).type(' ', {
|
|
121
|
+
scrollBehavior: false
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
);
|
|
112
125
|
|
|
113
126
|
Cypress.Commands.add(
|
|
114
127
|
'moveSortableElementUsingAriaLabel',
|
|
@@ -128,15 +141,36 @@ Cypress.Commands.add(
|
|
|
128
141
|
}
|
|
129
142
|
);
|
|
130
143
|
|
|
144
|
+
Cypress.Commands.add('adjustViewport', () => cy.viewport(1280, 590));
|
|
145
|
+
|
|
146
|
+
Cypress.Commands.add('makeSnapshot', (title?: string) => {
|
|
147
|
+
cy.adjustViewport();
|
|
148
|
+
cy.matchImageSnapshot(title);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
Cypress.Commands.add('cssDisableMotion', (): void => {
|
|
152
|
+
Cypress.on('window:before:load', (cyWindow) => {
|
|
153
|
+
disableMotion(cyWindow);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
131
157
|
declare global {
|
|
132
158
|
namespace Cypress {
|
|
133
159
|
interface Chainable {
|
|
160
|
+
adjustViewport: () => Cypress.Chainable;
|
|
161
|
+
cssDisableMotion: () => Cypress.Chainable;
|
|
162
|
+
getRequestCalls: (alias) => Cypress.Chainable;
|
|
134
163
|
interceptAPIRequest: <T extends object>(
|
|
135
164
|
props: InterceptAPIRequestProps<T>
|
|
136
165
|
) => Cypress.Chainable;
|
|
137
166
|
interceptRequest: (method, path, mock, alias) => Cypress.Chainable;
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
makeSnapshot: (title?: string) => void;
|
|
168
|
+
mount: ({ Component, options }: MountProps) => Cypress.Chainable;
|
|
169
|
+
moveSortableElement: ({
|
|
170
|
+
element,
|
|
171
|
+
direction,
|
|
172
|
+
times
|
|
173
|
+
}: MoveSortableElementProps) => void;
|
|
140
174
|
moveSortableElementUsingAriaLabel: ({ ariaLabel, direction }) => void;
|
|
141
175
|
waitForRequest: (alias) => Cypress.Chainable;
|
|
142
176
|
}
|
|
@@ -3,29 +3,34 @@ 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
|
-
module.exports = ({
|
|
8
|
+
module.exports = ({
|
|
9
|
+
webpackConfig,
|
|
10
|
+
cypressFolder,
|
|
11
|
+
specPattern,
|
|
12
|
+
env,
|
|
13
|
+
useVite = false,
|
|
14
|
+
excludeSpecPattern
|
|
15
|
+
}) => {
|
|
8
16
|
const mainCypressFolder = cypressFolder || 'cypress';
|
|
9
17
|
|
|
10
18
|
return defineConfig({
|
|
11
19
|
component: {
|
|
12
20
|
devServer: {
|
|
13
|
-
bundler: 'webpack',
|
|
21
|
+
bundler: useVite ? 'vite' : 'webpack',
|
|
14
22
|
framework: 'react',
|
|
15
23
|
webpackConfig
|
|
16
24
|
},
|
|
25
|
+
excludeSpecPattern,
|
|
17
26
|
setupNodeEvents: (on, config) => {
|
|
18
27
|
addMatchImageSnapshotPlugin(on, config);
|
|
19
28
|
|
|
29
|
+
cypressCodeCoverageTask(on, config);
|
|
30
|
+
|
|
20
31
|
on('before:browser:launch', (browser, launchOptions) => {
|
|
21
32
|
if (browser.name === 'chrome' && browser.isHeadless) {
|
|
22
|
-
launchOptions.args
|
|
23
|
-
if (arg === '--headless') {
|
|
24
|
-
return '--headless=new';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return arg;
|
|
28
|
-
});
|
|
33
|
+
launchOptions.args.push('--headless=new');
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
return launchOptions;
|
|
@@ -35,8 +40,17 @@ module.exports = ({ webpackConfig, cypressFolder, specPattern, env }) => {
|
|
|
35
40
|
supportFile: `${mainCypressFolder}/support/component.tsx`
|
|
36
41
|
},
|
|
37
42
|
env: {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
baseUrl: 'http://localhost:9092',
|
|
44
|
+
codeCoverage: {
|
|
45
|
+
exclude: [
|
|
46
|
+
'cypress/**/*.*',
|
|
47
|
+
'packages/**',
|
|
48
|
+
'node_modules',
|
|
49
|
+
'**/*.js',
|
|
50
|
+
'**/*.spec.tsx'
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
...env
|
|
40
54
|
},
|
|
41
55
|
reporter: 'mochawesome',
|
|
42
56
|
reporterOptions: {
|
|
@@ -47,6 +61,8 @@ module.exports = ({ webpackConfig, cypressFolder, specPattern, env }) => {
|
|
|
47
61
|
reportFilename: '[name]-report.json'
|
|
48
62
|
},
|
|
49
63
|
video: true,
|
|
50
|
-
videosFolder: `${mainCypressFolder}/results/videos
|
|
64
|
+
videosFolder: `${mainCypressFolder}/results/videos`,
|
|
65
|
+
viewportHeight: 590,
|
|
66
|
+
viewportWidth: 1280
|
|
51
67
|
});
|
|
52
68
|
};
|
|
@@ -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
|
};
|
|
@@ -144,6 +144,7 @@ interface Host {
|
|
|
144
144
|
alias?: string | null;
|
|
145
145
|
checkCommand?: string | null;
|
|
146
146
|
checkPeriod?: string | null;
|
|
147
|
+
hostGroup?: string;
|
|
147
148
|
maxCheckAttempts?: number | null;
|
|
148
149
|
name: string;
|
|
149
150
|
passiveCheckEnabled?: boolean;
|
|
@@ -159,6 +160,7 @@ Cypress.Commands.add(
|
|
|
159
160
|
alias = null,
|
|
160
161
|
checkCommand = null,
|
|
161
162
|
checkPeriod = null,
|
|
163
|
+
hostGroup = '',
|
|
162
164
|
maxCheckAttempts = 1,
|
|
163
165
|
name,
|
|
164
166
|
passiveCheckEnabled = true,
|
|
@@ -176,7 +178,7 @@ Cypress.Commands.add(
|
|
|
176
178
|
bodyContent: {
|
|
177
179
|
action: 'ADD',
|
|
178
180
|
object: 'HOST',
|
|
179
|
-
values: `${name};${hostAlias};${address};${template};${poller}
|
|
181
|
+
values: `${name};${hostAlias};${address};${template};${poller};${hostGroup}`
|
|
180
182
|
}
|
|
181
183
|
})
|
|
182
184
|
.then(() => {
|
|
@@ -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 {};
|