Skip to content
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
15 changes: 8 additions & 7 deletions packages/components/src/components/hds/dropdown/toggle/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type Owner from '@ember/owner';
export const DEFAULT_SIZE = HdsDropdownToggleIconSizeValues.Medium;
export const SIZES: string[] = Object.values(HdsDropdownToggleIconSizeValues);

export const ALLOWED_LIST: string[] = Object.values(
export const ALLOWED_ICON_LIST: string[] = Object.values(
HdsDropdownToggleIconAllowedIconValues
);

Expand Down Expand Up @@ -119,14 +119,15 @@ export default class HdsDropdownToggleIcon extends Component<HdsDropdownToggleIc
* @default true
*/
get hasChevron(): boolean {
const { icon, hasChevron } = this.args;

if (icon && !ALLOWED_LIST.includes(icon) && hasChevron === false) {
if (
this.args.icon &&
!ALLOWED_ICON_LIST.includes(this.args.icon) &&
this.args.hasChevron === false
) {
assert(
`@hasChevron for "Hds::Dropdown::Toggle::Icon" must be true unless the icon is one of the following: ${ALLOWED_LIST.join(
`@hasChevron for "Hds::Dropdown::Toggle::Icon" must be true unless the icon is one of the following: ${ALLOWED_ICON_LIST.join(
', '
)}; received: ${icon}`,
ALLOWED_LIST.includes(icon)
)}; received: ${this.args.icon}`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module('Integration | Component | hds/dropdown/toggle/icon', function (hooks) {
});
test('toggle-icon renders no chevron when hasChevron is set to false', async function (assert) {
await render(
hbs`<Hds::Dropdown::Toggle::Icon @icon="user" @text="user menu" id="test-toggle-icon" @hasChevron={{false}} />`,
hbs`<Hds::Dropdown::Toggle::Icon @icon="more-horizontal" @text="user menu" id="test-toggle-icon" @hasChevron={{false}} />`,
Copy link
Contributor

Choose a reason for hiding this comment

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

ooo good catch! i guess we were trying to debug the wrong test the whole time :,) a good learning experience though

);
assert.dom('.hds-icon.hds-icon-chevron-down').doesNotExist();
});
Expand Down Expand Up @@ -155,15 +155,15 @@ module('Integration | Component | hds/dropdown/toggle/icon', function (hooks) {
throw new Error(errorMessage);
});
});
test('it should throw an assertion if an incorrect value for @icon is provided and @hasChevron is false', async function (assert) {
test('it should throw an assertion if an incorrect value for @icon is provided while @hasChevron is false', async function (assert) {
const errorMessage =
'@hasChevron for "Hds::Dropdown::Toggle::Icon" must be true unless the icon is one of the following: more-horizontal, more-vertical; received: user';
'@hasChevron for "Hds::Dropdown::Toggle::Icon" must be true unless the icon is one of the following: more-horizontal, more-vertical; received: apple';
assert.expect(2);
setupOnerror(function (error) {
assert.strictEqual(error.message, `Assertion Failed: ${errorMessage}`);
});
await render(
hbs`<Hds::Dropdown::Toggle::Icon @icon="user" @text="user menu" @hasChevron={{false}}/>`,
hbs`<Hds::Dropdown::Toggle::Icon @icon="apple" @text="user menu" @hasChevron={{false}}/>`,
);
assert.throws(function () {
throw new Error(errorMessage);
Expand Down