@jahia/cypress 3.2.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 (55) 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/addVanityUrl.graphql +14 -0
  27. package/fixtures/graphql/jcr/mutation/deleteNodeProperty.graphql +9 -0
  28. package/fixtures/graphql/jcr/mutation/removeVanityUrl.graphql +9 -0
  29. package/fixtures/graphql/jcr/mutation/setPropertyValues.graphql +9 -0
  30. package/fixtures/graphql/jcr/mutation/startWorkflow.graphql +7 -0
  31. package/fixtures/graphql/jcr/query/getNodeByPath.graphql +2 -2
  32. package/fixtures/graphql/jcr/query/getVanityUrls.graphql +9 -0
  33. package/fixtures/groovy/admin/completeWorkflows.groovy +16 -0
  34. package/fixtures/groovy/admin/createSite.groovy +2 -1
  35. package/package.json +1 -1
  36. package/src/custom.d.ts +1 -0
  37. package/src/page-object/baseComponent.ts +1 -0
  38. package/src/page-object/html/iframe.ts +1 -0
  39. package/src/page-object/moonstone/pagination.ts +1 -0
  40. package/src/page-object/utils.ts +4 -3
  41. package/src/support/apollo/apollo.ts +2 -5
  42. package/src/support/apollo/apolloClient.ts +4 -5
  43. package/src/support/apollo/links.ts +1 -1
  44. package/src/support/fixture.ts +3 -3
  45. package/src/support/provisioning/runProvisioningScript.ts +5 -1
  46. package/src/support/repeatUntil.ts +2 -5
  47. package/src/utils/JCRHelper.ts +55 -0
  48. package/src/utils/PublicationAndWorkflowHelper.ts +55 -0
  49. package/src/utils/SiteHelper.ts +16 -0
  50. package/src/utils/UsersHelper.ts +30 -0
  51. package/src/utils/VanityUrlHelper.ts +30 -0
  52. package/src/utils/index.ts +5 -1
  53. package/dist/utils/Utils.d.ts +0 -20
  54. package/dist/utils/Utils.js +0 -128
  55. package/src/utils/Utils.ts +0 -122
@@ -31,11 +31,8 @@ function isMutationFile(options: ApolloOptions): options is FileMutationOptions
31
31
  return (<FileMutationOptions>options).mutationFile !== undefined;
32
32
  }
33
33
 
