Skip to content

Commit bcfa720

Browse files
authored
VACMS-11631: Create and save media entities in functional tests. (#12349)
* VACMS-11631: Create and save media entities in functional tests. * Stop ignoring test.
1 parent ec09325 commit bcfa720

File tree

7 files changed

+168
-44
lines changed

7 files changed

+168
-44
lines changed

.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": [
33
"airbnb",
4+
"plugin:cypress/recommended",
45
"plugin:prettier/recommended"
56
],
67
"root": true,
@@ -27,6 +28,7 @@
2728
"rules": {
2829
"prettier/prettier": "error",
2930
"consistent-return": ["off"],
31+
"cypress/no-unnecessary-waiting": ["off"],
3032
"no-underscore-dangle": ["off"],
3133
"max-nested-callbacks": ["warn", 3],
3234
"import/no-mutable-exports": ["warn"],

package-lock.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"eslint-config-airbnb": "^18.2.1",
6262
"eslint-config-prettier": "^7.0.0",
6363
"eslint-formatter-rdjson": "^1.0.3",
64+
"eslint-plugin-cypress": "^2.12.1",
6465
"eslint-plugin-import": "^2.22.1",
6566
"eslint-plugin-jsx-a11y": "^6.4.1",
6667
"eslint-plugin-prettier": "^3.2.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"Cypress complains about empty files."
2+
1

tests/cypress/integration/behavioral/common/i_create_a_media.js

+123-39
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,82 @@
11
import { Given } from "cypress-cucumber-preprocessor/steps";
2-
import { faker } from '@faker-js/faker';
2+
import { faker } from "@faker-js/faker";
33

44
const creators = {
5+
document: () => {
6+
cy.visit("/media/add/document");
7+
cy.scrollTo("top");
8+
cy.findAllByLabelText("Name").type(
9+
`[Test Data] ${faker.lorem.sentence()}`,
10+
{ force: true }
11+
);
12+
cy.findAllByLabelText("Section").select("VACO");
13+
cy.get("#edit-field-document-0-upload")
14+
.attachFile("documents/minimal.csv")
15+
.wait(1000);
16+
cy.get("form.media-form").find("input#edit-submit").click();
17+
return cy.wait(1000);
18+
},
19+
document_external: () => {
20+
cy.visit("/media/add/document_external");
21+
cy.scrollTo("top");
22+
cy.findAllByLabelText("Name").type(
23+
`[Test Data] ${faker.lorem.sentence()}`.substring(0, 60),
24+
{
25+
force: true,
26+
}
27+
);
28+
cy.findAllByLabelText("External File URL").type(
29+
"https://en.wikipedia.org/wiki/Stradella_bass_system#/media/File:120-button_Stradella_chart.pdf",
30+
{
31+
force: true,
32+
}
33+
);
34+
cy.findAllByLabelText("Description").type(faker.lorem.sentence(), {
35+
force: true,
36+
});
37+
cy.findAllByLabelText("Section").select("VACO");
38+
cy.get("form.media-form").find("input#edit-submit").click();
39+
return cy.wait(1000);
40+
},
541
image: () => {
6-
cy.visit('/media/add/image');
7-
cy.scrollTo('top');
8-
cy.findAllByLabelText('Name').type('[Test Data] ' + faker.lorem.sentence(), { force: true });
9-
cy.findAllByLabelText('Description').type(faker.lorem.sentence(), { force: true });
10-
cy.findAllByLabelText('Section').select('VACO');
11-
cy.get('#edit-image-0-upload').attachFile('images/polygon_image.png').wait(1000);
12-
cy.findAllByLabelText('Alternative text').type(faker.lorem.sentence(), { force: true });
13-
const resizePoint = cy.get('span.cropper-face.cropper-move');
14-
resizePoint.scrollIntoView();
15-
cy.scrollToSelector('.image-widget-data');
42+
cy.visit("/media/add/image");
43+
cy.scrollTo("top");
44+
cy.findAllByLabelText("Name").type(
45+
`[Test Data] ${faker.lorem.sentence()}`,
46+
{ force: true }
47+
);
48+
cy.findAllByLabelText("Description").type(faker.lorem.sentence(), {
49+
force: true,
50+
});
51+
cy.findAllByLabelText("Section").select("VACO");
52+
cy.get("#edit-image-0-upload")
53+
.attachFile("images/polygon_image.png")
54+
.wait(1000);
55+
cy.findAllByLabelText("Alternative text").type(faker.lorem.sentence(), {
56+
force: true,
57+
});
1658
cy.window().then((window) => {
17-
const POINTER_DOWN = window.PointerEvent ? 'pointerdown' : 'mousedown';
18-
const POINTER_MOVE = window.PointerEvent ? 'pointermove' : 'mousemove';
19-
const POINTER_UP = window.PointerEvent ? 'pointerup' : 'mouseup';
20-
const jQuery = window.jQuery;
21-
const cropperType = jQuery("[data-drupal-iwc=wrapper]").data('ImageWidgetCrop').types[0];
22-
const cropper = cropperType.cropper;
59+
window.jQuery('details[data-drupal-iwc-id="2_1"] > summary').click();
60+
cy.wait(1000);
61+
cy.get("span.cropper-face.cropper-move").scrollIntoView();
62+
});
63+
cy.window().then((window) => {
64+
const POINTER_DOWN = window.PointerEvent ? "pointerdown" : "mousedown";
65+
const POINTER_MOVE = window.PointerEvent ? "pointermove" : "mousemove";
66+
const POINTER_UP = window.PointerEvent ? "pointerup" : "mouseup";
67+
const cropperType = window.jQuery("[data-drupal-iwc=wrapper]").data(
68+
"ImageWidgetCrop"
69+
).types[0];
70+
const { cropper } = cropperType;
2371
const { dragBox } = cropper;
24-
const $wrapper = jQuery(dragBox).closest('.crop-preview-wrapper');
25-
const $cropBox = $wrapper.find('.cropper-crop-box');
26-
const $points = $wrapper.find('.cropper-point');
27-
const moveBox = jQuery('.cropper-face.cropper-move')[0].getBoundingClientRect();
72+
const $wrapper = window.jQuery(dragBox).closest(".crop-preview-wrapper");
73+
const $cropBox = $wrapper.find(".cropper-crop-box");
74+
const $points = $wrapper.find(".cropper-point");
75+
const moveBox = window
76+
.jQuery(".cropper-face.cropper-move")[0]
77+
.getBoundingClientRect();
2878
cy.wrap(dragBox)
29-
.trigger('mouseover', { force: true })
79+
.trigger("mouseover", { force: true })
3080
.wait(100)
3181
.trigger(POINTER_DOWN, { which: 1, force: true })
3282
.wait(100)
@@ -35,23 +85,57 @@ const creators = {
3585
.trigger(POINTER_MOVE, 50, 50, { which: 1, force: true })
3686
.wait(100)
3787
.trigger(POINTER_UP, { which: 1, force: true });
38-
const mediaImageUrl = jQuery('.image-widget-data').find('.file--image').find('a').attr('href');
39-
cy.wrap(mediaImageUrl).as('mediaImageUrl');
40-
cy.get('form.media-form').find('input#edit-submit').click();
41-
cy.window().then((window) => {
42-
const mediaPath = window.jQuery('[role="contentinfo"]').find('a').attr('href');
43-
const mediaId = mediaPath.split('/').pop();
44-
cy.wrap(mediaPath).as('mediaPath');
45-
cy.wrap(mediaId).as('mediaId');
46-
cy.visit(mediaPath);
47-
});
48-
});
49-
}
88+
});
89+
cy.window().then((window) => {
90+
const mediaImageUrl = window
91+
.jQuery("span.file--image")
92+
.find("a")
93+
.attr("href");
94+
cy.wrap(mediaImageUrl).as("mediaImageUrl");
95+
});
96+
cy.get("form.media-form").find("input#edit-submit").click();
97+
return cy.wait(1000);
98+
},
99+
video: () => {
100+
cy.visit("/media/add/video");
101+
cy.scrollTo("top");
102+
cy.findAllByLabelText("Name").type(
103+
`[Test Data] ${faker.lorem.sentence()}`,
104+
{ force: true }
105+
);
106+
cy.findAllByLabelText("Video URL").type(
107+
"https://www.youtube.com/watch?v=XuXax5-pWzI",
108+
{
109+
force: true,
110+
}
111+
);
112+
cy.findAllByLabelText("Description").type(faker.lorem.sentence(), {
113+
force: true,
114+
});
115+
cy.findAllByLabelText("Section").select("VACO");
116+
cy.get("form.media-form").find("input#edit-submit").click();
117+
return cy.wait(1000);
118+
},
50119
};
51120

