Skip to content

Commit

Permalink
Sort size calculations by addon name then most recent
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelyghost committed Nov 22, 2020
1 parent 76ea026 commit 48b96ce
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
22 changes: 18 additions & 4 deletions app/controllers/admin/size-calculation-results/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import classic from 'ember-classic-decorator';
import { sort } from '@ember/object/computed';
import { computed } from '@ember/object';
import Controller from '@ember/controller';

@classic
export default class SizeCalculationResultsIndexController extends Controller {
queryParams = ['date'];
sizeCalculationResultSorting = ['testsRunAt:desc'];

@sort('model', 'sizeCalculationResultSorting')
sortedSizeCalculationResults;
@computed('model')
get sortedSizeCalculationResults() {
return this.model.toArray().sort(sortByAddonNameAndMostRecent);
}
}

function sortByAddonNameAndMostRecent(a, b) {
let addonName1 = a.get('version.addonName');
let addonName2 = b.get('version.addonName');

if (addonName1 < addonName2) {
return -1;
}
if (addonName1 > addonName2) {
return 1;
}
return b.get('createdAt') - a.get('createdAt');
}
49 changes: 31 additions & 18 deletions tests/acceptance/size-calculation-results-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,43 @@ module('Acceptance | size calculation results', function(hooks) {
assert.dom(results[2]).hasText('2016-08-07 16:30', 'displays date/time');
});

test('sorts results by run date', async function(assert) {
let addon = server.create('addon');
let addonVersion = server.create('version', { addonId: addon.id });
let middleTestResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 12:00:00').utc()
});
let earliestTestResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 00:00:01').utc()
});
let latestTestResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 23:59:59').utc()
});
addonVersion.update({
sizeCalculationResultIds: [middleTestResult.id, earliestTestResult.id, latestTestResult.id]
test('sorts results by addon name then date', async function(assert) {
let addon1 = server.create('addon', { name: 'foo' });
let addon2 = server.create('addon', { name: 'bat' });
let addon3 = server.create('addon', { name: 'ember-foo' });
let addonVersion1 = server.create('version', { addonId: addon1.id, addonName: 'foo' });
let addonVersion2 = server.create('version', { addonId: addon2.id, addonName: 'bat' });
let addonVersion3 = server.create('version', { addonId: addon3.id, addonName: 'ember-foo' });
let addon1Result = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 12:00:00').utc(),
version: addonVersion1,
});
let addon2Result = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 12:00:00').utc(),
version: addonVersion2,
});
let addon3MiddleResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 12:00:00').utc(),
version: addonVersion3,
});
let addon3EarliestResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 00:00:01').utc(),
version: addonVersion3,
});
let addon3LatestResult = server.create('sizeCalculationResult', {
createdAt: moment('2016-11-19 23:59:59').utc(),
version: addonVersion3,
});

await login();
await visit('/admin/size-calculation-results');

assert.dom('.test-size-calculation-result').hasAttribute('data-sizeCalculationResultId', `${latestTestResult.id}`);

let results = findAll('.test-size-calculation-result');
assert.dom(results[1]).hasAttribute('data-sizeCalculationResultId', `${middleTestResult.id}`);
assert.dom(results[2]).hasAttribute('data-sizeCalculationResultId', `${earliestTestResult.id}`);
assert.dom(results[0]).hasAttribute('data-sizeCalculationResultId', `${addon2Result.id}`, 'Addon with first name comes first');
assert.dom(results[1]).hasAttribute('data-sizeCalculationResultId', `${addon3LatestResult.id}`, 'Addon with middle name and latest date');
assert.dom(results[2]).hasAttribute('data-sizeCalculationResultId', `${addon3MiddleResult.id}`, 'Addon with middle name and middle date');
assert.dom(results[3]).hasAttribute('data-sizeCalculationResultId', `${addon3EarliestResult.id}`, 'Addon with middle name and earliest date');
assert.dom(results[4]).hasAttribute('data-sizeCalculationResultId', `${addon1Result.id}`, 'Addon with latest name comes last');
});

test('displays appropriate status based on result', async function(assert) {
Expand Down

0 comments on commit 48b96ce

Please sign in to comment.