-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-table): sortable columns for userlist
- Loading branch information
1 parent
136b9b9
commit 70fa1a9
Showing
9 changed files
with
177 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<thead> | ||
<tr> | ||
{{yield}} | ||
{{yield (hash sorthead=(component "data-table/head/sortable-th" update=@update sortedBy=@sortedBy))}} | ||
</tr> | ||
</thead> | ||
</thead> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<th> | ||
<span | ||
data-test-sortable-th={{@sort}} | ||
class="sortable-th" | ||
role="button" | ||
{{on "click" (fn @update @sort)}} | ||
> | ||
{{yield}} | ||
{{#if (eq @sortedBy @sort)}} | ||
<UkIcon @icon="chevron-down"/> | ||
{{else if (eq @sortedBy (concat "-" @sort))}} | ||
<UkIcon @icon="chevron-up"/> | ||
{{/if}} | ||
</span> | ||
</th> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-emeis/components/data-table/head/sortable-th"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/integration/components/data-table/head/sortable-th-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { render, click } from "@ember/test-helpers"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { module, test } from "qunit"; | ||
|
||
module( | ||
"Integration | Component | data-table/head/sortable-th", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(function (assert) { | ||
this.set("sort", "last_name"); | ||
this.set("update", (sort) => { | ||
this.set("sort", sort); | ||
assert.step("update"); | ||
}); | ||
}); | ||
|
||
test("it renders", async function (assert) { | ||
await render(hbs` | ||
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |head|> | ||
<head.sorthead @sort={{this.sort}}> | ||
test | ||
</head.sorthead> | ||
</DataTable::Head> | ||
`); | ||
|
||
assert.dom(this.element).hasText("test"); | ||
assert.dom("span[icon=chevron-down]").exists(); | ||
}); | ||
|
||
test("it renders as block", async function (assert) { | ||
await render(hbs` | ||
<DataTable::Head::SortableTh @update={{this.update}}> | ||
template block text | ||
</DataTable::Head::SortableTh> | ||
`); | ||
|
||
assert.dom(this.element).hasText("template block text"); | ||
}); | ||
|
||
test("it toggles sort state", async function (assert) { | ||
await render(hbs` | ||
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |head|> | ||
<head.sorthead @sort={{"last_name"}}> | ||
one | ||
</head.sorthead> | ||
<head.sorthead @sort={{"first_name"}}> | ||
two | ||
</head.sorthead> | ||
</DataTable::Head> | ||
`); | ||
|
||
assert.dom("[data-test-sortable-th=last_name]").hasText("one"); | ||
assert.dom("[data-test-sortable-th=first_name]").hasText("two"); | ||
assert | ||
.dom("[data-test-sortable-th=last_name] span[icon=chevron-down]") | ||
.exists(); | ||
|
||
this.set("sort", "first_name"); | ||
|
||
assert | ||
.dom("[data-test-sortable-th=last_name] span[icon=chevron-down]") | ||
.doesNotExist(); | ||
assert | ||
.dom("[data-test-sortable-th=first_name] span[icon=chevron-down]") | ||
.exists(); | ||
|
||
await click("[data-test-sortable-th=last_name]"); | ||
|
||
assert.verifySteps(["update"]); | ||
|
||
assert | ||
.dom("[data-test-sortable-th=first_name] span[icon=chevron-down]") | ||
.doesNotExist(); | ||
assert | ||
.dom("[data-test-sortable-th=last_name] span[icon=chevron-down]") | ||
.exists(); | ||
|
||
this.set("sort", "-last_name"); | ||
|
||
assert | ||
.dom("[data-test-sortable-th=last_name] span[icon=chevron-up]") | ||
.exists(); | ||
}); | ||
} | ||
); |