Skip to content

Commit

Permalink
feat(uk-switcher): add uikit events for the switcher component
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhofmann2 authored and Jonas Metzener committed Sep 4, 2019
1 parent a1e181b commit 641bdaf
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
25 changes: 24 additions & 1 deletion addon/components/uk-switcher/content/item.js
@@ -1,8 +1,31 @@
import Component from "@ember/component";
import layout from "../../../templates/components/uk-switcher/content/item";
import UIkit from "uikit";

// empty function as default event handler
const noop = () => {};

export default Component.extend({
layout,

tagName: "li"
tagName: "li",

setEvents() {
let events = {
beforeshow: this.getWithDefault("on-beforeshow", noop),
show: this.getWithDefault("on-show", noop),
shown: this.getWithDefault("on-shown", noop),
beforehide: this.getWithDefault("on-beforehide", noop),
hide: this.getWithDefault("on-hide", noop),
hidden: this.getWithDefault("on-hidden", noop)
};

for (let event in events) {
UIkit.util.on(this.element, event, events[event]);
}
},
didInsertElement() {
this._super(...arguments);
this.setEvents();
}
});
46 changes: 45 additions & 1 deletion tests/integration/components/uk-switcher/content/item-test.js
@@ -1,6 +1,6 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { render } from "@ember/test-helpers";
import { render, triggerEvent } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";

module("Integration | Component | uk switcher/content/item", function(hooks) {
Expand All @@ -14,4 +14,48 @@ module("Integration | Component | uk switcher/content/item", function(hooks) {
assert.dom("li").exists();
assert.dom("li").hasText("Test");
});

test("has switcher content item events", async function(assert) {
this.set("beforeshow", false);
this.set("show", false);
this.set("shown", false);
this.set("beforehide", false);
this.set("hide", false);
this.set("hidden", false);

await render(
hbs`{{#uk-switcher/content/item
on-beforeshow=(action (mut beforeshow) true)
on-show=(action (mut show) true)
on-shown=(action (mut shown) true)
on-beforehide=(action (mut beforehide) true)
on-hide=(action (mut hide) true)
on-hidden=(action (mut hidden) true)
}}
<div />
{{/uk-switcher/content/item}}`
);

assert.dom("li").exists();
assert.notOk(this.get("beforeshow"));
assert.notOk(this.get("show"));
assert.notOk(this.get("shown"));
assert.notOk(this.get("beforehide"));
assert.notOk(this.get("hide"));
assert.notOk(this.get("hidden"));

await triggerEvent("li", "beforeshow");
await triggerEvent("li", "show");
await triggerEvent("li", "shown");
await triggerEvent("li", "beforehide");
await triggerEvent("li", "hide");
await triggerEvent("li", "hidden");

assert.ok(this.get("beforeshow"));
assert.ok(this.get("show"));
assert.ok(this.get("shown"));
assert.ok(this.get("beforehide"));
assert.ok(this.get("hide"));
assert.ok(this.get("hidden"));
});
});

0 comments on commit 641bdaf

Please sign in to comment.