| 1 |
import { getDataURLFromFile } from "@web/core/utils/urls"; |
| 2 |
import { stepUtils } from "@web_tour/tour_utils"; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
const testPngImage = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAD0lEQVQIHQEEAPv/AIdaewLIAV0IjhGPAAAAAElFTkSuQmCC'; |
| 8 |
const testPdf = 'JVBERi0xLjEKJWPDtsO2bW1lbnQKMSAwIG9iago8PC9UeXBlIC9DYXRhbG9nCi9QYWdlcyAyIDAgUgo+PgplbmRvYmoKMiAwIG9iago8PC9UeXBlIC9QYWdlcwovS2lkcyBbMyAwIFJdCi9Db3VudCAxCi9NZWRpYUJveCBbMCAwIDIxMCAyOTddCj4+CmVuZG9iagozIDAgb2JqCjw8L1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovUmVzb3VyY2VzCjw8L0ZvbnQKPDwvRjEKPDwvVHlwZSAvRm9udAovU3VidHlwZSAvVHlwZTEKL0Jhc2VGb250IC9UaW1lcy1Sb21hbgo+Pgo+Pgo+PgovQ29udGVudHMgNCAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwvTGVuZ3RoIDQ4Pj4Kc3RyZWFtCkJUCi9GMSA0OCBUZgo1MCAxMzAgVGQKKFRFU1QpIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMjEgMDAwMDAgbgowMDAwMDAwMDY5IDAwMDAwIG4KMDAwMDAwMDE0OSAwMDAwMCBuCjAwMDAwMDAyOTggMDAwMDAgbgp0cmFpbGVyCjw8L1Jvb3QgMSAwIFIKL1NpemUgNQo+PgpzdGFydHhyZWYKMzgxCiUlRU9G'; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
var addSection = function (sectionName, backend = false) { |
| 15 |
const prefix = backend ? ':iframe ' : ''; |
| 16 |
return [ |
| 17 |
{ |
| 18 |
content: 'eLearning: click on Add Section', |
| 19 |
trigger: prefix + 'a.o_wslides_js_slide_section_add', |
| 20 |
run: "click", |
| 21 |
}, { |
| 22 |
content: 'eLearning: set section name', |
| 23 |
trigger: prefix + 'input[name="name"]', |
| 24 |
run: `edit ${sectionName}`, |
| 25 |
}, { |
| 26 |
content: 'eLearning: create section', |
| 27 |
trigger: prefix + 'footer.modal-footer button:contains("Save")', |
| 28 |
run: "click", |
| 29 |
}, { |
| 30 |
content: 'eLearning: section created empty', |
| 31 |
trigger: prefix + 'div.o_wslides_slide_list_category_header:contains("' + sectionName + '")', |
| 32 |
run: "click", |
| 33 |
}]; |
| 34 |
}; |
| 35 |
|
| 36 |
const addContentToSection = (prefix, sectionName) => ({ |
| 37 |
content: `eLearning: click on add content for section ${sectionName}`, |
| 38 |
trigger: `${prefix} div.o_wslides_slide_list_category_header:contains(${sectionName}) a:contains(Add Content)`, |
| 39 |
run: "click", |
| 40 |
}); |
| 41 |
|
| 42 |
const clickOnAddTagDropdown = (prefix) => [ |
| 43 |
{ |
| 44 |
content: "Wait content is loaded before continue to avoid miss click", |
| 45 |
trigger: `${prefix} img[src*='boulonnate']`, |
| 46 |
}, |
| 47 |
{ |
| 48 |
content: "eLearning: click on Add Tag", |
| 49 |
trigger: `${prefix} a.o_wslides_js_channel_tag_add`, |
| 50 |
run: "click", |
| 51 |
}, |
| 52 |
{ |
| 53 |
content: "eLearning: click on tag dropdown", |
| 54 |
trigger: `${prefix} button.o_select_menu_toggler:first`, |
| 55 |
run: "click", |
| 56 |
}, |
| 57 |
]; |
| 58 |
|
| 59 |
var addVideoToSection = function (sectionName, saveAsDraft, backend = false) { |
| 60 |
const prefix = backend ? ':iframe ' : ''; |
| 61 |
var base_steps = [ |
| 62 |
addContentToSection(prefix, sectionName), |
| 63 |
{ |
| 64 |
content: "eLearning: click on video", |
| 65 |
trigger: prefix + "a[data-slide-category=video]", |
| 66 |
run: "click", |
| 67 |
}, |
| 68 |
{ |
| 69 |
content: "eLearning: fill video link", |
| 70 |
trigger: prefix + "input[name=video_url]", |
| 71 |
run: "edit https://www.youtube.com/watch?v=pzmI3vAIhbE", |
| 72 |
}, |
| 73 |
{ |
| 74 |
content: "eLearning: click outside to trigger onchange", |
| 75 |
trigger: prefix + "div.o_w_slide_upload_modal_container", |
| 76 |
run: "click", |
| 77 |
}, |
| 78 |
]; |
| 79 |
if (saveAsDraft) { |
| 80 |
base_steps = [].concat(base_steps, [ |
| 81 |
{ |
| 82 |
trigger: |
| 83 |
prefix + |
| 84 |
'div.o_slide_preview img:not([src="/website_slides/static/src/img/document.png"])', |
| 85 |
}, |
| 86 |
{ |
| 87 |
content: "eLearning: save as draft slide", |
| 88 |
trigger: prefix + 'footer.modal-footer button:contains("Save as Draft")', |
| 89 |
run: "click", |
| 90 |
}, |
| 91 |
]); |
| 92 |
} else { |
| 93 |
base_steps = [].concat(base_steps, [ |
| 94 |
{ |
| 95 |
trigger: |
| 96 |
prefix + |
| 97 |
'div.o_slide_preview img:not([src="/website_slides/static/src/img/document.png"])', |
| 98 |
}, |
| 99 |
{ |
| 100 |
content: "eLearning: create and publish slide", |
| 101 |
trigger: prefix + 'footer.modal-footer button:contains("Publish")', |
| 102 |
run: "click", |
| 103 |
}, |
| 104 |
]); |
| 105 |
} |
| 106 |
return base_steps; |
| 107 |
}; |
| 108 |
|
| 109 |
var addArticleToSection = function (sectionName, pageName, backend) { |
| 110 |
const prefix = backend ? ':iframe ' : ''; |
| 111 |
return [ |
| 112 |
addContentToSection(prefix, sectionName), |
| 113 |
{ |
| 114 |
content: 'eLearning: click on article', |
| 115 |
trigger: prefix + 'a[data-slide-category=article]', |
| 116 |
run: "click", |
| 117 |
}, { |
| 118 |
content: 'eLearning: fill article title', |
| 119 |
trigger: prefix + 'input[name=name]', |
| 120 |
run: `edit ${pageName}`, |
| 121 |
}, { |
| 122 |
content: 'eLearning: click on tags', |
| 123 |
trigger: prefix + ".o_select_menu_toggler:last", |
| 124 |
run: "click", |
| 125 |
}, { |
| 126 |
content: 'eLearning: select Practice tag', |
| 127 |
trigger: prefix + 'span.o_select_menu_item:contains("Practice")', |
| 128 |
run: "click", |
| 129 |
}, { |
| 130 |
content: 'eLearning: fill article completion time', |
| 131 |
trigger: prefix + 'input[name=duration]', |
| 132 |
run: "edit 4", |
| 133 |
}, { |
| 134 |
content: 'eLearning: create and publish slide', |
| 135 |
trigger: prefix + 'footer.modal-footer button:contains("Publish")', |
| 136 |
run: "click", |
| 137 |
expectUnloadPage: true, |
| 138 |
}]; |
| 139 |
}; |
| 140 |
|
| 141 |
const fillInFileInput = async (input, name, type, content) => { |
| 142 |
const blob = await (await fetch(`data:${type};base64,${content}`)).blob(); |
| 143 |
const file = new File([blob], name, { type: type}); |
| 144 |
const dataTransfer = new DataTransfer(); |
| 145 |
dataTransfer.items.add(file); |
| 146 |
input.files = dataTransfer.files; |
| 147 |
input.dispatchEvent(new Event('change', { bubbles: true })); |
| 148 |
}; |
| 149 |
|
| 150 |
const compareBase64Content = async (url, name, type, expectedContent) => { |
| 151 |
const blob = await (await fetch(url)).blob(); |
| 152 |
const file = new File([blob], name, { type: type}); |
| 153 |
const actualContent = await getDataURLFromFile(file).then(dataURL => dataURL.split(',', 2)[1]); |
| 154 |
return expectedContent === actualContent; |
| 155 |
}; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
const addImageToSection = (sectionName, pageName, backend) => { |
| 161 |
const prefix = backend ? ':iframe ' : ''; |
| 162 |
return [ |
| 163 |
addContentToSection(prefix, sectionName), |
| 164 |
{ |
| 165 |
content: 'eLearning: click on image', |
| 166 |
trigger: `${prefix}a[data-slide-category=infographic]`, |
| 167 |
run: "click", |
| 168 |
}, { |
| 169 |
content: 'eLearning: choose upload from device', |
| 170 |
trigger: `${prefix}#source_type_local_file`, |
| 171 |
run: "click", |
| 172 |
}, { |
| 173 |
content: 'eLearning: load image', |
| 174 |
trigger: 'body', |
| 175 |
run: async () => { |
| 176 |
const uploadInput = backend ? |
| 177 |
document.getElementsByTagName('iframe')[0].contentWindow.document.getElementById('upload') : |
| 178 |
document.getElementById('upload'); |
| 179 |
await fillInFileInput(uploadInput, 'Overview.png', 'image/png', testPngImage); |
| 180 |
}, |
| 181 |
}, { |
| 182 |
content: 'eLearning: ensure that the preview is displayed which means that data is loaded and can be submitted', |
| 183 |
trigger: `${prefix}#slide-image[src*="data:"]`, |
| 184 |
}, { |
| 185 |
content: 'eLearning: create and publish slide', |
| 186 |
trigger: `${prefix}footer.modal-footer button:contains("Publish")`, |
| 187 |
run: "click", |
| 188 |
}, { |
| 189 |
content: 'eLearning: launch content', |
| 190 |
trigger: `${prefix} a.o_wslides_js_slides_list_slide_link:contains("Overview")[href$="?fullscreen=1"]`, |
| 191 |
run: "click", |
| 192 |
}, |
| 193 |
{ |
| 194 |
content: 'eLearning: check uploaded image presence and perform comparison', |
| 195 |
trigger: prefix + '.o_wslides_fs_player img', |
| 196 |
run: async () => { |
| 197 |
const baseElement = backend ? document.querySelector('iframe').contentDocument : document; |
| 198 |
const img = baseElement.querySelector('.o_wslides_fs_player img'); |
| 199 |
if (await compareBase64Content(img.getAttribute('src'), 'Overview.png', 'image/png', testPngImage)) { |
| 200 |
img.classList.add('o_wslides_tour_img_upload_success'); |
| 201 |
} |
| 202 |
} |
| 203 |
}, { |
| 204 |
content: 'eLearning: check uploaded image content', |
| 205 |
trigger: `${prefix}.o_wslides_fs_player img.o_wslides_tour_img_upload_success`, |
| 206 |
run: "click", |
| 207 |
}, |
| 208 |
{ |
| 209 |
content: 'eLearning: back to course', |
| 210 |
trigger: `${prefix}.o_wslides_fs_sidebar_header a:contains("Déboulonnate")`, |
| 211 |
run: "click", |
| 212 |
}, |
| 213 |
{ |
| 214 |
content: 'eLearning: check course page', |
| 215 |
trigger: `${prefix}.o_wslides_course_main`, |
| 216 |
}]; |
| 217 |
}; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
const addPdfToSection = function (sectionName, pageName, backend) { |
| 223 |
const prefix = backend ? ':iframe ' : ''; |
| 224 |
return [ |
| 225 |
addContentToSection(prefix, sectionName), |
| 226 |
{ |
| 227 |
content: 'eLearning: click on document', |
| 228 |
trigger: `${prefix}a[data-slide-category=document]`, |
| 229 |
run: "click", |
| 230 |
}, { |
| 231 |
content: 'eLearning: choose upload from device', |
| 232 |
trigger: `${prefix}#source_type_local_file`, |
| 233 |
run: "click", |
| 234 |
}, { |
| 235 |
content: 'eLearning: load pdf', |
| 236 |
trigger: 'body', |
| 237 |
run: async () => { |
| 238 |
const upload = backend ? |
| 239 |
document.getElementsByTagName('iframe')[0].contentWindow.document.getElementById('upload') : |
| 240 |
document.getElementById('upload'); |
| 241 |
await fillInFileInput(upload, 'Exercise.pdf', 'application/pdf', testPdf); |
| 242 |
}, |
| 243 |
}, { |
| 244 |
content: 'eLearning: ensure that the preview is displayed which means that data is loaded and can be submitted', |
| 245 |
trigger: `${prefix}#slide-image[src*="data:"]`, |
| 246 |
run: "click", |
| 247 |
}, { |
| 248 |
content: 'eLearning: create and publish slide', |
| 249 |
trigger: `${prefix}footer.modal-footer button:contains("Publish")`, |
| 250 |
run: "click", |
| 251 |
}, { |
| 252 |
content: 'eLearning: launch content', |
| 253 |
trigger: `${prefix} a.o_wslides_js_slides_list_slide_link:contains(Exercise)[href$="?fullscreen=1"]`, |
| 254 |
run: "click", |
| 255 |
}, |
| 256 |
stepUtils.waitIframeIsReady(), |
| 257 |
{ |
| 258 |
content: 'eLearning: check uploaded pdf presence and perform comparison', |
| 259 |
trigger: (backend ? ':iframe ' : '') + '.o_wslides_fs_content :iframe #PDFSlideViewer', |
| 260 |
run: async (helpers) => { |
| 261 |
if (await compareBase64Content(helpers.anchor.getAttribute('data-slideurl'), 'Exercise.pdf', 'application/pdf', testPdf)) { |
| 262 |
helpers.anchor.classList.add('o_wslides_tour_pdf_upload_success'); |
| 263 |
} |
| 264 |
}, |
| 265 |
}, { |
| 266 |
content: 'eLearning: check uploaded pdf content', |
| 267 |
trigger: `${prefix}.o_wslides_fs_content :iframe #PDFSlideViewer.o_wslides_tour_pdf_upload_success`, |
| 268 |
run: "click", |
| 269 |
}, { |
| 270 |
content: 'eLearning: back to course', |
| 271 |
trigger: `${prefix}.o_wslides_fs_sidebar_header a:contains("Déboulonnate")`, |
| 272 |
run: "click", |
| 273 |
}, { |
| 274 |
content: 'eLearning: check course page', |
| 275 |
trigger: `${prefix}.o_wslides_course_main`, |
| 276 |
}]; |
| 277 |
}; |
| 278 |
|
| 279 |
var addExistingCourseTag = function (backend = false) { |
| 280 |
const prefix = backend ? ':iframe ' : ''; |
| 281 |
return [ |
| 282 |
...clickOnAddTagDropdown(prefix), |
| 283 |
{ |
| 284 |
content: 'eLearning: select advanced tag', |
| 285 |
trigger: prefix + '.o_select_menu_item:contains("Advanced")', |
| 286 |
run: "click", |
| 287 |
}, { |
| 288 |
content: 'eLearning: add existing course tag', |
| 289 |
trigger: prefix + 'footer.modal-footer a:contains("Add")', |
| 290 |
run: "click", |
| 291 |
}, { |
| 292 |
content: 'eLearning: check that modal is closed', |
| 293 |
trigger: prefix + 'body:not(.modal-open)', |
| 294 |
}]; |
| 295 |
}; |
| 296 |
|
| 297 |
var addNewCourseTag = function (courseTagName, backend) { |
| 298 |
const prefix = backend ? ':iframe ' : ''; |
| 299 |
return [ |
| 300 |
...clickOnAddTagDropdown(prefix), |
| 301 |
{ |
| 302 |
content: 'eLearning: add a new course tag', |
| 303 |
trigger: prefix + 'input.dropdown-item:first', |
| 304 |
run: "edit 123", |
| 305 |
}, { |
| 306 |
content: 'eLearning: click on create this tag', |
| 307 |
trigger: prefix + 'i:contains("123")', |
| 308 |
run: "click", |
| 309 |
},{ |
| 310 |
content: 'eLearning: click on tag group dropdown', |
| 311 |
trigger: prefix + 'button.o_select_menu_toggler:last', |
| 312 |
run: "click", |
| 313 |
}, { |
| 314 |
content: 'eLearning: select Tags tag group', |
| 315 |
trigger: prefix + '.o_select_menu_item:contains("Tags")', |
| 316 |
run: "click", |
| 317 |
}, { |
| 318 |
content: 'eLearning: add new course tag', |
| 319 |
trigger: prefix + 'footer.modal-footer a:contains("Add")', |
| 320 |
run: "click", |
| 321 |
}, { |
| 322 |
content: 'eLearning: check that modal is closed', |
| 323 |
trigger: prefix + 'body:not(.modal-open)', |
| 324 |
}]; |
| 325 |
}; |
| 326 |
|
| 327 |
export default { |
| 328 |
addSection: addSection, |
| 329 |
addImageToSection: addImageToSection, |
| 330 |
addPdfToSection: addPdfToSection, |
| 331 |
addVideoToSection: addVideoToSection, |
| 332 |
addArticleToSection: addArticleToSection, |
| 333 |
addExistingCourseTag: addExistingCourseTag, |
| 334 |
addNewCourseTag: addNewCourseTag, |
| 335 |
}; |