Skip to content

Commit

Permalink
Merge pull request #747 from edbrannin/feature/test-coverage-sortable
Browse files Browse the repository at this point in the history
Improve Sortable test coverage; call out a bug; fix others
  • Loading branch information
zachleat authored Nov 29, 2019
2 parents adac1bb + bf5e8c6 commit a4afbf7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Util/Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Sortable {
}

sortAscending() {
return this.sort(this.getSortFunctionAscending);
return this.sort(this.getSortFunctionAscending());
}

sortDescending() {
return this.sort(this.getSortFunctionDescending);
return this.sort(this.getSortFunctionDescending());
}

isSortAscending() {
Expand Down
49 changes: 49 additions & 0 deletions test/SortableTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,54 @@ test("get Sort Function", t => {

test("Alphabetic Ascending", t => {
let s = new Sortable();
t.false(s.isSortNumeric());
t.true(s.isSortAscending());

s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sort(), ["a", "m", "z"]);
});

test.skip("Alphabetic Ascending (shortcut)", t => {
/* FIXME THIS WILL NOT WORK because s.sortAscending() has been replaced by the boolean sortAscending.
*
* If backwards compatibility were not an issue, I'd recommend renaming the boolean properties
* to isSort(Ascending|Numeric) and renaming the getters & Setters to (get|set)IsSort(Ascending|Numeric)
*/
let s = new Sortable();
s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sortAscending(), ["a", "m", "z"]);
});

test("Alphabetic Descending", t => {
let s = new Sortable();
s.setSortDescending();
t.false(s.isSortNumeric());
t.false(s.isSortAscending());

s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sort(), ["z", "m", "a"]);
});

test("Alphabetic Descending (shortcut)", t => {
let s = new Sortable();
s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sortDescending(), ["z", "m", "a"]);
});

test("Numeric Ascending", t => {
let s = new Sortable();
s.setSortNumeric(true);
t.true(s.isSortNumeric());
t.true(s.isSortAscending());

s.add(1);
s.add(4);
s.add(2);
Expand All @@ -37,6 +67,9 @@ test("Numeric Descending", t => {
let s = new Sortable();
s.setSortNumeric(true);
s.setSortDescending();
t.true(s.isSortNumeric());
t.false(s.isSortAscending());

s.add(1);
s.add(4);
s.add(2);
Expand Down Expand Up @@ -149,3 +182,19 @@ test("Alphabetic Descending (str sort arg)", t => {
s.add("m");
t.deepEqual(s.sort("descending"), ["z", "m", "a"]);
});

test("Alphabetic Ascending (short str sort arg)", t => {
let s = new Sortable();
s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sort("A-Z"), ["a", "m", "z"]);
});

test("Alphabetic Descending (short str sort arg)", t => {
let s = new Sortable();
s.add("a");
s.add("z");
s.add("m");
t.deepEqual(s.sort("Z-A"), ["z", "m", "a"]);
});

0 comments on commit a4afbf7

Please sign in to comment.