Skip to content

Commit

Permalink
New: startAt file option support for media and document viewers (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDeMicco authored Feb 27, 2018
1 parent 018f71c commit 34e7e37
Show file tree
Hide file tree
Showing 23 changed files with 533 additions and 68 deletions.
31 changes: 21 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @chrome @firefox @edge @safari @ie @android @ios
language: node_js
node_js:
- '8'
Expand All @@ -14,9 +15,15 @@ aliases:
sauce_connect: true
script: yarn run functional-tests-ci
cache: yarn
- &sauce-labs-mobile
- &sauce-labs-ios
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @mobile
- &sauce-labs-chrome
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @chrome
- &sauce-labs-firefox
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @firefox
stages:
- ci
- name: sauce-labs - windows 10
Expand All @@ -33,33 +40,37 @@ jobs:
- <<: *sauce-labs
stage: sauce-labs - windows 10
env: BROWSER_PLATFORM="Windows 10" BROWSER_NAME="MicrosoftEdge"
- <<: *sauce-labs
script: yarn run functional-tests-ci --grep @edge
- <<: *sauce-labs-chrome
stage: sauce-labs - windows 10
env: BROWSER_PLATFORM="Windows 10" BROWSER_NAME="chrome"
- <<: *sauce-labs
- <<: *sauce-labs-firefox
stage: sauce-labs - windows 10
env: BROWSER_PLATFORM="Windows 10" BROWSER_NAME="firefox"
- <<: *sauce-labs
stage: sauce-labs - windows 10
env: BROWSER_PLATFORM="Windows 10" BROWSER_NAME="internet explorer"
script: yarn run functional-tests-ci --grep @ie
- <<: *sauce-labs
stage: sauce-labs - osx
env: BROWSER_PLATFORM="macOS 10.13" BROWSER_NAME="safari"
- <<: *sauce-labs
script: yarn run functional-tests-ci --grep @safari
- <<: *sauce-labs-chrome
stage: sauce-labs - osx
env: BROWSER_PLATFORM="macOS 10.13" BROWSER_NAME="chrome"
- <<: *sauce-labs
- <<: *sauce-labs-firefox
stage: sauce-labs - osx
env: BROWSER_PLATFORM="macOS 10.13" BROWSER_NAME="firefox"
- <<: *sauce-labs-mobile
- <<: *sauce-labs-ios
stage: sauce-labs - mobile
env: BROWSER_PLATFORM="iOS" DEVICE_NAME="iPhone X Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="Safari"
- <<: *sauce-labs-mobile
- <<: *sauce-labs-ios
stage: sauce-labs - mobile
env: BROWSER_PLATFORM="iOS" DEVICE_NAME="iPhone 6 Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="Safari"
- <<: *sauce-labs-mobile
- <<: *sauce-labs-ios
stage: sauce-labs - mobile
env: BROWSER_PLATFORM="iOS" DEVICE_NAME="iPad Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="Safari"
- <<: *sauce-labs-mobile
- <<: *sauce-labs
stage: sauce-labs - mobile
env: BROWSER_PLATFORM="Android" DEVICE_NAME="Android Emulator" PLATFORM_VERSION="6.0" BROWSER_NAME="Chrome"
env: BROWSER_PLATFORM="Android" DEVICE_NAME="Android GoogleAPI Emulator" PLATFORM_VERSION="7.1" BROWSER_NAME="Chrome"
script: yarn run functional-tests-ci --grep @android
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ preview.show(fileId, accessToken, {
| File Option | Description |
| --- | --- |
| fileVersionId | File version ID to preview. This must be a valid non-current file version ID. Use [Get Versions](https://developer.box.com/reference#view-versions-of-a-file) to fetch a list of file versions |
| startAt | Object with unit and value properties indicating where to start the preview at. Current supported units are 'seconds' for media and 'pages' for documents. |

Access Token
------------
Expand Down
8 changes: 5 additions & 3 deletions codecept.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const DEFAULT_WAIT_TIME = 90000; // 90 seconds
const {
SAUCE_USERNAME,
SAUCE_ACCESS_KEY,
Expand All @@ -8,7 +7,8 @@ const {
BROWSER_VERSION = 'latest',
BROWSER_PLATFORM,
PLATFORM_VERSION,
DEVICE_NAME
DEVICE_NAME,
DEFAULT_WAIT_TIME = 90000
} = process.env;
const MOBILE_PLATFORMS = ['iOS', 'Android'];

Expand Down Expand Up @@ -53,7 +53,9 @@ if (typeof SAUCE_USERNAME === 'undefined') {
platformVersion: PLATFORM_VERSION,
deviceName: DEVICE_NAME,
deviceOrientation: 'portrait',
appiumVersion: '1.7.2'
appiumVersion: '1.7.2',
platformName: BROWSER_PLATFORM

});
helperObj.Appium = mixedInSauceObj;
}
Expand Down
13 changes: 12 additions & 1 deletion functional-tests/constants.js
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';
72 changes: 72 additions & 0 deletions functional-tests/file-options.html
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>
102 changes: 102 additions & 0 deletions functional-tests/fileOptions_test.js
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);
});
6 changes: 4 additions & 2 deletions functional-tests/header_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { SELECTOR_BOX_PREVIEW_BTN_DOWNLOAD, SELECTOR_DOWNLOAD_IFRAME } = require('./constants');
const { expect } = require('chai');

Feature('Header', { retries: 3 });
const { CI } = process.env;

Feature('Header', { retries: CI ? 3 : 0 });

Before((I) => {
I.amOnPage('/functional-tests/index.html');
});

Scenario('Download the file @ci', function*(I) {
Scenario('Download the file @ci @chrome @firefox @edge @safari @ie', function*(I) {
I.waitForVisible(SELECTOR_BOX_PREVIEW_BTN_DOWNLOAD);
I.click(SELECTOR_BOX_PREVIEW_BTN_DOWNLOAD);
I.waitForElement(SELECTOR_DOWNLOAD_IFRAME);
Expand Down
70 changes: 70 additions & 0 deletions functional-tests/helpers.js
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 */
Loading

0 comments on commit 34e7e37

Please sign in to comment.