From bbe0a2d99377406a229b9d74f3ad6324bc80b1c9 Mon Sep 17 00:00:00 2001 From: Gabriel Grant Date: Fri, 24 Feb 2017 20:13:47 -0800 Subject: [PATCH] add additional tests for expected array.sort behavior --- tests/integration/array/sort-test.js | 52 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/integration/array/sort-test.js b/tests/integration/array/sort-test.js index fd57bfb..7bff4fe 100644 --- a/tests/integration/array/sort-test.js +++ b/tests/integration/array/sort-test.js @@ -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'; @@ -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'), @@ -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'), @@ -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({ @@ -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] + }); +});