52-
Given('I create a {string} media', (contentType) => {
53-
let creator = creators[contentType];
54-
assert.isNotNull(creator, `I do not know how to create ${contentType} media yet. Please add a definition in ${__filename}.`);
55-
creator();
121+
Given("I create a {string} media", (contentType) => {
122+
const creator = creators[contentType];
123+
assert.isDefined(
124+
creator,
125+
`I do not know how to create ${contentType} media yet. Please add a definition in ${__filename}.`
126+
);
127+
creator().then(() => {
128+
cy.location("pathname", { timeout: 10000 }).should(
129+
"not.include",
130+
"/media/add"
131+
);
132+
cy.getDrupalSettings().then((drupalSettings) => {
133+
const { currentPath } = drupalSettings.path;
134+
const pathComponents = currentPath.split("/");
135+
const mediaId = pathComponents.pop();
136+
cy.wrap(currentPath).as("mediaPath");
137+
cy.wrap(mediaId).as("mediaId");
138+
cy.wrap(currentPath).as("pagePath");
139+
});
140+
});
56141
});
57-

tests/cypress/integration/behavioral/common/i_create_a_node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Given('I create a {string} node', (contentType) => {
128128

129129
Given('I create a {string} node and continue', (contentType) => {
130130
let creator = creators[contentType];
131-
assert.isNotNull(creator, `I do not know how to create ${contentType} nodes yet. Please add a definition in ${__filename}.`);
131+
assert.isDefined(creator, `I do not know how to create ${contentType} nodes yet. Please add a definition in ${__filename}.`);
132132
creator().then(() => {
133133
cy.get('form.node-form').find('input#edit-save-continue').click();
134134
cy.location('pathname', {timeout: 10000}).should('not.include', '/node/add');
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
Feature: CMS Users can set h:m:s values
2-
In order to confirm that cms users can set hours minutes and seconds
3-
In the field_duration field
4-
I need to have confirm the field is visible and saves as expected
1+
Feature: Media entities
52

63
Scenario: Log in and confirm that field_duration has h:m:s format
74
Given I am logged in as a user with the "administrator" role
85
And I am at "media/add/video"
96
Then I should see "Video duration in Hours:Minutes:Seconds"
107
Then I am at "media/video/1278"
118
Then the element with selector "input.hms-field" should have attribute "value" matching expression "0:01:45"
9+
10+
Scenario: Log in and create a document media entity.
11+
Given I am logged in as a user with the "content_admin" role
12+
Then I create a "document" media
13+
14+
Scenario: Log in and create an external document media entity.
15+
Given I am logged in as a user with the "content_admin" role
16+
Then I create a "document_external" media
17+
18+
Scenario: Log in and create an image media entity.
19+
Given I am logged in as a user with the "content_admin" role
20+
Then I create a "image" media
21+
22+
Scenario: Log in and create a video media entity.
23+
Given I am logged in as a user with the "content_admin" role
24+
Then I create a "video" media

0 commit comments

Comments
 (0)