Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EOSF-594] Add example controller unit tests and component integration tests #293

Merged
merged 33 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8f10f47
add facotry-guy, mockjax and acceptance test
Feb 21, 2017
7728d4c
Fix module for acceptance, play with content test some more
Feb 27, 2017
06f1d3f
Flesh out content controller tests
Feb 28, 2017
adbdbff
New component tests:
Mar 1, 2017
7313017
Adjust author-link tests
Mar 3, 2017
4f2d582
Merge branch 'develop' of http:/CenterForOpenScience/embe…
Mar 3, 2017
cd2947f
Clean up tests and remove unused code
Mar 10, 2017
227b7ba
Make sure bower has Faker
Mar 14, 2017
2091748
Update yarn with pinned ember-osf commit
hmoco Mar 20, 2017
ddaa0c9
Merge branch 'feature/tests' of http:/CenterForOpenScienc…
Mar 21, 2017
ed8659f
Update packages, add stubbing to requests in acceptance tests
Mar 21, 2017
eea027d
Merge branch 'develop' of http:/CenterForOpenScience/embe…
Mar 21, 2017
0aa4bbd
Merge branch 'feature/tests' of http:/CenterForOpenScienc…
Mar 21, 2017
514e5b6
Remove obsolete tests
Mar 21, 2017
93b096d
Update module-for-acceptance.js
hmoco Mar 22, 2017
41e49eb
skip do nothing test, start discover page setup
Mar 27, 2017
7b2f3b1
unsure on how to ensure data is available fully prior to hitting andThen
Mar 27, 2017
781ed81
Make separates and joins of copyright providers use ', ' rather than ','
Mar 27, 2017
6a20fbd
Play around some more with acceptance/runs
Mar 28, 2017
6bfd5c8
remove unused tests (acceptance) and clean up/separate other tests
Mar 29, 2017
bc75a16
Merge branch 'develop' of http:/CenterForOpenScience/embe…
hmoco Apr 6, 2017
669d71a
Merge branch 'feature/tests' of http:/CenterForOpenScienc…
hmoco Apr 6, 2017
480c3d6
Attempt to recreate yarn file
hmoco Apr 7, 2017
d4e63d3
Attempt to fix lockfile conflicts
hmoco Apr 7, 2017
a399056
Merge branch 'feature/tests' of http:/CenterForOpenScienc…
hmoco Apr 24, 2017
80c272c
Clean up packages, pin ember data facotry guy version
hmoco Apr 24, 2017
bc0e632
Merge branch 'develop' of http:/CenterForOpenScience/embe…
hmoco Apr 26, 2017
c12ce72
Add messages to test failures
hmoco Apr 26, 2017
a751d6e
Make split and joins consistent across copyrightHolders and test for it
hmoco Apr 27, 2017
c6bb595
Distinguish async behavior on discardbasics, test for copyright holde…
hmoco Apr 27, 2017
28208e4
Revert changes made to submit conroller made in c6bb5953137687cd2cd0b…
jamescdavis Apr 28, 2017
ef7d697
Merge branch 'develop' of http:/CenterForOpenScience/embe…
hmoco Apr 28, 2017
842875d
Move filedownloadUrl test to its component
hmoco Apr 28, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions
this.set('basicsLicense', {
licenseType: license || this.get('availableLicenses').toArray()[0],
year: this.get('model.licenseRecord') ? this.get('model.licenseRecord').year : date.getUTCFullYear().toString(),
copyrightHolders: this.get('model.licenseRecord') ? this.get('model.licenseRecord').copyright_holders.join(',') : ''
copyrightHolders: this.get('model.licenseRecord') ? this.get('model.licenseRecord').copyright_holders.join(', ') : ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a test for this.

});
});
},
Expand Down Expand Up @@ -725,7 +725,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions
const currentNodeLicenseType = node.get('license');
const currentNodeLicenseRecord = node.get('nodeLicense');
const copyrightHolders = this.get('basicsLicense.copyrightHolders')
.split(',')
.split(', ')
.map(item => item.trim());

