@jahia/cypress 3.25.0 → 3.27.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.
@@ -1,8 +1,10 @@
1
1
  import {BaseComponent} from '../baseComponent';
2
2
  import {getComponentByRole} from '../utils';
3
+ import Chainable = Cypress.Chainable;
3
4
 
4
5
  export class Menu extends BaseComponent {
5
6
  static defaultSelector = '.moonstone-menu:not(.moonstone-hidden)'
7
+ static overlaySelector = '.moonstone-menu_overlay';
6
8
 
7
9
  submenu(item: string, menu: string): Menu {
8
10
  this.get().find('.moonstone-menuItem').contains(item).scrollIntoView().should('be.visible');
@@ -29,4 +31,8 @@ export class Menu extends BaseComponent {
29
31
  this.get().find(`.moonstone-menuItem[data-sel-role="${item}"]`).trigger('click');
30
32
  return this;
31
33
  }
34
+
35
+ close(): Chainable<unknown> {
36
+ return cy.get(Menu.overlaySelector).click('topRight');
37
+ }
32
38
  }
@@ -87,3 +87,20 @@ export const getNodeTypes = (filter = {}): Cypress.Chainable => {
87
87
  queryFile: 'graphql/jcr/query/getNodeTypes.graphql'
88
88
  });
89
89
  };
