Skip to content

Commit

Permalink
add additional tests for expected array.sort behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielgrant authored and Kelly Selden committed Feb 26, 2017
1 parent afef17c commit bbe0a2d
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions tests/integration/array/sort-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sort } from 'ember-awesome-macros/array';
import { raw } from 'ember-awesome-macros';
import { A as emberA } from 'ember-array/utils';
import { module, test } from 'qunit';
import sinon from 'sinon';
Expand All @@ -14,7 +15,7 @@ test('it returns undefined if array undefined', function(assert) {
});
});

test('it calls sort on array without a parameter', function(assert) {
test('it returns a sorted array without a parameter', function(assert) {
compute({
assert,
computed: sort('array'),
Expand All @@ -25,7 +26,7 @@ test('it calls sort on array without a parameter', function(assert) {
});
});

test('it calls sort on array with an array parameter', function(assert) {
test('it returns a sorted array with an array parameter', function(assert) {
compute({
assert,
computed: sort('array', 'sortDefinition'),
Expand Down Expand Up @@ -58,7 +59,18 @@ test('it calls sort on array with an array parameter', function(assert) {
});
});

test('it calls sort on array with function parameter', function(assert) {
test('it returns a sorted array with a direct array parameter', function(assert) {
compute({
assert,
computed: sort('array', ['prop:desc']),
properties: {
array: [{prop: 1}, {prop: 3}, {prop: 2}]
},
deepEqual: [{prop: 3}, {prop: 2}, {prop: 1}]
});
});

test('it returns a sorted array with function parameter', function(assert) {
let sortDefinition = sinon.stub().returns(1);

compute({
Expand Down Expand Up @@ -144,3 +156,37 @@ test('the callback is passed the correct args', function(assert) {
}
]]);
});

test('it does not sort the source array for default sorts', function(assert) {
let array = [1, 3, 2];
compute({
assert,
computed: sort('array'),
properties: {
array
},
deepEqual: [1, 2, 3]
});
assert.deepEqual(array, [1, 3, 2]);
});

test('it does not sort the source array for property sorts', function(assert) {
let array = [{prop: 1}, {prop: 3}, {prop: 2}];
compute({
assert,
computed: sort('array', ['prop:desc']),
properties: {
array
},
deepEqual: [{prop: 3}, {prop: 2}, {prop: 1}]
});
assert.deepEqual(array, [{prop: 1}, {prop: 3}, {prop: 2}]);
});

test('composable: it returns a sorted array', function(assert) {
compute({
assert,
computed: sort(raw([1, 3, 2])),
deepEqual: [1, 2, 3]
});
});

0 comments on commit bbe0a2d

Please sign in to comment.