-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: startAt file option support for media and document viewers (#663)
- Loading branch information
1 parent
018f71c
commit 34e7e37
Showing
23 changed files
with
533 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
// Unfortunately node doesnt support native imports (yet) | ||
|
||
exports.SELECTOR_BOX_PREVIEW_BTN_DOWNLOAD = '.bp-btn-download'; | ||
exports.SELECTOR_DOWNLOAD_IFRAME = '#downloadiframe'; | ||
exports.SELECTOR_NAVIGATION_LEFT = '.bp-navigate-left'; | ||
exports.SELECTOR_NAVIGATION_RIGHT = '.bp-navigate-right'; | ||
exports.SELECTOR_BOX_PREVIEW_LOADED = '.bp-loaded'; | ||
exports.SELECTOR_BOX_PREVIEW_LOGO = '.bp-default-logo'; | ||
exports.CLASS_BOX_PREVIEW_LOADING_WRAPPER = '.bp-loading-wrapper'; | ||
exports.SELECTOR_DOC_CURRENT_PAGE = '.bp-current-page'; | ||
exports.SELECTOR_MEDIA_TIMESTAMP = '.bp-media-controls-timecode'; | ||
exports.SELECTOR_BOX_PREVIEW = '.bp'; | ||
exports.SELECTOR_BOX_PREVIEW_DOC = '.bp-doc'; | ||
exports.SELECTOR_BOX_PREVIEW_MP3 = '.bp-media-mp3'; | ||
exports.SELECTOR_BOX_PREVIEW_DASH = '.bp-media-dash'; | ||
exports.SELECTOR_BOX_PREVIEW_MP4 = '.bp-media-mp4'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<style> | ||
.preview-container { | ||
border: 1px solid #eee; | ||
height: 490px; | ||
width: 100%; | ||
} | ||
</style> | ||
<link rel="stylesheet" type="text/css" href="../dist/dev/en-US/preview.css"> | ||
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise"></script> | ||
<script src="../dist/dev/en-US/preview.js"></script> | ||
|
||
</head> | ||
|
||
<body> | ||
<div class="preview-container"></div> | ||
<script> | ||
var ACCESS_TOKEN = 'EqFyi1Yq1tD9mxY8F38sxDfp73pFd7FP'; | ||
|
||
var FILE_ID_DOC = '93392244621'; | ||
var FILE_ID_VIDEO = '193986007241'; | ||
var FILE_ID_MP3 = '193985625282'; | ||
|
||
var preview = new Box.Preview(); | ||
var fileOptions = {}; | ||
fileOptions[FILE_ID_DOC] = { | ||
startAt: { | ||
value: 2, | ||
unit: 'pages' | ||
} | ||
}; | ||
fileOptions[FILE_ID_VIDEO] = { | ||
startAt: { | ||
value: 15, | ||
unit: 'seconds' | ||
} | ||
} | ||
fileOptions[FILE_ID_MP3] = { | ||
startAt: { | ||
value: 3, | ||
unit: 'seconds' | ||
} | ||
} | ||
preview.show(FILE_ID_DOC, ACCESS_TOKEN, { | ||
container: '.preview-container', | ||
showDownload: false, | ||
collection: [FILE_ID_DOC, FILE_ID_VIDEO, FILE_ID_MP3], | ||
fileOptions: fileOptions | ||
}); | ||
|
||
function disableDash() { | ||
preview.disableViewers('Dash'); | ||
fileOptions[FILE_ID_VIDEO] = { | ||
startAt: { | ||
value: 10, | ||
unit: 'seconds' | ||
} | ||
} | ||
preview.show(FILE_ID_VIDEO, ACCESS_TOKEN, { | ||
container: '.preview-container', | ||
showDownload: false, | ||
fileOptions: fileOptions | ||
}); | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { | ||
SELECTOR_BOX_PREVIEW_LOADED, | ||
SELECTOR_MEDIA_TIMESTAMP, | ||
SELECTOR_DOC_CURRENT_PAGE, | ||
SELECTOR_BOX_PREVIEW_LOGO, | ||
CLASS_BOX_PREVIEW_LOADING_WRAPPER, | ||
SELECTOR_BOX_PREVIEW_DOC, | ||
SELECTOR_BOX_PREVIEW_MP3, | ||
SELECTOR_BOX_PREVIEW_DASH, | ||
SELECTOR_BOX_PREVIEW_MP4 | ||
} = require('./constants'); | ||
|
||
const { navigateToNextItem, makeNavAppear, navigateToPrevItem } = require('./helpers'); | ||
|
||
const { CI } = process.env; | ||
const DOC_START = '2'; | ||
const DASH_START = '0:15'; | ||
const MP3_START = '0:03'; | ||
const MP4_START = '0:10'; | ||
const SELECTOR_VIDEO = 'video'; | ||
|
||
Feature('File Options', { retries: CI ? 3 : 0 }); | ||
|
||
Before((I) => { | ||
I.amOnPage('/functional-tests/file-options.html'); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOADED); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOGO); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_DOC); | ||
}); | ||
|
||
// Excludes ie | ||
Scenario( | ||
'Check preview starts at correct spot for all file types @ci @chrome @firefox @edge @safari @android @ios', | ||
(I) => { | ||
// document | ||
makeNavAppear(I); | ||
I.waitForVisible(SELECTOR_DOC_CURRENT_PAGE); | ||
I.seeTextEquals(DOC_START, SELECTOR_DOC_CURRENT_PAGE); | ||
navigateToNextItem(I); | ||
|
||
// video (dash) | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOADED); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_DASH); | ||
makeNavAppear(I, SELECTOR_VIDEO); | ||
I.waitForVisible(SELECTOR_MEDIA_TIMESTAMP); | ||
I.seeTextEquals(DASH_START, SELECTOR_MEDIA_TIMESTAMP); | ||
navigateToNextItem(I); | ||
|
||
// mp3 | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_MP3); | ||
makeNavAppear(I); | ||
I.waitForVisible(SELECTOR_MEDIA_TIMESTAMP); | ||
I.seeTextEquals(MP3_START, SELECTOR_MEDIA_TIMESTAMP); | ||
|
||
// video (mp4) | ||
/* eslint-disable prefer-arrow-callback */ | ||
I.executeScript(function() { | ||
window.disableDash(); | ||
}); | ||
I.waitForElement(CLASS_BOX_PREVIEW_LOADING_WRAPPER); | ||
/* eslint-enable prefer-arrow-callback */ | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOADED); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_MP4); | ||
|
||
makeNavAppear(I, SELECTOR_VIDEO); | ||
I.waitForVisible(SELECTOR_MEDIA_TIMESTAMP); | ||
I.seeTextEquals(MP4_START, SELECTOR_MEDIA_TIMESTAMP); | ||
} | ||
); | ||
|
||
// Sacuelabs ie11 doesn't like audio files | ||
Scenario('Check preview starts at correct spot for all file types @ci @ie', (I) => { | ||
// document | ||
makeNavAppear(I); | ||
I.waitForVisible(SELECTOR_DOC_CURRENT_PAGE); | ||
I.seeTextEquals(DOC_START, SELECTOR_DOC_CURRENT_PAGE); | ||
navigateToNextItem(I); | ||
|
||
// video (dash) | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_DASH); | ||
makeNavAppear(I, SELECTOR_VIDEO); | ||
I.waitForVisible(SELECTOR_MEDIA_TIMESTAMP); | ||
I.seeTextEquals(DASH_START, SELECTOR_MEDIA_TIMESTAMP); | ||
|
||
// mp3 is not supported :( | ||
navigateToPrevItem(I); | ||
// video (mp4) | ||
/* eslint-disable prefer-arrow-callback */ | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOADED); | ||
|
||
I.executeScript(function() { | ||
window.disableDash(); | ||
}); | ||
/* eslint-enable prefer-arrow-callback */ | ||
|
||
I.waitForElement(SELECTOR_BOX_PREVIEW_LOADED); | ||
I.waitForElement(SELECTOR_BOX_PREVIEW_MP4); | ||
|
||
makeNavAppear(I, SELECTOR_VIDEO); | ||
I.waitForVisible(SELECTOR_MEDIA_TIMESTAMP); | ||
I.seeTextEquals(MP4_START, SELECTOR_MEDIA_TIMESTAMP); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { SELECTOR_BOX_PREVIEW, CLASS_BOX_PREVIEW_LOADING_WRAPPER } = require('./constants'); | ||
|
||
/** | ||
* Makes the navigation arrows appear in preview | ||
* This currently doesnt work in firefox | ||
* | ||
* @param {Object} I the codeceptjs I | ||
* | ||
* @return {void} | ||
*/ | ||
function makeNavAppear(I, selector = SELECTOR_BOX_PREVIEW) { | ||
I.waitForElement(selector); | ||
|
||
/* eslint-disable prefer-arrow-callback, no-var */ | ||
I.executeScript(function(sel) { | ||
var count = 0; | ||
var el = document.querySelector(sel); | ||
|
||
/** | ||
* Simulates click and mousemove events for mobile & desktop browsers for | ||
* controls to appear | ||
* | ||
* @return {void} | ||
*/ | ||
function simulateEvents() { | ||
/** | ||
* Cross browswer event creation | ||
* @param {string} eventName the event name | ||
* @return {Event} the event | ||
*/ | ||
function createNewEvent(eventName) { | ||
var event; | ||
if (typeof Event === 'function') { | ||
event = new Event(eventName, { bubbles: true }); | ||
} else { | ||
event = document.createEvent('Event'); | ||
event.initEvent(eventName, true, true); | ||
} | ||
|
||
return event; | ||
} | ||
|
||
el.dispatchEvent(createNewEvent('mousemove')); | ||
el.dispatchEvent(createNewEvent('click')); | ||
|
||
count += 1; | ||
if (count < 5) { | ||
simulateEvents(); | ||
} | ||
} | ||
|
||
setTimeout(simulateEvents, 500); | ||
simulateEvents(); | ||
}, selector); | ||
} | ||
|
||
exports.makeNavAppear = makeNavAppear; | ||
exports.navigateToNextItem = (I) => { | ||
I.executeScript(function() { | ||
window.preview.navigateRight(); | ||
}); | ||
I.waitForElement(CLASS_BOX_PREVIEW_LOADING_WRAPPER); | ||
}; | ||
exports.navigateToPrevItem = (I) => { | ||
I.executeScript(function() { | ||
window.preview.navigateLeft(); | ||
}); | ||
I.waitForElement(CLASS_BOX_PREVIEW_LOADING_WRAPPER); | ||
}; | ||
/* eslint-enable prefer-arrow-callback, no-var */ |
Oops, something went wrong.