Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HdsTab tests and types #230

Merged
merged 1 commit into from
Jun 26, 2023
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
1 change: 0 additions & 1 deletion web/app/components/dashboard/latest-updates.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
<div class="flex items-center space-x-2 mb-6">
<FlightIcon @name="collections" @size="24" />
<h2
Expand Down
20 changes: 4 additions & 16 deletions web/app/components/x/hds-tab.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
{{! @glint-nocheck: not typesafe yet }}
<div class="x-hds-tab {{if @isSelected 'x-hds-tab--selected'}}">
{{#if @action}}
<button {{on "click" @action}} class="x-hds-tab--button">
<FlightIcon @name={{@icon}} />
{{#unless @iconOnly}}
<span>{{@label}}</span>
{{/unless}}
</button>
{{else}}
<LinkTo @route={{@link}} @query={{hds-link-to-query @query}} class="x-hds-tab--link">
<FlightIcon @name={{@icon}} />
{{#unless @iconOnly}}
<span>{{@label}}</span>
{{/unless}}
</LinkTo>
{{/if}}
<button {{on "click" @action}} class="x-hds-tab--button">
<FlightIcon @name={{@icon}} />
<span>{{@label}}</span>
</button>
</div>
21 changes: 21 additions & 0 deletions web/app/components/x/hds-tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Component from "@glimmer/component";

interface XHdsTabComponentSignature {
Args: {
label: string;
icon: string;
isSelected: boolean;
action: () => void;
};
Blocks: {
default: [];
};
}

export default class XHdsTabComponent extends Component<XHdsTabComponentSignature> {}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
"X::HdsTab": typeof XHdsTabComponent;
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { click, render } from "@ember/test-helpers";
import { TestContext, click, render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";

interface HdsTabTestContext extends TestContext {
action: () => void;
isSelected: boolean;
buttonWasClicked: boolean;
}

module("Integration | Component | hds-tab", function (hooks) {
setupRenderingTest(hooks);

test("it renders as a link", async function (assert) {
await render(hbs`
<X::HdsTab
@label="Tab"
@icon="star"
@link="/"
/>
`);

assert.dom(".x-hds-tab--link").hasText("Tab");
assert.dom(".flight-icon-star").exists();
});

test("it can be displayed `iconOnly`", async function (assert) {
await render(hbs`
<X::HdsTab
@label="Tab"
@icon="star"
@link="/"
@iconOnly={{true}}
/>
`);

assert.dom(".x-hds-tab span").doesNotExist();
assert.dom(".flight-icon-star").exists();
});

test("it renders as a button when an `action` is provided", async function (assert) {
test("it renders as expected", async function (this: HdsTabTestContext, assert) {
this.set("action", () => {
this.set("buttonWasClicked", true);
});
this.set("isSelected", false);

await render(hbs`
await render<HdsTabTestContext>(hbs`
<X::HdsTab
@label="Tab"
@icon="star"
@action={{this.action}}
@isSelected={{this.isSelected}}

/>

{{#if this.buttonWasClicked}}
Expand All @@ -58,20 +40,8 @@ module("Integration | Component | hds-tab", function (hooks) {
assert.dom(".success-message").doesNotExist();
await click(".x-hds-tab--button");
assert.dom(".success-message").exists();
});

test("it can take a selected state", async function (assert) {
this.set("isSelected", false);

await render(hbs`
<X::HdsTab
@label="Tab"
@icon="star"
@link="/"
@isSelected={{this.isSelected}}
/>
`);

// test the is-selected state
assert.dom(".x-hds-tab--selected").doesNotExist();
this.set("isSelected", true);
assert.dom(".x-hds-tab--selected").exists("Tab has a selected state");
Expand Down