@jahia/cypress 3.3.0 → 3.4.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.
Files changed (50) hide show
  1. package/dist/page-object/baseComponent.js +1 -0
  2. package/dist/page-object/html/iframe.js +1 -0
  3. package/dist/page-object/moonstone/pagination.js +1 -0
  4. package/dist/page-object/utils.d.ts +1 -1
  5. package/dist/page-object/utils.js +4 -3
  6. package/dist/support/apollo/apollo.js +2 -3
  7. package/dist/support/apollo/apolloClient.js +1 -2
  8. package/dist/support/apollo/links.d.ts +1 -1
  9. package/dist/support/apollo/links.js +3 -3
  10. package/dist/support/fixture.d.ts +1 -1
  11. package/dist/support/fixture.js +3 -3
  12. package/dist/support/provisioning/runProvisioningScript.js +3 -0
  13. package/dist/support/repeatUntil.js +1 -2
  14. package/dist/utils/JCRHelper.d.ts +11 -0
  15. package/dist/utils/JCRHelper.js +58 -0
  16. package/dist/utils/PublicationAndWorkflowHelper.d.ts +4 -0
  17. package/dist/utils/PublicationAndWorkflowHelper.js +59 -0
  18. package/dist/utils/SiteHelper.d.ts +7 -0
  19. package/dist/utils/SiteHelper.js +20 -0
  20. package/dist/utils/UsersHelper.d.ts +6 -0
  21. package/dist/utils/UsersHelper.js +34 -0
  22. package/dist/utils/VanityUrlHelper.d.ts +3 -0
  23. package/dist/utils/VanityUrlHelper.js +34 -0
  24. package/dist/utils/index.d.ts +5 -1
  25. package/dist/utils/index.js +5 -1
  26. package/fixtures/graphql/jcr/mutation/setPropertyValues.graphql +9 -0
  27. package/fixtures/graphql/jcr/mutation/startWorkflow.graphql +7 -0
  28. package/fixtures/groovy/admin/completeWorkflows.groovy +16 -0
  29. package/fixtures/groovy/admin/createSite.groovy +2 -1
  30. package/package.json +1 -1
  31. package/src/custom.d.ts +1 -0
  32. package/src/page-object/baseComponent.ts +1 -0
  33. package/src/page-object/html/iframe.ts +1 -0
  34. package/src/page-object/moonstone/pagination.ts +1 -0
  35. package/src/page-object/utils.ts +4 -3
  36. package/src/support/apollo/apollo.ts +2 -5
  37. package/src/support/apollo/apolloClient.ts +4 -5
  38. package/src/support/apollo/links.ts +1 -1
  39. package/src/support/fixture.ts +3 -3
  40. package/src/support/provisioning/runProvisioningScript.ts +5 -1
  41. package/src/support/repeatUntil.ts +2 -5
  42. package/src/utils/JCRHelper.ts +55 -0
  43. package/src/utils/PublicationAndWorkflowHelper.ts +55 -0
  44. package/src/utils/SiteHelper.ts +16 -0
  45. package/src/utils/UsersHelper.ts +30 -0
  46. package/src/utils/VanityUrlHelper.ts +30 -0
  47. package/src/utils/index.ts +5 -1
  48. package/dist/utils/Utils.d.ts +0 -24
  49. package/dist/utils/Utils.js +0 -172
  50. package/src/utils/Utils.ts +0 -166
@@ -1,9 +1,9 @@
1
1
  import Chainable = Cypress.Chainable;
2
2
 
