From bf5e8c6455d7097f8b79097f30143d376a342c89 Mon Sep 17 00:00:00 2001 From: Ed Brannin Date: Tue, 29 Oct 2019 13:00:29 -0400 Subject: [PATCH] Improve Sortable test coverage; call out a bug; fix others --- src/Util/Sortable.js | 4 ++-- test/SortableTest.js | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/Util/Sortable.js b/src/Util/Sortable.js index 176f90181..6d2805571 100644 --- a/src/Util/Sortable.js +++ b/src/Util/Sortable.js @@ -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() { diff --git a/test/SortableTest.js b/test/SortableTest.js index d43570088..82a51af16 100644 --- a/test/SortableTest.js +++ b/test/SortableTest.js @@ -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); @@ -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); @@ -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"]); +});