Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Sortable test coverage; call out a bug; fix others #747

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]);
});