Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
New: Added tests 馃殌馃殌馃殌
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Sep 28, 2017
1 parent ea8d853 commit cbdb6e9
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 19 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<template is="dom-bind" id="demo">
<div class="vertical-section-container centered">
<section card>
<import-panel on-google-autorize="_onAuth"></import-panel>
<import-panel api-key="10525470235-anf4fj0c73c0of7g2vt62f0lj93bnrtp.apps.googleusercontent.com" on-google-autorize="_onAuth"></import-panel>
</section>
<arc-data-import></arc-data-import>
<google-signin-aware client-id="10525470235-anf4fj0c73c0of7g2vt62f0lj93bnrtp.apps.googleusercontent.com" scopes="{{authScope}}" signed-in="{{signedIn}}" is-authorized="{{isAuthorized}}" need-additional-auth="{{needAdditionalAuth}}" on-google-signin-aware-error="handleSignInError" on-google-signin-aware-success="_userAuthorized" on-google-signin-offline-success="handleOffline" on-google-signin-aware-signed-out="handleSignOut" on-signed-in-changed="handleStateChange" on-initialized-changed="handleStateChange"></google-signin-aware>
Expand Down
4 changes: 2 additions & 2 deletions import-data-inspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
</template>

<form-action-bar>
<paper-button on-tap="_cancel">Cancel</paper-button>
<paper-button class="primary-action" on-tap="_import">Import data</paper-button>
<paper-button on-tap="_cancel" data-action="cancel-import">Cancel</paper-button>
<paper-button class="primary-action" on-tap="_import" data-action="import-data">Import data</paper-button>
</form-action-bar>
</template>
<script>
Expand Down
38 changes: 28 additions & 10 deletions import-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@
<iron-pages selected="[[selectedPage]]">
<section class="import-actions">
<h2>Import data</h2>
<paper-button on-tap="_selectFile" raised>
<paper-button on-tap="_selectFile" raised data-action="opend-file-picker">
Open from file
<iron-icon icon="arc:insert-drive-file"></iron-icon>
</paper-button>
<paper-button on-tap="_importDrive" raised>
<paper-button on-tap="_importDrive" raised data-action="open-drive-picker">
Open from Drive
<iron-icon icon="arc:drive"></iron-icon>
</paper-button>
<paper-button on-tap="_pasteData" raised>
<paper-button on-tap="_pasteData" raised data-action="open-text-entry">
Paste text data
<iron-icon icon="arc:short-text"></iron-icon>
</paper-button>
Expand All @@ -182,8 +182,8 @@ <h2>Paste data</h2>
</div>
<paper-textarea label="Import data" id="manualInput"></paper-textarea>
<form-action-bar>
<paper-button on-tap="screenBack">Cancel</paper-button>
<paper-button class="primary-action" on-tap="_importText">Next</paper-button>
<paper-button on-tap="screenBack" data-action="cancel-text">Cancel</paper-button>
<paper-button class="primary-action" on-tap="_importText" data-action="import-text">Next</paper-button>
</form-action-bar>
</section>
<section>
Expand Down Expand Up @@ -212,14 +212,13 @@ <h2>Inspect data</h2>
},
// Treue when file is being loaded.
readingFile: Boolean,
// Any error message to print.
error: String,
/**
* Currently selected import page.
*
* - 0 is import options selector
* - 1 is Google Drive file picker
* - 2 is import table preview
* - 2 is paste data
* - 3 is import table preview
*/
selectedPage: {
type: Number,
Expand Down Expand Up @@ -361,8 +360,16 @@ <h2>Inspect data</h2>
_processContent: function(content) {
var event = this.fire('import-normalize', {
content: content,
}, {
cancelable: true
});

if (!event.detail.result) {
let err = 'Data importer not in the DOM.';
this._notifyError(err);
return Promise.reject(new Error(err));
}

return event.detail.result.then(result => {
this.data = result;
this.selectedPage = 3;
Expand All @@ -386,22 +393,33 @@ <h2>Inspect data</h2>
// Sends the `import-data` custom event to the import element to save the data
_importData: function(e) {
var data = e.detail;
this.importing = true;
this._setImporting(true);
var event = this.fire('import-data', {
content: data,
}, {
cancelable: true
});

event.detail.result.then(errors => {
if (!event.detail.result) {
let err = 'Data importer not in the DOM.';
this._notifyError(err);
throw new Error(err);
}

// Returns value for tests.
return event.detail.result.then(errors => {
this.data = undefined;
this.selectedPage = 0;
this.$.imported.opened = true;
this._setImporting(false);
if (errors) {
console.error(errors);
}
})
.catch(cause => {
this._notifyError(cause.message);
console.error(cause);
this._setImporting(false);
this.fire('app-log', {
'message': ['import:data-save', cause.message],
'level': 'error'
Expand Down
60 changes: 55 additions & 5 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>

<!-- Step 1: import the element to test -->
<link rel="import" href="../import-panel.html">
</head>
<body>
Expand All @@ -30,16 +28,68 @@
</test-fixture>

<script>
/* global fixture, assert */
/* global fixture, assert, MockInteractions */
suite('basic', function() {

var element;
setup(function() {
element = fixture('basic');
});

test('`import-panel` should be initialized', function() {
assert.equal(element.isAttached, true, 'element.isAttached equals true');
test('data is not set', function() {
assert.isUndefined(element.data);
});

test('hasData is not computed', function() {
assert.isUndefined(element.hasData);
});

test('readingFile inherited value', function() {
assert.isFalse(element.readingFile);
});

test('withDriveList is not set', function() {
assert.isUndefined(element.withDriveList);
});

test('importing is false by default', function() {
assert.isFalse(element.importing);
});

test('Drive picker is not opened', function() {
var node = element.$$('google-drive-browser');
var attrName = node.getAttribute('attr-for-opened');
assert.typeOf(attrName, 'string');
assert.isFalse(node.hasAttribute(attrName));
});

test('paper-spinner is not in the DOM', function() {
var node = element.$$('paper-spinner');
assert.notOk(node);
});

test('Opens Google Drive picker', function() {
var button = element.$$('[data-action="open-drive-picker"]');
MockInteractions.tap(button);
assert.equal(element.selectedPage, 1, 'selectedPage is 1');
assert.isTrue(element.withDriveList, 'withDriveList is true');
var node = element.$$('google-drive-browser');
var attrName = node.getAttribute('attr-for-opened');
assert.isTrue(node.hasAttribute(attrName), 'Picker is opened');
});

test('Opens data manual entry', function() {
var button = element.$$('[data-action="open-text-entry"]');
MockInteractions.tap(button);
assert.equal(element.selectedPage, 2, 'selectedPage is 2');
});

test('Restores view from the Drive Picket', function() {
element.selectedPage = 1;
element.withDriveList = true;
element.screenBack();
assert.equal(element.selectedPage, 0, 'selectedPage is 0');
assert.isFalse(element.withDriveList, 'withDriveList is false');
});
});
</script>
Expand Down
101 changes: 101 additions & 0 deletions test/data-import-flow-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<script src="test-helper.js"></script>
<link rel="import" href="../import-panel.html">
<link rel="import" href="../../arc-demo-helpers/data-generator.html">
<link rel="import" href="../../arc-data-import/arc-data-import.html">
</head>
<body>

<test-fixture id="basic">
<template>
<import-panel></import-panel>
<arc-data-import></arc-data-import>
</template>
</test-fixture>

<script>
/* global fixture, assert, DataGenerator */
suite('basic', function() {
var importData;
suiteSetup(function() {
var saved = DataGenerator.generateSavedRequestData({
requestsSize: 10,
projectsSize: 1
});
var history = DataGenerator.generateHistoryRequestsData({
requestsSize: 10
});
importData = {
kind: 'ARC#Import',
createdAt: '2017-09-28T19:43:09.491',
version: '9.14.64.305',
requests: saved.requests,
projects: saved.projects,
history: history,
variables: DataGenerator.generateVariablesData(),
'headers-sets': DataGenerator.generateHeadersSetsData(),
cookies: DataGenerator.generateCookiesData(),
'url-history': DataGenerator.generateUrlsData(),
'websocket-url-history': DataGenerator.generateUrlsData()
};
});

var element;
setup(function() {
element = fixture('basic')[0];
element.data = DataGenerator.clone(importData);
element.selectedPage = 3;
});

test('Sends the import-data custom event', function(done) {
element.addEventListener('import-data', function f(e) {
element.removeEventListener('import-data', f);
assert.isTrue(e.cancelable, 'Event is cancelable.');
assert.equal(e.detail.content, importData);
done();
});
element._importData({
detail: importData
});
});

test('Sets the importing flag', function() {
element._importData({
detail: importData
});
assert.isTrue(element.importing, 'importing is set.');
});

test('Clears the state after import', function() {
return element._importData({
detail: importData
})
.then(() => {
assert.isFalse(element.importing, 'importing is set.');
assert.isUndefined(element.data, 'data is set.');
assert.equal(element.selectedPage, 0, 'selected page is set.');
});
});
});
</script>

</body>
</html>
88 changes: 88 additions & 0 deletions test/data-normalize-flow-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<script src="test-helper.js"></script>
<link rel="import" href="../../arc-data-import/arc-data-import.html">
<link rel="import" href="../import-panel.html">
</head>
<body>

<test-fixture id="basic">
<template>
<import-panel></import-panel>
<arc-data-import></arc-data-import>
</template>
</test-fixture>

<script>
/* global fixture, assert, MockInteractions, DataTestHelper */
suite('basic', function() {
var importData;
suiteSetup(function() {
return DataTestHelper.getFile('import-data-test.json')
.then(response => {
importData = response;
});
});

var element;
setup(function() {
element = fixture('basic')[0];
element.selectedPage = 2;
element.$$('#manualInput').value = importData;
});

function normalize() {
var button = element.$$('[data-action="import-text"]');
MockInteractions.tap(button);
}

test('Sends the import-normalize custom event', function(done) {
element.addEventListener('import-normalize', function f(e) {
element.removeEventListener('import-normalize', f);
assert.isTrue(e.cancelable, 'Event is cancelable.');
assert.equal(e.detail.content, importData);
done();
});
normalize();
});

test('_processContent returns a Promise', function() {
return element._processContent(importData)
.then(() => {});
});

test('Opens a table after normalization', function() {
return element._processContent(importData)
.then(() => {
assert.equal(element.selectedPage, 3);
});
});

test('Sets the data after normalization', function() {
return element._processContent(importData)
.then(() => {
assert.typeOf(element.data, 'object');
});
});
});
</script>

</body>
</html>

0 comments on commit cbdb6e9

Please sign in to comment.