90
+
91
+ export const uploadFile = (fixturePath: string, parentPathOrId: string, name: string, mimeType: string): Cypress.Chainable => {
92
+ return cy.fixture(fixturePath, 'binary')
93
+ .then(image => {
94
+ const blob = Cypress.Blob.binaryStringToBlob(image, mimeType);
95
+ const file = new File([blob], name, {type: blob.type});
96
+ return cy.apollo({
97
+ mutationFile: 'graphql/jcr/mutation/uploadFile.graphql',
98
+ variables: {
99
+ parentPathOrId,
100
+ name,
101
+ mimeType,
102
+ file
103
+ }
104
+ });
105
+ });
106
+ };
@@ -1,36 +1,67 @@
1
- /*
2
- When Jahia is starting or performing provisioning operations
3
- it is expected for the SAM probe to alternate beween GREEN, YELLOW and RED statuses.
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import Chainable = Cypress.Chainable
4
3
 
5
- The primary use of this method is to wait until a Jahia platform stabilizes after a startup or
6
- provisioning operation.
7
-
8
- Instead of waiting only for one occurence of a GREEN status, this function will wait until the a
9
- GREEN status was returned a number of consecutive times (greenMatchCount).
10
- */
11
- export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, interval = 500, greenMatchCount = 10) : void => {
12
- let greenCount = 0;
13
- let lastGraphqlResponse = {};
14
- cy.waitUntil(() =>
15
- cy.apollo({
4
+ /**
5
+ * Simple health check query
6
+ * @param severity the severity of the health check, default is MEDIUM
7
+ * @param probeHealthFilter the filter for the health check probes, default is GREEN
8
+ */
9
+ export const healthCheck = (severity = 'MEDIUM', probeHealthFilter = 'GREEN'): Chainable<any> => {
10
+ return cy
11
+ .apollo({
16
12
  fetchPolicy: 'no-cache',
17
13
  queryFile: 'graphql/sam/healthStatus.graphql',
18
14
  variables: {
19
- severity: severity
15
+ severity,
16
+ probeHealthFilter
20
17
  }
21
- }).then(result => {
22
- const healthStatus = result?.data?.admin?.jahia?.healthCheck?.status;
23
- lastGraphqlResponse = result?.data?.admin?.jahia?.healthCheck;
18
+ })
19
+ .then((response: any) => {
20
+ return response?.data?.admin?.jahia?.healthCheck;
21
+ });
22
+ };
23
+
24
+ /**
25
+ * Wait until the health check returns the expected health
26
+ * @param expectedHealth the expected health status
27
+ * @param severity the severity of the health check, default is MEDIUM
28
+ * @param probeHealthFilter the filter for the health check probes, default is GREEN
29
+ * @param timeout the timeout in milliseconds, default is 60000
30
+ * @param interval the interval in milliseconds, default is 500
31
+ * @param statusMatchCount the number of consecutive status matches before the waitUntil resolves, default is 1
32
+ */
33
+ export const waitUntilSAMStatus = ({expectedHealth, severity = 'MEDIUM', probeHealthFilter = 'GREEN', timeout = 60000, interval = 500, statusMatchCount = 1}) : void => {
34
+ let statusCount = 0;
35
+ let lastGraphqlResponse = {};
36
+ cy.waitUntil(() =>
37
+ healthCheck(severity, probeHealthFilter).then(result => {
38
+ lastGraphqlResponse = result;
39
+ const healthStatus = result?.status;
24
40
  if (healthStatus) {
25
- greenCount = healthStatus.health === 'GREEN' ? greenCount + 1 : 0;
26
- return greenCount >= greenMatchCount;
41
+ statusCount = healthStatus.health === expectedHealth ? statusCount + 1 : 0;
42
+ return statusCount >= statusMatchCount;
27
43
  }
28
44
  }),
29
45
  {
30
- errorMsg: `Timeout waiting for SAM to be green for severity: ${severity}. Last GraphQL response: ${JSON.stringify(lastGraphqlResponse)}`,
46
+ errorMsg: `Timeout waiting for SAM to be ${expectedHealth} for severity: ${severity} and probeHealthFilter: ${probeHealthFilter}. Last GraphQL response: ${JSON.stringify(lastGraphqlResponse)}`,
31
47
  timeout: timeout,
32
48
  verbose: true,
33
49
  interval: interval
34
50
  });
35
51
  };
36
52
 
53
+ /**
54
+ When Jahia is starting or performing provisioning operations
55
+ it is expected for the SAM probe to alternate beween GREEN, YELLOW and RED statuses.
56
+
57
+ The primary use of this method is to wait until a Jahia platform stabilizes after a startup or
58
+ provisioning operation.
59
+
60
+ Instead of waiting only for one occurence of a GREEN status, this function will wait until the a
61
+ GREEN status was returned a number of consecutive times (greenMatchCount).
62
+ */
63
+ export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, interval = 500, greenMatchCount = 10) : void => {
64
+ // We use YELLOW as the probeHealthFilter because we are not interested in potential GREEN probes in the response
65
+ waitUntilSAMStatus({expectedHealth: 'GREEN', severity, probeHealthFilter: 'YELLOW', timeout, interval, statusMatchCount: greenMatchCount});
66
+ };
67
+
@@ -0,0 +1,49 @@
1
+ import {NodeSSH, SSHExecCommandResponse} from 'node-ssh';
2
+
3
+ interface connection {
4
+ hostname: string
5
+ port: string
6
+ username: string
7
+ password: string
8
+ }
9
+
10
+ /**
11
+ * Execute SSH commands on a specific host. Returns a promise that resolves to the command result.
12
+ * Rejects if the commands fail (exit code is not 0).
13
+ * @param commands Array of SSH commands to execute
14
+ * @param connection Connection details
15
+ */
16
+ export const sshCommands = (commands: Array<string>, connection: connection): Promise<SSHExecCommandResponse> => {
17
+ return new Promise((resolve, reject) => {
18
+ const ssh = new NodeSSH();
19
+ console.info('[SSH] connection to:', connection.hostname, ' (port: ', connection.port, ')');
20
+ console.info('[SSH] commands:', commands);
21
+ console.info('[SSH] ', connection);
22
+ ssh.connect({
23
+ host: connection.hostname,
24
+ port: parseInt(connection.port, 10),
25
+ username: connection.username,
26
+ password: connection.password
27
+ })
28
+ .then(() => {
29
+ ssh.exec(commands.join(';'), [], {stream: 'both'})
30
+ .then(function (result) {
31
+ console.info('[SSH] Successfully executed commands: ', commands);
32
+ console.info('[SSH] Result: ', result);
33
+ if (result.code === 0) {
34
+ resolve(result); // Resolve to command result
35
+ } else {
36
+ reject(new Error(`Commands "${commands}" failed with exit code ${result.code} on host ${connection.hostname}. Stdout:${result.stdout}, Stderr: ${result.stderr}`));
37
+ }
38
+ })
39
+ .catch(reason => {
40
+ console.error('[SSH] Failed to execute commands: ', commands);
41
+ reject(reason);
42
+ });
43
+ })
44
+ .catch(reason => {
45
+ console.error('[SSH] Failed to connect to: ', connection.hostname);
46
+ reject(reason);
47
+ });
48
+ });
49
+ };
@@ -1,9 +1,10 @@
1
+ export * from './ClusterHelper';
2
+ export * from './GraphQLHelper';
3
+ export * from './JahiaPlatformHelper';
1
4
  export * from './JCRHelper';
2
5
  export * from './PublicationAndWorkflowHelper';
6
+ export * from './SAMHelper';
3
7
  export * from './SiteHelper';
8
+ export * from './SSHHelper';
4
9
  export * from './UsersHelper';
5
10
  export * from './VanityUrlHelper';
6
- export * from './ClusterHelper';
7
- export * from './JahiaPlatformHelper';
8
- export * from './GraphQLHelper';
9
- export * from './SAMHelper';