-
Notifications
You must be signed in to change notification settings - Fork 39
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
Changes from 26 commits
8f10f47
7728d4c
06f1d3f
adbdbff
7313017
4f2d582
cd2947f
227b7ba
2091748
ddaa0c9
ed8659f
eea027d
0aa4bbd
514e5b6
93b096d
41e49eb
7b2f3b1
781ed81
6a20fbd
6bfd5c8
bc75a16
669d71a
480c3d6
d4e63d3
a399056
80c272c
bc0e632
c12ce72
a751d6e
c6bb595
28208e4
ef7d697
842875d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,7 +304,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions | |
let license = this.get('model.license'); | ||
return { | ||
year: record ? record.year : null, | ||
copyrightHolders: record && record.copyright_holders ? record.copyright_holders.join(',') : null, | ||
copyrightHolders: record && record.copyright_holders ? record.copyright_holders.join(', ') : null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SAA about mentioning this in Side Effects. |
||
licenseType: license || null | ||
}; | ||
}), | ||
|
@@ -313,7 +313,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions | |
if (this.get('model.licenseRecord') || this.get('model.license.content')) { | ||
changed = changed || (this.get('model.license.name') !== this.get('basicsLicense.licenseType.name')); | ||
changed = changed || (this.get('model.licenseRecord').year !== this.get('basicsLicense.year')); | ||
changed = changed || ((this.get('model.licenseRecord.copyright_holders.length') ? this.get('model.licenseRecord.copyright_holders').join(',') : '') !== this.get('basicsLicense.copyrightHolders')); | ||
changed = changed || ((this.get('model.licenseRecord.copyright_holders.length') ? this.get('model.licenseRecord.copyright_holders').join(', ') : '') !== this.get('basicsLicense.copyrightHolders')); | ||
} else { | ||
changed = changed || ((this.get('availableLicenses').toArray().length ? this.get('availableLicenses').toArray()[0].get('name') : null) !== this.get('basicsLicense.licenseType.name')); | ||
let date = new Date(); | ||
|
@@ -675,7 +675,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(', ') : '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to add a test for this. |
||
}); | ||
}); | ||
}, | ||
|
@@ -717,7 +717,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions | |
|
||
let newCopyrightHolders = []; | ||
if (this.get('basicsLicense.copyrightHolders') && this.get('basicsLicense.copyrightHolders').length) { | ||
newCopyrightHolders = this.get('basicsLicense.copyrightHolders').slice().split(','); | ||
newCopyrightHolders = this.get('basicsLicense.copyrightHolders').slice().split(', '); | ||
} | ||
|
||
if (this.get('abstractChanged')) node.set('description', this.get('basicsAbstract')); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General comment for this PR: is this necessary? From docs:
See also the factory guy setup for comparison in case it sparks some ideas: |
||
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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks helpful! I ran the tests in chrome with the network inspector open, and noticed that the page still sends a request to google analytics every time tests run. This may indicate one more thing that needs stubbing. Thoughts? |
||
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)); | ||
} | ||
}); | ||
} |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
assert.equal(this.$().text().trim(), contributorModel.get('users.fullName')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
}); | ||
|
||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that the component is being rendered twice. Just to ensure tests are isolated, might I suggest splitting this into two tests? (the common setup parts could be moved into a beforeEach of course) |
||
this.set('contributor', contributor); | ||
|
||
this.render(hbs`{{author-link contributor=contributor}}`); | ||
assert.ok(this.$('a').length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
assert.equal(this.$().text().trim(), contributorModel.get('users.fullName')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,105 @@ | ||
import Ember from 'ember'; | ||
import { moduleFor, test } from 'ember-qunit'; | ||
import FactoryGuy, { manualSetup } from 'ember-data-factory-guy'; | ||
|
||
moduleFor('controller:content/index', 'Unit | Controller | content/index', { | ||
// Specify the other units that are required for this test. | ||
needs: ['service:metrics', 'service:theme'] | ||
moduleFor('controller:content/index', 'Unit | Controller | content', { | ||
needs: ['service:metrics', 'service:theme', 'model:file', 'model:preprint', | ||
'model:preprint-provider', 'model:node', 'model:license', | ||
'model:user', 'model:citation', 'model:draft-registration', | ||
'model:contributor', 'model:comment', 'model:institution', | ||
'model:registration', 'model:file-provider', 'model:log', | ||
'model:node-link', 'model:wiki'], | ||
beforeEach: function() { | ||
manualSetup(this.container); | ||
} | ||
}); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let controller = this.subject(); | ||
assert.ok(controller); | ||
let controller = this.subject(); | ||
assert.ok(controller); | ||
}); | ||
|
||
test('fullLicenseText computed property with multiple copyright holders and year', function(assert) { | ||
let ctrl = this.subject(); | ||
let preprint = FactoryGuy.make('preprint'); | ||
let license = preprint.get('license'); | ||
Ember.run(() => { | ||
ctrl.set('model', preprint); | ||
license.set('text', 'On {{year}}, for {{copyrightHolders}}'); | ||
preprint.set('licenseRecord', { | ||
year: '2001', | ||
copyright_holders: ['Henrique', 'Someone Else'] | ||
}); | ||
assert.equal(ctrl.get('fullLicenseText'), 'On 2001, for Henrique, Someone Else'); | ||
}); | ||
}); | ||
|
||
test('fullLicenseText computed property with no copyright holders or year', function(assert) { | ||
let ctrl = this.subject(); | ||
let preprint = FactoryGuy.make('preprint'); | ||
let license = preprint.get('license'); | ||
Ember.run(() => { | ||
ctrl.set('model', preprint); | ||
license.set('text', 'On {{year}}, for {{copyrightHolders}}'); | ||
preprint.set('licenseRecord', { | ||
year: '', | ||
copyright_holders: [] | ||
}); | ||
|
||
assert.equal(ctrl.get('fullLicenseText'), 'On , for '); | ||
}); | ||
}); | ||
test('fullLicenseText computed property with {{}} for copyrightHolders', function(assert) { | ||
let ctrl = this.subject(); | ||
let preprint = FactoryGuy.make('preprint'); | ||
let license = preprint.get('license'); | ||
Ember.run(() => { | ||
ctrl.set('model', preprint); | ||
license.set('text', 'On {{year}}, for {{copyrightHolders}}'); | ||
preprint.set('licenseRecord', { | ||
year: '{{year}}', | ||
copyright_holders: ['{{copyrightHolders}}'] | ||
}); | ||
|
||
assert.equal(ctrl.get('fullLicenseText'), 'On {{year}}, for {{copyrightHolders}}'); | ||
}); | ||
}); | ||
|
||
test('useShortenedDescription computed property', function(assert) { | ||
let ctrl = this.subject(); | ||
let node = FactoryGuy.make('node'); | ||
Ember.run(() => { | ||
ctrl.set('node', node); | ||
|
||
node.set('description', 'string'.repeat(100).slice(0, 351)); | ||
assert.ok(ctrl.get('useShortenedDescription')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
|
||
node.set('description', 'string'.repeat(100).slice(0, 350)); | ||
assert.ok(!ctrl.get('useShortenedDescription')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
|
||
node.set('description', 'string'.repeat(100).slice(0, 349)); | ||
assert.ok(!ctrl.get('useShortenedDescription')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
}); | ||
}); | ||
|
||
test('description computed property', function(assert) { | ||
let ctrl = this.subject(); | ||
let node = FactoryGuy.make('node'); | ||
Ember.run(() => { | ||
ctrl.set('node', node); | ||
ctrl.set('expandedAbstract', false); | ||
|
||
//Test cut at 350 characters | ||
let description = 'string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string string str'; | ||
let notExpanded = description.slice(0, 350); | ||
node.set('description', description); | ||
assert.equal(ctrl.get('description'), notExpanded.trim()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
|
||
//Test cut at less than 350 characters to not cut in middle of word | ||
description = 'string stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring'; | ||
notExpanded = 'string '; | ||
node.set('description', description); | ||
assert.equal(ctrl.get('description'), notExpanded.trim()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add message? |
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this change is minor, it'd be good to mention it in Side Effects just to bring it to attention of QA and others.