34
- export const apollo = function (apollo: ApolloClient<any>, options: ApolloOptions): void {
35
- if (!apollo) {
36
- apollo = this.currentApolloClient;
37
- }
38
-
34
+ // eslint-disable-next-line default-param-last, @typescript-eslint/no-shadow
35
+ export const apollo = function (apollo: ApolloClient<any> = this.currentApolloClient, options: ApolloOptions): void {
39
36
  let result : ApolloQueryResult<any> | FetchResult;
40
37
  let logger : Cypress.Log;
41
38
  const optionsWithDefaultCache: ApolloOptions = {fetchPolicy: 'no-cache', ...options};
@@ -1,7 +1,5 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
2
-
3
- import {ApolloClient, from, HttpLink, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core';
4
- import {FormDataHttpLink, uploadLink} from './links';
1
+ import {ApolloClient, from, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core';
2
+ import {formDataHttpLink, uploadLink} from './links';
5
3
 
6
4
  interface AuthMethod {
7
5
  token?: string
@@ -10,6 +8,7 @@ interface AuthMethod {
10
8
  }
11
9
 
12
10
  declare global {
11
+ // eslint-disable-next-line @typescript-eslint/no-namespace
13
12
  namespace Cypress {
14
13
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
14
  interface Chainable<Subject> {
@@ -35,7 +34,7 @@ export const apolloClient = function (authMethod?: AuthMethod, options: ApolloCl
35
34
  headers.authorization = `Basic ${btoa(authMethod.username + ':' + authMethod.password)}`;
36
35
  }
37
36
 
38
- const links = [uploadLink, FormDataHttpLink(Cypress.config().baseUrl, headers)];
37
+ const links = [uploadLink, formDataHttpLink(Cypress.config().baseUrl, headers)];
39
38
 
40
39
  const client = new ApolloClient({
41
40
  link: from(links),
@@ -7,7 +7,7 @@ interface ApolloRequestInit extends RequestInit {
7
7
  formData?: FormData
8
8
  }
9
9
 
10
- export const FormDataHttpLink = (baseUrl: string, headers: Object) => {
10
+ export const formDataHttpLink = (baseUrl: string, headers: unknown) => {
11
11
  return new HttpLink({
12
12
  uri: `${baseUrl}/modules/graphql`,
13
13
  headers,
@@ -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,20 +0,0 @@
1
- export declare const setNodeProperty: (pathOrId: string, property: string, value: string, language: string) => Cypress.Chainable;
2
- export declare const deleteNode: (pathOrId: string) => Cypress.Chainable;
3
- export declare const grantRoles: (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string) => Cypress.Chainable;
4
- export declare const publishAndWaitJobEnding: (path: string, languages?: string[]) => void;
5
- export declare const waitAllJobsFinished: (errorMessage?: string, timeout?: number) => void;
6
- export declare const addNode: (variables: {
7
- parentPathOrId: string;
8
- primaryNodeType: string;
9
- name: string;
10
- properties?: any[];
11
- children?: any[];
12
- }) => Cypress.Chainable;
13
- export declare const getNodeByPath: (path: string) => Cypress.Chainable;
14
- export declare const createSite: (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string) => void;
15
- export declare const deleteSite: (siteKey: string) => void;
16
- export declare const createUser: (userName: string, password: string, properties?: {
17
- name: string;
18
- value: string;
19
- }[]) => void;
20
- export declare const deleteUser: (userName: string) => void;
@@ -1,128 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.deleteUser = exports.createUser = exports.deleteSite = exports.createSite = exports.getNodeByPath = exports.addNode = exports.waitAllJobsFinished = exports.publishAndWaitJobEnding = exports.grantRoles = exports.deleteNode = 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 deleteNode = function (pathOrId) {
17
- return cy.apollo({
18
- variables: {
19
- pathOrId: pathOrId
20
- },
21
- mutationFile: 'graphql/jcr/mutation/deleteNode.graphql'
22
- });
23
- };
24
- exports.deleteNode = deleteNode;
25
- var grantRoles = function (pathOrId, roleNames, principalName, principalType) {
26
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
27
- return cy.apollo({
28
- variables: {
29
- pathOrId: pathOrId,
30
- roleNames: roleNames,
31
- principalName: principalName,
32
- principalType: principalType
33
- },
34
- mutationFile: 'graphql/jcr/mutation/grantRoles.graphql'
35
- });
36
- };
37
- exports.grantRoles = grantRoles;
38
- var publishAndWaitJobEnding = function (path, languages) {
39
- if (languages === void 0) { languages = ['en']; }
40
- cy.apollo({
41
- variables: {
42
- pathOrId: path,
43
- languages: languages,
44
- publishSubNodes: true,
45
- includeSubTree: true
46
- },
47
- mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
48
- });
49
- exports.waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
50
- };
51
- exports.publishAndWaitJobEnding = publishAndWaitJobEnding;
52
- var waitAllJobsFinished = function (errorMessage, timeout) {
53
- if (timeout === void 0) { timeout = 60000; }
54
- cy.waitUntil(function () {
55
- return cy
56
- .apollo({
57
- fetchPolicy: 'no-cache',
58
- queryFile: 'graphql/jcr/query/getJobsWithStatus.graphql'
59
- })
60
- .then(function (response) {
61
- var _a, _b, _c, _d;
62
- 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;
63
- var publicationJobs = jobs.filter(function (job) { return job.group === 'PublicationJob'; });
64
- var hasActivePublicationJobs = publicationJobs.some(function (job) { return job.jobStatus === 'EXECUTING'; });
65
- return !hasActivePublicationJobs;
66
- });
67
- }, {
68
- errorMsg: errorMessage ? errorMessage : 'Jobs are still running before the end of timeout',
69
- timeout: timeout,
70
- verbose: true,
71
- interval: 1000
72
- });
73
- // Wait 2 seconds for server sync after publication
74
- // eslint-disable-next-line cypress/no-unnecessary-waiting
75
- cy.wait(2000);
76
- };
77
- exports.waitAllJobsFinished = waitAllJobsFinished;
78
- var addNode = function (variables) {
79
- return cy.apollo({
80
- variables: variables,
81
- mutationFile: 'graphql/jcr/mutation/addNode.graphql'
82
- });
83
- };
84
- exports.addNode = addNode;
85
- var getNodeByPath = function (path) {
86
- return cy.apollo({
87
- variables: {
88
- path: path
89
- },
90
- queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
91
- });
92
- };
93
- exports.getNodeByPath = getNodeByPath;
94
- var createSite = function (siteKey, templateSet, serverName, locale, languages) {
95
- var definedLocale = locale ? locale : 'en';
96
- cy.executeGroovy('groovy/admin/createSite.groovy', {
97
- SITEKEY: siteKey,
98
- TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
99
- SERVERNAME: serverName ? serverName : 'localhost',
100
- LOCALE: definedLocale,
101
- LANGUAGES: languages ? "Arrays.asList(" + languages + ")" : "Arrays.asList(\"" + definedLocale + "\")"
102
- });
103
- };
104
- exports.createSite = createSite;
105
- var deleteSite = function (siteKey) {
106
- cy.executeGroovy('groovy/admin/deleteSite.groovy', {
107
- SITEKEY: siteKey
108
- });
109
- };
110
- exports.deleteSite = deleteSite;
111
- var createUser = function (userName, password, properties) {
112
- if (properties === void 0) { properties = []; }
113
- var userProperties = properties.map(function (property) {
114
- return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
115
- });
116
- cy.executeGroovy('groovy/admin/createUser.groovy', {
117
- USER_NAME: userName,
118
- PASSWORD: password ? password : 'password',
119
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
120
- });
121
- };
122
- exports.createUser = createUser;
123
- var deleteUser = function (userName) {
124
- cy.executeGroovy('groovy/admin/deleteUser.groovy', {
125
- USER_NAME: userName
126
- });
127
- };
128
- exports.deleteUser = deleteUser;
@@ -1,122 +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 deleteNode = (pathOrId: string): Cypress.Chainable => {
14
- return cy.apollo({
15
- variables: {
16
- pathOrId: pathOrId
17
- },
18
- mutationFile: 'graphql/jcr/mutation/deleteNode.graphql'
19
- });
20
- };
21
-
22
- export const grantRoles = (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string): Cypress.Chainable => {
23
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
24
- return cy.apollo({
25
- variables: {
26
- pathOrId: pathOrId,
27
- roleNames: roleNames,
28
- principalName: principalName,
29
- principalType: principalType
30
- },
31
- mutationFile: 'graphql/jcr/mutation/grantRoles.graphql'
32
- });
33
- };
34
-
35
- export const publishAndWaitJobEnding = (path: string, languages: string[] = ['en']): void => {
36
- cy.apollo({
37
- variables: {
38
- pathOrId: path,
39
- languages: languages,
40
- publishSubNodes: true,
41
- includeSubTree: true
42
- },
43
- mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
44
- });
45
- waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
46
- };
47
-
48
- export const waitAllJobsFinished = (errorMessage?: string, timeout = 60000): void => {
49
- cy.waitUntil(
50
- () =>
51
- cy
52
- .apollo({
53
- fetchPolicy: 'no-cache',
54
- queryFile: 'graphql/jcr/query/getJobsWithStatus.graphql'
55
- })
56
- .then(response => {
57
- const jobs = response?.data?.admin?.jahia?.scheduler?.jobs;
58
- const publicationJobs = jobs.filter(job => job.group === 'PublicationJob');
59
- const hasActivePublicationJobs = publicationJobs.some(job => job.jobStatus === 'EXECUTING');
60
- return !hasActivePublicationJobs;
61
- }),
62
- {
63
- errorMsg: errorMessage ? errorMessage : 'Jobs are still running before the end of timeout',
64
- timeout: timeout,
65
- verbose: true,
66
- interval: 1000
67
- }
68
- );
69
- // Wait 2 seconds for server sync after publication
70
- // eslint-disable-next-line cypress/no-unnecessary-waiting
71
- cy.wait(2000);
72
- };
73
-
74
- export const addNode = (variables: { parentPathOrId: string, primaryNodeType: string, name: string, properties?: any[], children?: any[] }): Cypress.Chainable => {
75
- return cy.apollo({
76
- variables: variables,
77
- mutationFile: 'graphql/jcr/mutation/addNode.graphql'
78
- });
79
- };
80
-
81
- export const getNodeByPath = (path: string): Cypress.Chainable => {
82
- return cy.apollo({
83
- variables: {
84
- path: path
85
- },
86
- queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
87
- });
88
- };
89
-
90
- export const createSite = (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string): void => {
91
- const definedLocale = locale ? locale : 'en';
92
- cy.executeGroovy('groovy/admin/createSite.groovy', {
93
- SITEKEY: siteKey,
94
- TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
95
- SERVERNAME: serverName ? serverName : 'localhost',
96
- LOCALE: definedLocale,
97
- LANGUAGES: languages ? `Arrays.asList(${languages})` : `Arrays.asList("${definedLocale}")`
98
- });
99
- };
100
-
101
- export const deleteSite = (siteKey: string): void => {
102
- cy.executeGroovy('groovy/admin/deleteSite.groovy', {
103
- SITEKEY: siteKey
104
- });
105
- };
106
-
107
- export const createUser = (userName: string, password: string, properties: { name: string, value: string }[] = []): void => {
108
- const userProperties = properties.map(property => {
109
- return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
110
- });
111
- cy.executeGroovy('groovy/admin/createUser.groovy', {
112
- USER_NAME: userName,
113
- PASSWORD: password ? password : 'password',
114
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
115
- });
116
- };
117
-
118
- export const deleteUser = (userName: string): void => {
119
- cy.executeGroovy('groovy/admin/deleteUser.groovy', {
120
- USER_NAME: userName
121
- });
122
- };