1
1
import { Given } from "cypress-cucumber-preprocessor/steps" ;
2
- import { faker } from ' @faker-js/faker' ;
2
+ import { faker } from " @faker-js/faker" ;
3
3
4
4
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
+ } ,
5
41
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
+ } ) ;
16
58
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 ;
23
71
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 ( ) ;
28
78
cy . wrap ( dragBox )
29
- . trigger ( ' mouseover' , { force : true } )
79
+ . trigger ( " mouseover" , { force : true } )
30
80
. wait ( 100 )
31
81
. trigger ( POINTER_DOWN , { which : 1 , force : true } )
32
82
. wait ( 100 )
@@ -35,23 +85,57 @@ const creators = {
35
85
. trigger ( POINTER_MOVE , 50 , 50 , { which : 1 , force : true } )
36
86
. wait ( 100 )
37
87
. 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
+ } ,
50
119
} ;
51
120
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
+ } ) ;
56
141
} ) ;
57
-
0 commit comments