if (this.get('abstractChanged'))
Expand Down
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"toastr": "^2.1.2",
"hint.css": "^2.3.2",
"jquery.tagsinput": "^1.3.6",
"loaders.css": "^0.1.2"
"loaders.css": "^0.1.2",
"jquery-mockjax": "~2.2.1",
"Faker": "~3.0.0"
},
"resolutions": {
"jquery": "~2.2.4"
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
"ember-cli-code-coverage": "0.3.11",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-dropzonejs": "0.7.0",
"ember-cli-fake-server": "0.3.2",
"ember-cli-eslint": "3.0.3",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-inline-content": "0.4.0",
"ember-cli-meta-tags": "3.0.1",
"ember-cli-postcss": "^3.0.1",
"ember-cli-qunit": "^2.0.0",
"ember-cli-qunit": "^3.0.0",
"ember-cli-release": "^0.2.9",
"ember-cli-sass": "5.3.1",
"ember-cli-sri": "^2.1.0",
Expand All @@ -56,7 +57,9 @@
"ember-collection": "1.0.0-alpha.6",
"ember-cp-validations": "^2.9.4",
"ember-data": "^2.7.0",
"ember-data-factory-guy": "2.11.6",
"ember-export-application-global": "^1.0.5",
"ember-faker": "^1.1.1",
"ember-font-awesome": "2.1.1",
"ember-get-config": "0.0.4",
"ember-i18n": "4.3.1",
Expand All @@ -73,6 +76,8 @@
"ember-truth-helpers": "1.2.0",
"ember-welcome-page": "^1.0.1",
"eslint": "^3.18.0",
"faker": "^4.1.0",
"jscs": "^3.0.7",
"liquid-fire": "0.24.1",
"loader.js": "^4.0.1",
"pagination-pager": "2.4.2",
Expand Down
39 changes: 32 additions & 7 deletions tests/helpers/module-for-acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,47 @@ import { module } from 'qunit';
import Ember from 'ember';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import FactoryGuy, { manualSetup } from 'ember-data-factory-guy';
import config from 'ember-get-config';
import FakeServer, { stubRequest } from 'ember-cli-fake-server';

const { RSVP: { Promise } } = Ember;

export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
this.application = startApp();
FakeServer.start();
manualSetup(this.application.__container__);
const url = config.OSF.apiUrl;
const provider = FactoryGuy.build('preprint-provider');

if (options.beforeEach) {
return options.beforeEach.apply(this, arguments);
}
},
stubRequest('get', url + '/v2/users/me', (request) => {
request.unauthorized({});
});
stubRequest('get', url + '/v2/preprint_providers', (request) => {
request.ok({data: [{
attributes: provider.data.attributes,
type: "preprint_providers",
id: "osf"
}]});
});
stubRequest('get', url + '/v2/preprint_providers/osf', (request) => {
request.ok({data: {
attributes: provider.data.attributes,
type: "preprint_providers",
id: "osf"
}});
});

if (options.beforeEach) {
return options.beforeEach.apply(this, arguments);
}
},
afterEach() {
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return Promise.resolve(afterEach).then(() => destroyApp(this.application));
FakeServer.stop();
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return Promise.resolve(afterEach).then(() => destroyApp(this.application));
}
});
}
37 changes: 37 additions & 0 deletions tests/integration/components/author-link-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import FactoryGuy, { manualSetup } from 'ember-data-factory-guy';

moduleForComponent('author-link', 'Integration | Component | author link', {
integration: true,
beforeEach: function() {
manualSetup(this.container);
}
});

test('renders non-links', function(assert) {
let contributorModel = FactoryGuy.make('contributor');
// Problem here is that author link expects a share search-result contributor,
// not a store instance of a contributor and its user(s).
let contributor = {users: {identifiers: []}};
contributor.users.name = contributorModel.get('users.fullName');
contributor = Ember.merge(contributor, contributorModel.serialize().data.attributes);
this.set('contributor', contributor);
this.render(hbs`{{author-link contributor=contributor}}`);
assert.ok(!this.$('a').length, 'Found a link when user has no identifiers');
assert.equal(this.$().text().trim(), contributorModel.get('users.fullName'), 'Text of author-link not equal to fullName of user');
});

test('renders links', function(assert) {
let contributorModel = FactoryGuy.make('contributor');
let contributor = {users: {identifiers: []}};
contributor.users.name = contributorModel.get('users.fullName');
contributor = Ember.merge(contributor, contributorModel.serialize().data.attributes);
contributor.users.identifiers.push('https://staging.osf.io/cool');
this.set('contributor', contributor);

this.render(hbs`{{author-link contributor=contributor}}`);
assert.ok(this.$('a').length, 'Expected a link in author-link as user has an identifier');
assert.equal(this.$().text().trim(), contributorModel.get('users.fullName'), 'Text of author-link not equal to fullName of user');
});
81 changes: 40 additions & 41 deletions tests/integration/components/supplementary-file-browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,51 @@ import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';

moduleForComponent('supplementary-file-browser', 'Integration | Component | supplementary file browser', {
integration: true
integration: true,
beforeEach: function() {
let providerFiles = () => Ember.RSVP.resolve(Ember.ArrayProxy.create({
content: Ember.A(),
meta: {
pagination: {
total: 1
}
}}));
let providersQuery = Ember.RSVP.resolve(Ember.A([{
name: 'osfstorage',
query: providerFiles
}]));

let node = Ember.Object.create({
dateModified: '10-11-2016',
title:'My Preprint Title',
files: providersQuery
});

let file = Ember.Object.create({

});
let preprint = Ember.Object.create({
primaryFile: file,
node: node,
provider: 'osf',
files: providersQuery
});

this.set('preprint', preprint);
this.set('node', node);
}
});

