@centreon/js-config 23.4.21-MON-fix-image-snapshot.4 → 23.4.22-0

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.
@@ -2,11 +2,13 @@
2
2
  import React from 'react';
3
3
 
4
4
  import { mount } from 'cypress/react18';
5
+ import { equals, isNil } from 'ramda';
5
6
 
6
7
  import { Box } from '@mui/material';
7
8
 
8
9
  import { ThemeProvider } from '@centreon/ui';
9
10
 
11
+ import '@testing-library/cypress/add-commands';
10
12
  import 'cypress-msw-interceptor';
11
13
 
12
14
  interface MountProps {
@@ -29,7 +31,6 @@ Cypress.Commands.add('mount', ({ Component, options }) => {
29
31
  sx={{
30
32
  backgroundColor: 'background.paper',
31
33
  height: '100%',
32
- overflow: 'hidden',
33
34
  width: '100%'
34
35
  }}
35
36
  >
@@ -43,10 +44,16 @@ Cypress.Commands.add('mount', ({ Component, options }) => {
43
44
  return mount(wrapped, options);
44
45
  });
45
46
 
47
+ interface Query {
48
+ name: string;
49
+ value: string;
50
+ }
51
+
46
52
  export interface InterceptAPIRequestProps<T> {
47
53
  alias: string;
48
54
  method: Method;
49
55
  path: string;
56
+ query?: Query;
50
57
  response?: T | Array<T>;
51
58
  statusCode?: number;
52
59
  }
@@ -58,13 +65,30 @@ Cypress.Commands.add(
58
65
  path,
59
66
  response,
60
67
  alias,
68
+ query,
61
69
  statusCode = 200
62
70
  }: InterceptAPIRequestProps<T>): void => {
63
71
  cy.interceptRequest(
64
72
  method,
65
73
  path.replace('./', '**'),
66
74
  (req, res, ctx) => {
67
- return res(ctx.delay(500), ctx.json(response), ctx.status(statusCode));
75
+ const getQuery = req?.url?.searchParams?.get(query?.name);
76
+ if (query && equals(query.value, getQuery)) {
77
+ return res(
78
+ ctx.delay(500),
79
+ ctx.json(response),
80
+ ctx.status(statusCode)
81
+ );
82
+ }
83
+ if (!getQuery && isNil(query)) {
84
+ return res(
85
+ ctx.delay(500),
86
+ ctx.json(response),
87
+ ctx.status(statusCode)
88
+ );
89
+ }
90
+
91
+ return null;
68
92
  },
69
93
  alias
70
94
  );
@@ -11,7 +11,7 @@ const enableVisualTesting = (cypressFolder = 'cypress'): void => {
11
11
 
12
12
  addMatchImageSnapshotCommand({
13
13
  capture: 'viewport',
14
- customDiffConfig: { threshold: 0.1 },
14
+ customDiffConfig: { threshold: 0.01 },
15
15
  customSnapshotsDir: `${cypressFolder}/visual-testing-snapshots`,
16
16
  failureThreshold: 0.06,
17
17
  failureThresholdType: 'percent'
@@ -15,7 +15,10 @@ Cypress.Commands.add('getIframeBody', (): Cypress.Chainable => {
15
15
  Cypress.Commands.add(
16
16
  'hoverRootMenuItem',
17
17
  (rootItemNumber: number): Cypress.Chainable => {
18
- return cy.get('li').eq(rootItemNumber).trigger('mouseover');
18
+ return cy
19
+ .get('div[data-testid="sidebar"] li')
20
+ .eq(rootItemNumber)
21
+ .trigger('mouseover');
19
22
  }
20
23
  );
21
24
 
@@ -172,6 +175,36 @@ Cypress.Commands.add(
172
175
  }
173
176
  );
174
177
 
178
+ Cypress.Commands.add('waitForContainerAndSetToken', (): Cypress.Chainable => {
179
+ return cy
180
+ .exec(`npx wait-on ${Cypress.config().baseUrl}`)
181
+ .then(() => cy.setUserTokenApiV1());
182
+ });
183
+
184
+ interface StartContainerProps {
185
+ name: string;
186
+ os: string;
187
+ version: string;
188
+ }
189
+
190
+ Cypress.Commands.add(
191
+ 'startContainer',
192
+ ({ name, os, version }: StartContainerProps): Cypress.Chainable => {
193
+ return cy.exec(
194
+ `docker run -p 4000:80 -d --name ${name} docker.centreon.com/centreon/centreon-web-${os}:${version}`
195
+ );
196
+ }
197
+ );
198
+
199
+ Cypress.Commands.add(
200
+ 'stopContainer',
201
+ (containerName: string): Cypress.Chainable => {
202
+ return cy.exec(
203
+ `docker stop ${containerName} && docker rm ${containerName}`
204
+ );
205
+ }
206
+ );
207
+
175
208
  declare global {
176
209
  namespace Cypress {
177
210
  interface Chainable {
@@ -192,6 +225,9 @@ declare global {
192
225
  rootItemNumber,
193
226
  subMenu
194
227
  }: NavigateToProps) => Cypress.Chainable;
228
+ startContainer: () => Cypress.Chainable;
229
+ stopContainer: (containerName: string) => Cypress.Chainable;
230
+ waitForContainerAndSetToken: () => Cypress.Chainable;
195
231
  }
196
232
  }
197
233
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@centreon/js-config",
3
3
  "description": "Centreon Frontend shared build configuration",
4
- "version": "23.4.21-MON-fix-image-snapshot.4",
4
+ "version": "23.4.22-0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon-frontend.git"