3
3
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- export const fixture = function (originalCommand: ((...args: any[]) => any), fixture: string, ...args: any[]): Chainable<any> {
4
+ export const fixture = function (originalCommand: ((...args: any[]) => any), fixtureParam: string, ...args: any[]): Chainable<any> {
5
5
  return cy.wrap({}, {log: false}).then(() => {
6
- return originalCommand(fixture, ...args).then(f => {
6
+ return originalCommand(fixtureParam, ...args).then(f => {
7
7
  return f;
8
8
  }).catch(() => {
9
9
  return null;
@@ -16,7 +16,7 @@ export const fixture = function (originalCommand: ((...args: any[]) => any), fix
16
16
  }
17
17
 
18
18
  try {
19
- cy.readFile('./node_modules/@jahia/cypress/fixtures/' + fixture, encoding, {log: false, timeout: 200});
19
+ cy.readFile('./node_modules/@jahia/cypress/fixtures/' + fixtureParam, encoding, {log: false, timeout: 200});
20
20
  } catch (e) {
21
21
  console.log(e);
22
22
  }
@@ -1,13 +1,14 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
2
1
  import RequestOptions = Cypress.RequestOptions;
3
2
 
4
3
  // Load type definitions that come with Cypress module
5
4
  /// <reference types="cypress" />
6
5
 
7
6
  declare global {
7
+ // eslint-disable-next-line @typescript-eslint/no-namespace
8
8
  namespace Cypress {
9
9
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
10
  interface Chainable<Subject> {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
12
  runProvisioningScript(script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer): Chainable<any>
12
13
  }
13
14
  }
@@ -67,6 +68,7 @@ function isFormFile(script: FormFile | StringDictionary[]): script is FormFile {
67
68
  return Boolean((script as FormFile).fileContent || (script as FormFile).fileName);
68
69
  }
69
70
 
71
+ // eslint-disable-next-line default-param-last, max-params
70
72
  export const runProvisioningScript = (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer: JahiaServer = serverDefaults, options: Cypress.Loggable = {log: true}, timeout?: number): void => {
71
73
  const formData = new FormData();
72
74
 
@@ -85,7 +87,9 @@ export const runProvisioningScript = (script: FormFile | StringDictionary[], fil
85
87
  });
86
88
  }
87
89
 
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
91
  let response: Cypress.Response<any>;
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
93
  let result: any;
90
94
  let logger: Cypress.Log;
91
95
 
@@ -1,7 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
2
-
3
- // Load type definitions that come with Cypress module
4
- /// <reference types="cypress" />
1
+ // Load type definitions that come with Cypress module <reference types="cypress" />
5
2
 
6
3
  export type RepeatUntilOptions = {
7
4
  attempts: number,
@@ -16,6 +13,7 @@ const defaultOptions: RepeatUntilOptions = {
16
13
  };
17
14
 
18
15
  declare global {
16
+ // eslint-disable-next-line @typescript-eslint/no-namespace
19
17
  namespace Cypress {
20
18
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
21
19
  interface Chainable<Subject> {
@@ -48,7 +46,6 @@ export const repeatUntil = (selector: string, options: Partial<RepeatUntilOption
48
46
  log.end();
49
47
  options.callback();
50
48
 
51
- // eslint-disable-next-line cypress/no-unnecessary-waiting
52
49
  cy.wait(options.delay);
53
50
  cy.repeatUntil(selector, {...options, attempts: options.attempts - 1});
54
51
  } else {
@@ -0,0 +1,55 @@
1
+ export const setNodeProperty = (pathOrId: string, property: string, value: string | Array<string>, language: string): Cypress.Chainable => {
2
+ let mutationFile = 'graphql/jcr/mutation/setProperty.graphql';
3
+ if (value instanceof Array) {
4
+ mutationFile = 'graphql/jcr/mutation/setPropertyValues.graphql';
5
+ }
6
+
7
+ return cy.apollo({
8
+ variables: {
9
+ pathOrId: pathOrId,
10
+ property: property,
11
+ language: language,
12
+ value: value
13
+ },
14
+ mutationFile
15
+ });
16
+ };
17
+
18
+ export const deleteNode = (pathOrId: string): Cypress.Chainable => {
19
+ return cy.apollo({
20
+ variables: {
21
+ pathOrId: pathOrId
22
+ },
23
+ mutationFile: 'graphql/jcr/mutation/deleteNode.graphql'
24
+ });
25
+ };
26
+
27
+ export const deleteNodeProperty = (pathOrId: string, property: string, language: string): Cypress.Chainable => {
28
+ return cy.apollo({
29
+ variables: {
30
+ pathOrId: pathOrId,
31
+ property: property,
32
+ language: language
33
+ },
34
+ mutationFile: 'graphql/jcr/mutation/deleteNodeProperty.graphql'
35
+ });
36
+ };
37
+
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ export const addNode = (variables: { parentPathOrId: string, primaryNodeType: string, name: string, properties?: any[], children?: any[] }): Cypress.Chainable => {
40
+ return cy.apollo({
41
+ variables: variables,
42
+ mutationFile: 'graphql/jcr/mutation/addNode.graphql'
43
+ });
44
+ };
45
+
46
+ export const getNodeByPath = (path: string, properties?: string[], language?:string): Cypress.Chainable => {
47
+ return cy.apollo({
48
+ variables: {
49
+ path: path,
50
+ properties: properties,
51
+ language: language
52
+ },
53
+ queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
54
+ });
55
+ };
@@ -0,0 +1,55 @@
1
+
2
+ export const publishAndWaitJobEnding = (path: string, languages: string[] = ['en']): void => {
3
+ cy.apollo({
4
+ variables: {
5
+ pathOrId: path,
6
+ languages: languages,
7
+ publishSubNodes: true,
8
+ includeSubTree: true
9
+ },
10
+ mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
11
+ });
12
+ waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
13
+ };
14
+
15
+ export const startWorkflow = (pathOrId: string, definition: string, language: string): Cypress.Chainable => {
16
+ return cy.apollo({
17
+ variables: {
18
+ pathOrId,
19
+ definition,
20
+ language
21
+ },
22
+ mutationFile: 'graphql/jcr/mutation/startWorkflow.graphql'
23
+ });
24
+ };
25
+
26
+ export const validateAllWorkflows = (): void => {
27
+ cy.executeGroovy('groovy/admin/completeWorkflows.groovy');
28
+ waitAllJobsFinished('All workflows validated but some jobs are still running after a minute', 60000);
29
+ };
30
+
31
+ export const waitAllJobsFinished = (errorMessage?: string, timeout = 60000): void => {
32
+ cy.waitUntil(
33
+ () =>
34
+ cy
35
+ .apollo({
36
+ fetchPolicy: 'no-cache',
37
+ queryFile: 'graphql/jcr/query/getJobsWithStatus.graphql'
38
+ })
39
+ .then(response => {
40
+ const jobs = response?.data?.admin?.jahia?.scheduler?.jobs;
41
+ const publicationJobs = jobs.filter(job => job.group === 'PublicationJob');
42
+ const hasActivePublicationJobs = publicationJobs.some(job => job.jobStatus === 'EXECUTING');
43
+ return !hasActivePublicationJobs;
44
+ }),
45
+ {
46
+ errorMsg: errorMessage ? errorMessage : 'Jobs are still running before the end of timeout',
47
+ timeout: timeout,
48
+ verbose: true,
49
+ interval: 500
50
+ }
51
+ );
52
+ // Wait 0.5 seconds for server sync after publication
53
+ // eslint-disable-next-line cypress/no-unnecessary-waiting
54
+ cy.wait(500);
55
+ };
@@ -0,0 +1,16 @@
1
+
2
+ export const createSite = (siteKey: string, config: {languages?: string, templateSet: string, serverName: string, locale: string} = {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en'}): void => {
3
+ cy.executeGroovy('groovy/admin/createSite.groovy', {
4
+ SITEKEY: siteKey,
5
+ TEMPLATES_SET: config.templateSet,
6
+ SERVERNAME: config.serverName,
7
+ LOCALE: config.locale,
8
+ LANGUAGES: config.languages || config.locale
9
+ });
10
+ };
11
+
12
+ export const deleteSite = (siteKey: string): void => {
13
+ cy.executeGroovy('groovy/admin/deleteSite.groovy', {
14
+ SITEKEY: siteKey
15
+ });
16
+ };
@@ -0,0 +1,30 @@
1
+
2
+ export const grantRoles = (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string): Cypress.Chainable => {
3
+ cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
4
+ return cy.apollo({
5
+ variables: {
6
+ pathOrId: pathOrId,
7
+ roleNames: roleNames,
8
+ principalName: principalName,
9
+ principalType: principalType
10
+ },
11
+ mutationFile: 'graphql/jcr/mutation/grantRoles.graphql'
12
+ });
13
+ };
14
+
15
+ export const createUser = (userName: string, password: string, properties: { name: string, value: string }[] = []): void => {
16
+ const userProperties = properties.map(property => {
17
+ return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
18
+ });
19
+ cy.executeGroovy('groovy/admin/createUser.groovy', {
20
+ USER_NAME: userName,
21
+ PASSWORD: password ? password : 'password',
22
+ USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
23
+ });
24
+ };
25
+
26
+ export const deleteUser = (userName: string): void => {
27
+ cy.executeGroovy('groovy/admin/deleteUser.groovy', {
28
+ USER_NAME: userName
29
+ });
30
+ };
@@ -0,0 +1,30 @@
1
+ export const addVanityUrl = (pathOrId: string, language: string, url: string): Cypress.Chainable => {
2
+ return cy.apollo({
3
+ variables: {
4
+ pathOrId: pathOrId,
5
+ language: language,
6
+ url: url
7
+ },
8
+ mutationFile: 'graphql/jcr/mutation/addVanityUrl.graphql'
9
+ });
10
+ };
11
+
12
+ export const getVanityUrl = (path: string, languages: Array<string>): Cypress.Chainable => {
13
+ return cy.apollo({
14
+ variables: {
15
+ path: path,
16
+ languages: languages
17
+ },
18
+ queryFile: 'graphql/jcr/query/getVanityUrls.graphql'
19
+ });
20
+ };
21
+
22
+ export const removeVanityUrl = (pathOrId: string, url: string): Cypress.Chainable => {
23
+ return cy.apollo({
24
+ variables: {
25
+ pathOrId: pathOrId,
26
+ url: url
27
+ },
28
+ mutationFile: 'graphql/jcr/mutation/removeVanityUrl.graphql'
29
+ });
30
+ };
@@ -1 +1,5 @@
1
- export * from './Utils';
1
+ export * from './JCRHelper';
2
+ export * from './PublicationAndWorkflowHelper';
3
+ export * from './SiteHelper';
4
+ export * from './UsersHelper';
5
+ export * from './VanityUrlHelper';
@@ -1,24 +0,0 @@
1
- export declare const setNodeProperty: (pathOrId: string, property: string, value: string, language: string) => Cypress.Chainable;
2
- export declare const deleteNodeProperty: (pathOrId: string, property: string, language: string) => Cypress.Chainable;
3
- export declare const deleteNode: (pathOrId: string) => Cypress.Chainable;
4
- export declare const grantRoles: (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string) => Cypress.Chainable;
5
- export declare const publishAndWaitJobEnding: (path: string, languages?: string[]) => void;
6
- export declare const waitAllJobsFinished: (errorMessage?: string, timeout?: number) => void;
7
- export declare const addNode: (variables: {
8
- parentPathOrId: string;
9
- primaryNodeType: string;
10
- name: string;
11
- properties?: any[];
12
- children?: any[];
13
- }) => Cypress.Chainable;
14
- export declare const getNodeByPath: (path: string, properties?: string[], language?: string) => Cypress.Chainable;
15
- export declare const createSite: (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string) => void;
16
- export declare const deleteSite: (siteKey: string) => void;
17
- export declare const createUser: (userName: string, password: string, properties?: {
18
- name: string;
19
- value: string;
20
- }[]) => void;
21
- export declare const deleteUser: (userName: string) => void;
22
- export declare const addVanityUrl: (pathOrId: string, language: string, url: string) => Cypress.Chainable;
23
- export declare const getVanityUrl: (path: string, languages: Array<string>) => Cypress.Chainable;
24
- export declare const removeVanityUrl: (pathOrId: string, url: string) => Cypress.Chainable;
@@ -1,172 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.removeVanityUrl = exports.getVanityUrl = exports.addVanityUrl = exports.deleteUser = exports.createUser = exports.deleteSite = exports.createSite = exports.getNodeByPath = exports.addNode = exports.waitAllJobsFinished = exports.publishAndWaitJobEnding = exports.grantRoles = exports.deleteNode = exports.deleteNodeProperty = exports.setNodeProperty = void 0;
4
- var setNodeProperty = function (pathOrId, property, value, language) {
5
- return cy.apollo({
6
- variables: {
7
- pathOrId: pathOrId,
8
- property: property,
9
- value: value,
10
- language: language
11
- },
12
- mutationFile: 'graphql/jcr/mutation/setProperty.graphql'
13
- });
14
- };
15
- exports.setNodeProperty = setNodeProperty;
16
- var deleteNodeProperty = function (pathOrId, property, language) {
17
- return cy.apollo({
18
- variables: {
19
- pathOrId: pathOrId,
20
- property: property,
21
- language: language
22
- },
23
- mutationFile: 'graphql/jcr/mutation/deleteNodeProperty.graphql'
24
- });
25
- };
26
- exports.deleteNodeProperty = deleteNodeProperty;
27
- var deleteNode = function (pathOrId) {
28
- return cy.apollo({
29
- variables: {
30
- pathOrId: pathOrId
31
- },
32
- mutationFile: 'graphql/jcr/mutation/deleteNode.graphql'
33
- });
34
- };
35
- exports.deleteNode = deleteNode;
36
- var grantRoles = function (pathOrId, roleNames, principalName, principalType) {
37
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
38
- return cy.apollo({
39
- variables: {
40
- pathOrId: pathOrId,
41
- roleNames: roleNames,
42
- principalName: principalName,
43
- principalType: principalType
44
- },
45
- mutationFile: 'graphql/jcr/mutation/grantRoles.graphql'
46
- });
47
- };
48
- exports.grantRoles = grantRoles;
49
- var publishAndWaitJobEnding = function (path, languages) {
50
- if (languages === void 0) { languages = ['en']; }
51
- cy.apollo({
52
- variables: {
53
- pathOrId: path,
54
- languages: languages,
55
- publishSubNodes: true,
56
- includeSubTree: true
57
- },
58
- mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
59
- });
60
- exports.waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
61
- };
62
- exports.publishAndWaitJobEnding = publishAndWaitJobEnding;
63
- var waitAllJobsFinished = function (errorMessage, timeout) {
64
- if (timeout === void 0) { timeout = 60000; }
65
- cy.waitUntil(function () {
66
- return cy
67
- .apollo({
68
- fetchPolicy: 'no-cache',
69
- queryFile: 'graphql/jcr/query/getJobsWithStatus.graphql'
70
- })
71
- .then(function (response) {
72
- var _a, _b, _c, _d;
73
- var jobs = (_d = (_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.admin) === null || _b === void 0 ? void 0 : _b.jahia) === null || _c === void 0 ? void 0 : _c.scheduler) === null || _d === void 0 ? void 0 : _d.jobs;
74
- var publicationJobs = jobs.filter(function (job) { return job.group === 'PublicationJob'; });
75
- var hasActivePublicationJobs = publicationJobs.some(function (job) { return job.jobStatus === 'EXECUTING'; });
76
- return !hasActivePublicationJobs;
77
- });
78
- }, {
79
- errorMsg: errorMessage ? errorMessage : 'Jobs are still running before the end of timeout',
80
- timeout: timeout,
81
- verbose: true,
82
- interval: 1000
83
- });
84
- // Wait 2 seconds for server sync after publication
85
- // eslint-disable-next-line cypress/no-unnecessary-waiting
86
- cy.wait(2000);
87
- };
88
- exports.waitAllJobsFinished = waitAllJobsFinished;
89
- var addNode = function (variables) {
90
- return cy.apollo({
91
- variables: variables,
92
- mutationFile: 'graphql/jcr/mutation/addNode.graphql'
93
- });
94
- };
95
- exports.addNode = addNode;
96
- var getNodeByPath = function (path, properties, language) {
97
- return cy.apollo({
98
- variables: {
99
- path: path,
100
- properties: properties,
101
- language: language
102
- },
103
- queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
104
- });
105
- };
106
- exports.getNodeByPath = getNodeByPath;
107
- var createSite = function (siteKey, templateSet, serverName, locale, languages) {
108
- var definedLocale = locale ? locale : 'en';
109
- cy.executeGroovy('groovy/admin/createSite.groovy', {
110
- SITEKEY: siteKey,
111
- TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
112
- SERVERNAME: serverName ? serverName : 'localhost',
113
- LOCALE: definedLocale,
114
- LANGUAGES: languages ? "Arrays.asList(" + languages + ")" : "Arrays.asList(\"" + definedLocale + "\")"
115
- });
116
- };
117
- exports.createSite = createSite;
118
- var deleteSite = function (siteKey) {
119
- cy.executeGroovy('groovy/admin/deleteSite.groovy', {
120
- SITEKEY: siteKey
121
- });
122
- };
123
- exports.deleteSite = deleteSite;
124
- var createUser = function (userName, password, properties) {
125
- if (properties === void 0) { properties = []; }
126
- var userProperties = properties.map(function (property) {
127
- return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
128
- });
129
- cy.executeGroovy('groovy/admin/createUser.groovy', {
130
- USER_NAME: userName,
131
- PASSWORD: password ? password : 'password',
132
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
133
- });
134
- };
135
- exports.createUser = createUser;
136
- var deleteUser = function (userName) {
137
- cy.executeGroovy('groovy/admin/deleteUser.groovy', {
138
- USER_NAME: userName
139
- });
140
- };
141
- exports.deleteUser = deleteUser;
142
- var addVanityUrl = function (pathOrId, language, url) {
143
- return cy.apollo({
144
- variables: {
145
- pathOrId: pathOrId,
146
- language: language,
147
- url: url
148
- },
149
- mutationFile: 'graphql/jcr/mutation/addVanityUrl.graphql'
150
- });
151
- };
152
- exports.addVanityUrl = addVanityUrl;
153
- var getVanityUrl = function (path, languages) {
154
- return cy.apollo({
155
- variables: {
156
- path: path,
157
- languages: languages
158
- },
159
- queryFile: 'graphql/jcr/query/getVanityUrls.graphql'
160
- });
161
- };
162
- exports.getVanityUrl = getVanityUrl;
163
- var removeVanityUrl = function (pathOrId, url) {
164
- return cy.apollo({
165
- variables: {
166
- pathOrId: pathOrId,
167
- url: url
168
- },
169
- mutationFile: 'graphql/jcr/mutation/removeVanityUrl.graphql'
170
- });
171
- };
172
- exports.removeVanityUrl = removeVanityUrl;
@@ -1,166 +0,0 @@
1
- export const setNodeProperty = (pathOrId: string, property: string, value: string, language: string): Cypress.Chainable => {
2
- return cy.apollo({
3
- variables: {
4
- pathOrId: pathOrId,
5
- property: property,
6
- value: value,
7
- language: language
8
- },
9
- mutationFile: 'graphql/jcr/mutation/setProperty.graphql'
10
- });
11
- };
12
-
13
- export const deleteNodeProperty = (pathOrId: string, property: string, language: string): Cypress.Chainable => {
14
- return cy.apollo({
15
- variables: {
16
- pathOrId: pathOrId,
17
- property: property,
18
- language: language
19
- },
20
- mutationFile: 'graphql/jcr/mutation/deleteNodeProperty.graphql'
21
- });
22
- };
23
-
24
- export const deleteNode = (pathOrId: string): Cypress.Chainable => {
25
- return cy.apollo({
26
- variables: {
27
- pathOrId: pathOrId
28
- },
29
- mutationFile: 'graphql/jcr/mutation/deleteNode.graphql'
30
- });
31
- };
32
-
33
- export const grantRoles = (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string): Cypress.Chainable => {
34
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
35
- return cy.apollo({
36
- variables: {
37
- pathOrId: pathOrId,
38
- roleNames: roleNames,
39
- principalName: principalName,
40
- principalType: principalType
41
- },
42
- mutationFile: 'graphql/jcr/mutation/grantRoles.graphql'
43
- });
44
- };
45
-
46
- export const publishAndWaitJobEnding = (path: string, languages: string[] = ['en']): void => {
47
- cy.apollo({
48
- variables: {
49
- pathOrId: path,
50
- languages: languages,
51
- publishSubNodes: true,
52
- includeSubTree: true
53
- },
54
- mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
55
- });
56
- waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
57
- };
58
-
59
- export const waitAllJobsFinished = (errorMessage?: string, timeout = 60000): void => {
60
- cy.waitUntil(
61
- () =>
62
- cy
63
- .apollo({
64
- fetchPolicy: 'no-cache',
65
- queryFile: 'graphql/jcr/query/getJobsWithStatus.graphql'
66
- })
67
- .then(response => {
68
- const jobs = response?.data?.admin?.jahia?.scheduler?.jobs;
69
- const publicationJobs = jobs.filter(job => job.group === 'PublicationJob');
70
- const hasActivePublicationJobs = publicationJobs.some(job => job.jobStatus === 'EXECUTING');
71
- return !hasActivePublicationJobs;
72
- }),
73
- {
74
- errorMsg: errorMessage ? errorMessage : 'Jobs are still running before the end of timeout',
75
- timeout: timeout,
76
- verbose: true,
77
- interval: 1000
78
- }
79
- );
80
- // Wait 2 seconds for server sync after publication
81
- // eslint-disable-next-line cypress/no-unnecessary-waiting
82
- cy.wait(2000);
83
- };
84
-
85
- export const addNode = (variables: { parentPathOrId: string, primaryNodeType: string, name: string, properties?: any[], children?: any[] }): Cypress.Chainable => {
86
- return cy.apollo({
87
- variables: variables,
88
- mutationFile: 'graphql/jcr/mutation/addNode.graphql'
89
- });
90
- };
91
-
92
- export const getNodeByPath = (path: string, properties?: string[], language?:string): Cypress.Chainable => {
93
- return cy.apollo({
94
- variables: {
95
- path: path,
96
- properties: properties,
97
- language: language
98
- },
99
- queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
100
- });
101
- };
102
-
103
- export const createSite = (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string): void => {
104
- const definedLocale = locale ? locale : 'en';
105
- cy.executeGroovy('groovy/admin/createSite.groovy', {
106
- SITEKEY: siteKey,
107
- TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
108
- SERVERNAME: serverName ? serverName : 'localhost',
109
- LOCALE: definedLocale,
110
- LANGUAGES: languages ? `Arrays.asList(${languages})` : `Arrays.asList("${definedLocale}")`
111
- });
112
- };
113
-
114
- export const deleteSite = (siteKey: string): void => {
115
- cy.executeGroovy('groovy/admin/deleteSite.groovy', {
116
- SITEKEY: siteKey
117
- });
118
- };
119
-
120
- export const createUser = (userName: string, password: string, properties: { name: string, value: string }[] = []): void => {
121
- const userProperties = properties.map(property => {
122
- return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
123
- });
124
- cy.executeGroovy('groovy/admin/createUser.groovy', {
125
- USER_NAME: userName,
126
- PASSWORD: password ? password : 'password',
127
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
128
- });
129
- };
130
-
131
- export const deleteUser = (userName: string): void => {
132
- cy.executeGroovy('groovy/admin/deleteUser.groovy', {
133
- USER_NAME: userName
134
- });
135
- };
136
-
137
- export const addVanityUrl = (pathOrId: string, language: string, url: string): Cypress.Chainable => {
138
- return cy.apollo({
139
- variables: {
140
- pathOrId: pathOrId,
141
- language: language,
142
- url: url
143
- },
144
- mutationFile: 'graphql/jcr/mutation/addVanityUrl.graphql'
145
- });
146
- };
147
-
148
- export const getVanityUrl = (path: string, languages: Array<string>): Cypress.Chainable => {
149
- return cy.apollo({
150
- variables: {
151
- path: path,
152
- languages: languages
153
- },
154
- queryFile: 'graphql/jcr/query/getVanityUrls.graphql'
155
- });
156
- };
157
-
158
- export const removeVanityUrl = (pathOrId: string, url: string): Cypress.Chainable => {
159
- return cy.apollo({
160
- variables: {
161
- pathOrId: pathOrId,
162
- url: url
163
- },
164
- mutationFile: 'graphql/jcr/mutation/removeVanityUrl.graphql'
165
- });
166
- };