-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import moment from 'moment'; | ||
|
||
|
||
export default function latestAction(actions) { | ||
if (!actions.length) { | ||
export default function latestAction(submissionActions) { | ||
if (!submissionActions.get('length')) { | ||
return null; | ||
} | ||
// on create, Ember puts the new object at the end of the array | ||
// https://stackoverflow.com/questions/15210249/ember-data-insert-new-item-at-beginning-of-array-instead-of-at-the-end | ||
const first = actions.get('firstObject'); | ||
const last = actions.get('lastObject'); | ||
const first = submissionActions.get('firstObject'); | ||
const last = submissionActions.get('lastObject'); | ||
return moment(first.get('dateModified')) > moment(last.get('dateModified')) ? first : last; | ||
} |
90 changes: 90 additions & 0 deletions
90
tests/integration/components/moderation-list-row/component-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import EmberObject from '@ember/object'; | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('moderation-list-row', 'Integration | Component | moderation-list-row', { | ||
integration: true, | ||
}); | ||
|
||
|
||
test('it renders moderation-list-row accepted with actions', function(assert) { | ||
this.set('submission', { | ||
dateLastTransitioned: '2017-10-27T19:14:27.816946Z', | ||
actions: [ | ||
EmberObject.create({ | ||
fromState: 'pending', toState: 'accepted', dateModified: '2017-10-28T14:57:35.949534Z', creator: { fullName: 'Kung-fu Panda' }, | ||
}), | ||
EmberObject.create({ | ||
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Viper' }, | ||
}), | ||
], | ||
reviewsState: 'accepted', | ||
node: { contributors: ['Viper', 'Oogway'] }, | ||
}); | ||
this.render(hbs`{{moderation-list-row submission=submission}}`); | ||
assert.ok(this.$('[data-status=accepted]').length); | ||
assert.notOk(this.$('[data-status=pending]').length); | ||
assert.notOk(this.$('[data-status=rejected]').length); | ||
|
||
assert.equal(this.$('[data-status=accepted]').text().trim(), 'accepted on October 27, 2017 by Kung-fu Panda'); | ||
}); | ||
|
||
test('it renders moderation-list-row accepted without actions', function(assert) { | ||
this.set('submission', { | ||
dateLastTransitioned: '2017-10-27T19:14:27.816946Z', | ||
actions: [], | ||
reviewsState: 'accepted', | ||
node: { contributors: ['Tigerss', 'Crane'] }, | ||
}); | ||
this.render(hbs`{{moderation-list-row submission=submission}}`); | ||
assert.equal(this.$('[data-status=accepted]').text().trim(), 'accepted automatically on October 27, 2017'); | ||
}); | ||
|
||
test('it renders moderation-list-row rejected with actions', function(assert) { | ||
this.set('submission', { | ||
dateLastTransitioned: '2017-10-27T19:14:27.816946Z', | ||
actions: [ | ||
EmberObject.create({ | ||
fromState: 'pending', toState: 'rejected', dateModified: '2017-10-28T14:57:35.949534Z', creator: { fullName: 'Master Shifu' }, | ||
}), | ||
EmberObject.create({ | ||
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' }, | ||
}), | ||
], | ||
reviewsState: 'rejected', | ||
node: { contributors: ['Mr. Ping', 'Mantis'] }, | ||
}); | ||
this.render(hbs`{{moderation-list-row submission=submission}}`); | ||
assert.equal(this.$('[data-status=rejected]').text().trim(), 'rejected on October 27, 2017 by Master Shifu'); | ||
}); | ||
|
||
test('it renders moderation-list-row pending with actions', function(assert) { | ||
this.set('submission', { | ||
dateLastTransitioned: '2017-10-27T19:14:27.816946Z', | ||
actions: [ | ||
EmberObject.create({ | ||
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' }, | ||
}), | ||
], | ||
reviewsState: 'pending', | ||
node: { contributors: [{ users: { fullName: 'Mr. Ping' } }, { users: { fullName: 'Mantis' } }] }, | ||
}); | ||
this.render(hbs`{{moderation-list-row submission=submission}}`); | ||
assert.equal(this.$('[data-status=pending]').text().replace(/\n/g, ' ').trim(), 'submitted on October 27, 2017 by Mr. Ping Mantis'); | ||
}); | ||
|
||
test('it renders moderation-list-row pending with actions and more than three contributors', function(assert) { | ||
this.set('submission', { | ||
dateLastTransitioned: '2017-10-27T19:14:27.816946Z', | ||
actions: [ | ||
EmberObject.create({ | ||
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' }, | ||
}), | ||
], | ||
reviewsState: 'pending', | ||
node: { contributors: [{ users: { fullName: 'Mr. Ping' } }, { users: { fullName: 'Mantis' } }, { users: { fullName: 'Crane' } }, { users: { fullName: 'Tai Lung' } }] }, | ||
}); | ||
this.set('submission.node.contributors.content', { meta: { pagination: { total: this.get('submission.node.contributors.length') } } }); | ||
this.render(hbs`{{moderation-list-row submission=submission}}`); | ||
assert.equal(this.$('[data-status=pending]').text().replace(/\s+/g, ' ').trim(), 'submitted on October 27, 2017 by Mr. Ping Mantis Crane + 1'); | ||
}); |
Oops, something went wrong.