Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.
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
26 changes: 26 additions & 0 deletions packages/oui-dropdown/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,32 @@ describe("ouiDropdown", () => {
expect(link.attr("target")).toBe("_blank");
expect(link.attr("rel")).toBe("noopener");
});

it("should call click callback", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getter better at this, nice 👍

const onLinkClickSpy = jasmine.createSpy("onLinkClickSpy");
const onButtonClickSpy = jasmine.createSpy("onButtonClickSpy");
const element = TestUtils.compileTemplate(`
<oui-dropdown>
<oui-dropdown-trigger text="Actions"></oui-dropdown-trigger>
<oui-dropdown-content>
<oui-dropdown-item text="Lorem ipsum" href="#" on-click="$ctrl.onLinkClick()"></oui-dropdown-item>
<oui-dropdown-item text="Lorem ipsum" on-click="$ctrl.onButtonClick()"></oui-dropdown-item>
<oui-dropdown-item text="Lorem ipsum" href="#"></oui-dropdown-item>
</oui-dropdown-content>
</oui-dropdown>
`, {
onLinkClick: onLinkClickSpy,
onButtonClick: onButtonClickSpy
});

$timeout.flush();
const items = angular.element(element[0].querySelectorAll("oui-dropdown-item")).children();
angular.element(items[0]).triggerHandler("click");
angular.element(items[1]).triggerHandler("click");

expect(onLinkClickSpy).toHaveBeenCalled();
expect(onButtonClickSpy).toHaveBeenCalled();
});
});

describe("Group", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/oui-dropdown/src/item/dropdown-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
ng-if="::!!$ctrl.href"
ng-href="{{::$ctrl.href}}"
ng-attr-target="{{::$ctrl.linkTarget}}"
ng-attr-rel="{{::$ctrl.linkRel}}">
ng-attr-rel="{{::$ctrl.linkRel}}"
ng-click="$ctrl.onClick()">
<span ng-transclude>{{::$ctrl.text}}</span>
<span ng-if="::$ctrl.external"
class="oui-icon oui-icon-external_link"
Expand All @@ -23,6 +24,7 @@
role="menuitem"
ng-if="::!!$ctrl.state"
ui-sref="{{::$ctrl.getFullSref()}}"
ng-click="$ctrl.onClick()"
ng-transclude>
{{::$ctrl.text}}
</a>