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-574] controller unit tests #319

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
52 changes: 26 additions & 26 deletions app/controllers/content/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import DS from 'ember-data';
import loadAll from 'ember-osf/utils/load-relationship';
import config from 'ember-get-config';
import Analytics from '../../mixins/analytics';
Expand Down Expand Up @@ -53,9 +54,7 @@ function queryStringify(queryParams) {
export default Ember.Controller.extend(Analytics, {
theme: Ember.inject.service(),
fullScreenMFR: false,
expandedAuthors: true,
showLicenseText: false,
fileDownloadURL: '',
expandedAbstract: navigator.userAgent.includes('Prerender'),
queryParams: {
chosenFile: 'file'
Expand Down Expand Up @@ -114,37 +113,40 @@ export default Ember.Controller.extend(Analytics, {
return this.get('model.subjects').reduce((acc, val) => acc.concat(val), []).uniqBy('id');
}),

hasTag: Ember.computed('node.tags', function() {
return (this.get('node.tags') || []).length;
}),
hasTag: Ember.computed.bool('node.tags.length'),

getAuthors: Ember.observer('node', function() {
authors: Ember.computed('node', function() {
// Cannot be called until node has loaded!
const node = this.get('node');
if (!node) return [];

if (!node)
return [];

const contributors = Ember.A();
loadAll(node, 'contributors', contributors).then(() =>
this.set('authors', contributors)
);

return DS.PromiseArray.create({
promise: loadAll(node, 'contributors', contributors)
.then(() => contributors)
});
}),

doiUrl: Ember.computed('model.doi', function() {
return `https://dx.doi.org/${this.get('model.doi')}`;
}),

fullLicenseText: Ember.computed('model.license', function() {
let text = this.get('model.license.text');
if (text) {
text = text.replace(/({{year}})/g, this.get('model.licenseRecord').year || '');
text = text.replace(/({{copyrightHolders}})/g, this.get('model.licenseRecord').copyright_holders ? this.get('model.licenseRecord').copyright_holders.join(',') : false || '');
}
return text;
fullLicenseText: Ember.computed('model.license.text', 'model.licenseRecord', function() {
const text = this.get('model.license.text') || '';
const {year = '', copyright_holders = []} = this.get('model.licenseRecord');

return text
.replace(/({{year}})/g, year)
.replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
}),

_fileDownloadURL: Ember.observer('model.primaryFile', function() {
this.get('model.primaryFile').then(file => {
this.set('fileDownloadURL', fileDownloadPath(file, this.get('node')));
fileDownloadURL: Ember.computed('model.primaryFile', 'node', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job getting rid of that observer.

return DS.PromiseObject.create({
promise: this.get('model.primaryFile')
.then(file => fileDownloadPath(file, this.get('node')))
});
}),

Expand Down Expand Up @@ -187,17 +189,15 @@ export default Ember.Controller.extend(Analytics, {
label: `Preprints - Content - MFR ${beforeState}`
});
},
// Unused
expandAuthors() {
this.toggleProperty('expandedAuthors');
},
expandAbstract() {
this.toggleProperty('expandedAbstract');
},
// Metrics are handled in the component
chooseFile(fileItem) {
this.set('chosenFile', fileItem.get('id'));
this.set('activeFile', fileItem);
this.setProperties({
chosenFile: fileItem.get('id'),
activeFile: fileItem
});
},
shareLink(href, category, action, label) {
const metrics = Ember.get(this, 'metrics');
Expand Down
14 changes: 0 additions & 14 deletions app/controllers/forbidden.js

This file was deleted.

14 changes: 0 additions & 14 deletions app/controllers/page-not-found.js

This file was deleted.

13 changes: 0 additions & 13 deletions app/controllers/provider.js

This file was deleted.

14 changes: 0 additions & 14 deletions app/controllers/resource-deleted.js

This file was deleted.

Loading