diff --git a/app/components/optimized-power-select/trigger/template.hbs b/app/components/optimized-power-select/trigger/template.hbs index 60aa8844e..30b2e7b86 100644 --- a/app/components/optimized-power-select/trigger/template.hbs +++ b/app/components/optimized-power-select/trigger/template.hbs @@ -1,30 +1,36 @@ -{{#if @select.selected}} - {{#if @selectedItemComponent}} +
+ {{#if @select.selected}} + {{#if @selectedItemComponent}} + {{component + @selectedItemComponent + option=(readonly @select.selected) + select=(readonly @select) + }} + {{else}} + + {{#if @extra.selectedTemplate}} + {{component + (ensure-safe-component @extra.selectedTemplate) + selected=@select.selected + }} + {{else}} + {{yield @select.selected @select}} + {{/if}} + + {{/if}} + {{#if (and @allowClear (not @select.disabled))}} + × + {{/if}} + {{else}} {{component - @selectedItemComponent - option=(readonly @select.selected) - select=(readonly @select) + (ensure-safe-component @placeholderComponent) + placeholder=@placeholder }} - {{else}} - - {{#if @extra.selectedTemplate}} - {{component (ensure-safe-component @extra.selectedTemplate) selected=@select.selected}} - {{else}} - {{yield @select.selected @select}} - {{/if}} - - {{/if}} - {{#if (and @allowClear (not @select.disabled))}} - × {{/if}} -{{else}} - {{component - (ensure-safe-component @placeholderComponent) - placeholder=@placeholder - }} -{{/if}} - + +
diff --git a/tests/integration/components/optimized-power-select/component-test.js b/tests/integration/components/optimized-power-select/component-test.js new file mode 100644 index 000000000..a5876c909 --- /dev/null +++ b/tests/integration/components/optimized-power-select/component-test.js @@ -0,0 +1,83 @@ +import { triggerKeyEvent, render } from "@ember/test-helpers"; +import { hbs } from "ember-cli-htmlbars"; +import { + typeInSearch, + clickTrigger, +} from "ember-power-select/test-support/helpers"; +import { setupRenderingTest } from "ember-qunit"; +import { module, test } from "qunit"; +import taskOptionTemplate from "timed/components/optimized-power-select/custom-options/task-option"; +import customSelectedTemplate from "timed/components/optimized-power-select/custom-select/task-selection"; + +const OPTIONS = [ + { id: 1, name: "Test 1" }, + { id: 2, name: "Test 2" }, + { id: 3, name: "Test 3" }, +]; + +module("Integration | Component | optimized power select", function (hooks) { + setupRenderingTest(hooks); + + test("can use blockless", async function (assert) { + this.set("options", OPTIONS); + this.set("selected", OPTIONS[0]); + + this.set("selectedTemplate", customSelectedTemplate); + this.set("optionTemplate", taskOptionTemplate); + + await render(hbs` + {{(component + (ensure-safe-component "optimized-power-select") + options = this.options + selected = this.selected + onChange = (fn (mut this.selected)) + tagName = 'div' + renderInPlace = true + searchField = 'name' + extra = (hash + optionTemplate = this.optionTemplate + selectedTemplate = this.selectedTemplate + ) + ) + }} + `); + + await clickTrigger(); + + assert.dom(".ember-power-select-selected-item").hasText("Test 1"); + assert.dom(".ember-power-select-option:first-of-type").hasText("Test 1"); + }); + + test("can select with return key", async function (assert) { + assert.expect(1); + this.set("options", OPTIONS); + this.set("selected", OPTIONS[0]); + + this.set("selectedTemplate", customSelectedTemplate); + this.set("optionTemplate", taskOptionTemplate); + + await render(hbs` + {{(component + (ensure-safe-component "optimized-power-select") + options = this.options + selected = this.selected + onChange = (fn (mut this.selected)) + tagName = 'div' + renderInPlace = true + searchField = 'name' + extra = (hash + optionTemplate = this.optionTemplate + selectedTemplate = this.selectedTemplate + ) + ) + }} + `); + + await clickTrigger(); + await typeInSearch("2"); + + await triggerKeyEvent(".ember-power-select-search-input", "keydown", 13); + + assert.strictEqual(this.get("selected.id"), 2); + }); +}); diff --git a/tests/integration/components/power-select/component-test.js b/tests/integration/components/power-select/component-test.js deleted file mode 100644 index b95f5c078..000000000 --- a/tests/integration/components/power-select/component-test.js +++ /dev/null @@ -1,80 +0,0 @@ -import { triggerKeyEvent, render } from "@ember/test-helpers"; -import { hbs } from "ember-cli-htmlbars"; -import { - typeInSearch, - clickTrigger, -} from "ember-power-select/test-support/helpers"; -import { setupRenderingTest } from "ember-qunit"; -import { module, test } from "qunit"; - -const OPTIONS = [ - { id: 1, name: "Test 1" }, - { id: 2, name: "Test 2" }, - { id: 3, name: "Test 3" }, -]; - -module("Integration | Component | power select", function (hooks) { - setupRenderingTest(hooks); - - test("can use blockless", async function (assert) { - this.set("options", OPTIONS); - this.set("selected", OPTIONS[0]); - - this.set("selectedTemplate", hbs`Selected: {{selected.name}}`); - this.set("optionTemplate", hbs`Option: {{option.name}}`); - - await render(hbs` - {{power-select - options = options - selected = selected - onchange = (action (mut selected)) - tagName = 'div' - class = 'select' - renderInPlace = true - extra = (hash - optionTemplate = optionTemplate - selectedTemplate = selectedTemplate - ) - }} - `); - - await clickTrigger(".select"); - - assert.dom(".ember-power-select-selected-item").hasText("Selected: Test 1"); - assert - .dom(".ember-power-select-option:first-of-type") - .hasText("Option: Test 1"); - }); - - test("can select with tab", async function (assert) { - assert.expect(1); - this.set("options", OPTIONS); - this.set("selected", OPTIONS[0]); - - this.set("selectedTemplate", hbs`Selected: {{selected.name}}`); - this.set("optionTemplate", hbs`Option: {{option.name}}`); - - await render(hbs` - {{power-select - options = options - selected = selected - onchange = (action (mut selected)) - tagName = 'div' - class = 'select' - renderInPlace = true - searchField = 'name' - extra = (hash - optionTemplate = optionTemplate - selectedTemplate = selectedTemplate - ) - }} - `); - - await clickTrigger(".select"); - await typeInSearch("2"); - - await triggerKeyEvent(".ember-power-select-search-input", "keydown", 9); - - assert.strictEqual(this.get("selected.id"), 2); - }); -}); diff --git a/tests/unit/index/controller-test.js b/tests/unit/index/controller-test.js index 008cb42b1..243eee375 100644 --- a/tests/unit/index/controller-test.js +++ b/tests/unit/index/controller-test.js @@ -1,14 +1,9 @@ import { setupTest } from "ember-qunit"; import { module, test } from "qunit"; -import { setup as setupTrackingStub } from "timed/tests/helpers/tracking-mock"; module("Unit | Controller | index", function (hooks) { setupTest(hooks); - hooks.beforeEach(function () { - setupTrackingStub(this); - }); - test("exists", function (assert) { const controller = this.owner.lookup("controller:index"); assert.ok(controller);