test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

// Construct a fake preprint object to satisfy browser needs
let providerFiles = () => Ember.RSVP.resolve(Ember.ArrayProxy.create({
content: Ember.A(),
meta: {
pagination: {
total: 1
}
}}));
let providersQuery = Ember.RSVP.resolve(Ember.A([{
name: 'osfstorage',
query: providerFiles
}]));

let node = Ember.Object.create({
dateModified: '10-11-2016',
title:'My Preprint Title',
files: providersQuery
});

let file = Ember.Object.create({

});
let preprint = Ember.Object.create({
primaryFile: file,
node: node,
provider: 'osf',
files: providersQuery
});



this.set('preprint', preprint);
this.set('node', node);

this.render(hbs`{{supplementary-file-browser node=node preprint=preprint}}`);

assert.equal(this.$().text().trim().replace(/\s/g, ""), 'DownloadpreprintVersion:');

// this.on('changeFile', function() {});
});

// {{supplementary-file-browser preprint=model projectURL=model.links.html chooseFile=(action 'chooseFile')}}
test('fileDownloadURL computed property', function (assert) {
this.render(hbs`{{supplementary-file-browser node=node preprint=preprint}}`);

let url = this.$('.supplemental-downloads > a').attr('href')
assert.ok(url);
assert.ok(url.indexOf(this.get('primaryFile.guid')) !== -1, 'Url does not have file\'s guid in it');
});
53 changes: 1 addition & 52 deletions tests/unit/controllers/content/index-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {moduleFor, test} from 'ember-qunit';
import Ember from 'ember';
import { moduleFor, test } from 'ember-qunit';
import config from 'ember-get-config';

moduleFor('controller:content/index', 'Unit | Controller | content/index', {
Expand Down Expand Up @@ -268,57 +268,6 @@ test('fullLicenseText computed property', function (assert) {
});
});

test('fileDownloadURL computed property', function (assert) {
// Note: testing of the file download url string value should be done in the file-download-path util test
this.inject.service('store');

const store = this.store;
const ctrl = this.subject();

// Without a node should be null
Ember.run(() => {
const primaryFile = store.createRecord('file', {
guid: 'abc12',
path: '/test_path'
});

const model = store.createRecord('preprint', {
primaryFile
});

ctrl.setProperties({
model
});

ctrl.get('fileDownloadURL')
.then(url => assert.notOk(url));
});

// With file and node
Ember.run(() => {
const primaryFile = store.createRecord('file', {
guid: 'abc12',
path: '/test_path'
});

const model = store.createRecord('preprint', {
primaryFile
});

const node = store.createRecord('node', {
id: 'def34'
});

ctrl.setProperties({
model,
node
});

ctrl.get('fileDownloadURL')
.then(url => assert.ok(url));
});
});

test('hasShortenedDescription computed property', function (assert) {
this.inject.service('store');

Expand Down
39 changes: 39 additions & 0 deletions tests/unit/controllers/submit-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { moduleFor, test, skip } from 'ember-qunit';
import Ember from 'ember';
import wait from 'ember-test-helpers/wait';

const panelNames = [
'Discipline',
Expand Down Expand Up @@ -516,6 +517,44 @@ test('licenseChanged with no model set', function(assert) {
});
});

test('basicsLicense with multiple copyrightHolders', function(assert) {
const ctrl = this.subject();
const model = {
licenseRecord: {
copyright_holders: ['Frank', 'Everest']
}
};
Ember.run(() => {
ctrl.set('model', model);
assert.equal(ctrl.get('basicsLicense').copyrightHolders, 'Frank, Everest');
});
});

test('discardBasics properly joins copyrightHolders', function(assert) {
assert.expect(1);
const ctrl = this.subject();
this.inject.service('store');
const store = this.store;
Ember.run(() => {
const node = store.createRecord('node', {
tags: ['tags']
});
const model = store.createRecord('preprint', {
licenseRecord: {
copyright_holders: ['Frank', 'Everest']
}
});
const license = store.createRecord('license', {
'name': 'No license'
});
model.set('license', license);
ctrl.set('node', node);
ctrl.set('model', model);
ctrl.send('discardBasics');
return wait().then(() => assert.equal(ctrl.get('basicsLicense').copyrightHolders, 'Frank, Everest'));
});
})

test('basicsChanged computed property', function(assert) {
const ctrl = this.subject();
ctrl.set('tagsChanged', false);
Expand Down
Loading