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

Conversation

binoculars
Copy link
Member

Ticket

https://openscience.atlassian.net/browse/EOSF-574

Purpose

Adds/updates tests for controllers

Changes

  • Remove unused controllers (and their tests)
  • Refactor to simplify controllers, including:
    • General code cleanup
    • Observers to computed properties
    • Using built-ins for computed properties
  • Add more tests

Note: Holding off on tests for actions with promises in them until we figure out a good way to handle those without concurrency issues

Notes for QA

  • Functionality shouldn't change at all, but please test the content, submit, and edit functionality thoroughly.

Side effects

Copy link
Contributor

@pattisdr pattisdr left a comment

Choose a reason for hiding this comment

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

Nice work @binoculars. These are big contributions to the submit/content controller tests as well as submit controller cleanup. I tried to go over this pretty thoroughly and only found a couple of bugs introduced on the submit controller. Main thing I see for QA is testing the Add Preprints page.


if (this.get('applyLicense')) {
if (node.get('nodeLicense.year') !== this.get('basicsLicense.year') || node.get('nodeLicense.copyrightHolders') !== newCopyrightHolders) {
node.set('nodeLicense', {year: this.get('basicsLicense.year'), copyright_holders: newCopyrightHolders});
if (node.get('nodeLicense.year') !== this.get('basicsLicense.year') || node.get('nodeLicense.copyrightHolders').join() !== copyrightHolders.join()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Getting errors on this line. nodeLicense.copyrightHolders if undefined. Cannot read property 'join' of undefined. Happens if you go back to edit section on Submit form.

Copy link
Contributor

Choose a reason for hiding this comment

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

@binoculars - this is still broken.

Copy link
Member Author

Choose a reason for hiding this comment

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

My apologies. I misunderstood the test case you mentioned.

}),

basicsDOI: Ember.computed.or('model.doi'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 'or' here? Is there something else that gives you a one-liner checking for existence?

Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, when using Ember.computed.alias the validation breaks, but Ember.computed.or works just fine--weird

node.set('title', nodeTitle);
return node.save();
})
//.then(() => this.send(this.get('abandonedPreprint') ? 'resumeAbandonedPreprint' : 'startPreprint'))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is needed. Without it, you cannot initiate a preprint on an existing node with an existing file.


// Cannot be called until a project has been selected!
// Cannot be called until a project has been selected!
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment out of place.

node.set('title', currentTitle);
this.get('toast').error(this.get('i18n').t('submit.could_not_update_title'));
});
// Ember.run(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove if not using.


const tags = this.get('basicsTags');
tags.removeAt(tags.indexOf(tag));
Copy link
Contributor

Choose a reason for hiding this comment

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

Will removeObject work?

_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.

});

// test('existingNodeExistingFile', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

skip instead of commented out test? When I put the first draft of tests in here, I was asked to use skip instead of commenting so they were more visible.

test('error', function(assert) {
// TODO How to properly test this? The error action creates an error
// toast message displaying the error message
// test('changesSaved temporarily changes currentPanelSaveState to true', function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

skip?

this.get('toast').error(this.get('i18n').t('submit.could_not_update_title'));
});
// Ember.run(() => {
return Promise.resolve()
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own understanding, can you explain why you used Promise.resolve() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It just starts a promise chain, because we need it for the return on L520 so that it's a 'thenable'. It could also be written as:

(() => {
    if (currentTitle === nodeTitle) {
        return Promise.resolve();
    }

    node.set('title', nodeTitle);
    return node.save(); // returns a promise
})() // immediately invoked function
    .then( ... )
    .catch( ... )

Once you start the promise chain, you can just use return to go to the next .then without returning a value

@binoculars
Copy link
Member Author

Some of this is friday afternoon madness. Update forthcoming

@pattisdr
Copy link
Contributor

Looks good to me @binoculars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants