Skip to content

Commit 38f1a85

Browse files
committed
Add Glint support to the AuMainHeader component
1 parent 132d303 commit 38f1a85

File tree

5 files changed

+128
-32
lines changed

5 files changed

+128
-32
lines changed

addon/components/au-main-header.gjs addon/components/au-main-header.gts

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import { AuBrand, AuLink } from '@appuniversum/ember-appuniversum';
21
import { on } from '@ember/modifier';
32
import { action } from '@ember/object';
43
import { LinkTo } from '@ember/routing';
5-
import { inject as service } from '@ember/service';
4+
import type RouterService from '@ember/routing/router-service';
5+
import { service } from '@ember/service';
66
import Component from '@glimmer/component';
7+
import AuBrand from './au-brand';
8+
import AuLink from './au-link';
79

8-
export default class AuMainHeader extends Component {
10+
export interface AuMainHeaderSignature {
11+
Args: {
12+
appTitle: string;
13+
brandLink?: string;
14+
contactRoute?: string;
15+
homeRoute?: string;
16+
};
17+
Blocks: {
18+
default: [];
19+
};
20+
Element: HTMLElement;
21+
}
22+
23+
export default class AuMainHeader extends Component<AuMainHeaderSignature> {
924
@action
1025
headerLinkFocus() {
11-
document.querySelector('#main')?.focus();
26+
(document.querySelector('#main') as HTMLElement | null)?.focus();
1227
}
1328

1429
<template>
15-
<header class="au-c-main-header">
30+
<header class="au-c-main-header" ...attributes>
1631
<div class="au-c-main-header__title-group">
1732
<NavigationNarrator />
1833
<AuBrand @link="{{@brandLink}}" />
@@ -56,7 +71,7 @@ export default class AuMainHeader extends Component {
5671
}
5772

5873
class NavigationNarrator extends Component {
59-
@service router;
74+
@service declare router: RouterService;
6075

6176
get activeRoute() {
6277
return 'Nieuwe pagina: ' + this.router.currentRouteName;

addon/template-registry.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type AuList from '@appuniversum/ember-appuniversum/components/au-list';
2727
import type AuLoader from '@appuniversum/ember-appuniversum/components/au-loader';
2828
import type AuMainContainer from '@appuniversum/ember-appuniversum/components/au-main-container';
2929
import type AuMainFooter from '@appuniversum/ember-appuniversum/components/au-main-footer';
30+
import type AuMainHeader from '@appuniversum/ember-appuniversum/components/au-main-header';
3031
import type AuToolbar from '@appuniversum/ember-appuniversum/components/au-toolbar';
3132

3233
// Modifiers
@@ -62,6 +63,7 @@ export default interface AppuniversumRegistry {
6263
AuLoader: typeof AuLoader;
6364
AuMainContainer: typeof AuMainContainer;
6465
AuMainFooter: typeof AuMainFooter;
66+
AuMainHeader: typeof AuMainHeader;
6567
AuToolbar: typeof AuToolbar;
6668

6769
// Modifiers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import AuMainHeader from '@appuniversum/ember-appuniversum/components/au-main-header';
2+
import { getRootElement } from '@ember/test-helpers';
3+
import { click } from '@ember/test-helpers';
4+
import { render } from '@ember/test-helpers';
5+
import { queryByText } from '@testing-library/dom';
6+
import { setupRenderingTest } from 'ember-qunit';
7+
import { module, test } from 'qunit';
8+
9+
module('Integration | Component | au-main-header', function (hooks) {
10+
setupRenderingTest(hooks);
11+
12+
test('it requires an `@appTitle`', async function (assert) {
13+
await render(
14+
<template>
15+
{{! @glint-expect-error: @appTitle is required }}
16+
<AuMainHeader />
17+
</template>,
18+
);
19+
20+
await render(
21+
<template><AuMainHeader @appTitle="Appuniversum" /></template>,
22+
);
23+
24+
const testContainer = getRootElement() as HTMLElement;
25+
const title = queryByText(testContainer, 'Appuniversum');
26+
assert.dom(title).exists();
27+
});
28+
29+
test('it can display the title as a link by setting the `@homeRoute` argument', async function (assert) {
30+
await render(
31+
<template>
32+
<AuMainHeader @appTitle="Appuniversum" @homeRoute="application" />
33+
</template>,
34+
);
35+
36+
const testContainer = getRootElement() as HTMLElement;
37+
const title = queryByText(testContainer, 'Appuniversum');
38+
assert
39+
.dom(title)
40+
.hasTagName('a', 'The title element is a link if `@homeRoute` is set');
41+
});
42+
43+
test('it focuses the #main element after clicking the title link', async function (assert) {
44+
await render(
45+
<template>
46+
<AuMainHeader @appTitle="Appuniversum" @homeRoute="application" />
47+
<main id="main" tabindex="-1">Main content</main>
48+
</template>,
49+
);
50+
51+
const testContainer = getRootElement() as HTMLElement;
52+
const title = queryByText(testContainer, 'Appuniversum') as HTMLElement;
53+
54+
assert.dom('#main').isNotFocused();
55+
await click(title);
56+
assert.dom('#main').isFocused();
57+
});
58+
59+
test('it supports showing a link to the contact route', async function (assert) {
60+
await render(
61+
<template><AuMainHeader @appTitle="Appuniversum" /></template>,
62+
);
63+
64+
const testContainer = getRootElement() as HTMLElement;
65+
let contactLink = queryByText(testContainer, 'Contacteer ons');
66+
assert.notOk(
67+
contactLink,
68+
"The contact link isn't displayed without the `@contactRoute` argument",
69+
);
70+
71+
await render(
72+
<template>
73+
<AuMainHeader @appTitle="Appuniversum" @contactRoute="application" />
74+
</template>,
75+
);
76+
77+
contactLink = queryByText(testContainer, 'Contacteer ons');
78+
79+
assert.dom(contactLink).hasTagName('a');
80+
});
81+
82+
test('it accepts extra block contents', async function (assert) {
83+
await render(
84+
<template>
85+
<AuMainHeader @appTitle="Appuniversum" data-test-main-header>
86+
extra header content
87+
</AuMainHeader>
88+
</template>,
89+
);
90+
91+
const testContainer = getRootElement() as HTMLElement;
92+
const extraHeaderContent = queryByText(
93+
testContainer,
94+
'extra header content',
95+
);
96+
assert.ok(extraHeaderContent);
97+
});
98+
});

tests/integration/components/au-main-header-test.js

-26
This file was deleted.

tests/integration/components/loose-mode-test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ module('Integration | Component | Loose mode', function (hooks) {
200200
assert.dom('[data-test-main-footer]').exists();
201201
});
202202

203+
test('`<AuMainHeader>` resolves in loose mode', async function (assert) {
204+
await render(hbs`
205+
<AuMainHeader @appTitle="Appuniversum" data-test-main-header />
206+
`);
207+
assert.dom('[data-test-main-header]').exists();
208+
});
209+
203210
test('`<AuToolbar>` resolves in loose mode', async function (assert) {
204211
await render(hbs`
205212
<AuToolbar data-test-toolbar></AuToolbar>

0 commit comments

Comments
 (0)