Files
iptvnator/libs/ui/components/src/lib/dialog-shell/dialog-shell.component.spec.ts
T
4grayandClaude Fable 5.1 2139ddd5c0 feat(ui): one dialog frame, a shared dialog shell and three width presets (#1942)
* feat(ui): one dialog frame, a shared dialog shell and three width presets

Every dialog gets the kit frame from m3-theme.scss: a 16px panel on the
widget surface with a hairline border and the popover shadow, over a tinted
backdrop blurred at 6px. The command palette and the programme dialog keep
their own surface through their panel classes.

`app-dialog-shell` (@iptvnator/ui/components) draws the header (optional
icon tile, the heading as mat-dialog-title, subtitle, a header-end slot and
a close button), the body and a footer that renders only when an element
marked appDialogFooter wraps the actions. The close button is last in the
DOM, so first-tabbable autofocus lands in the body. Footer buttons take the
kit look: ghost, accent (new accent-button mixin) or secondary; destructive
buttons keep their tint and get the kit's 10px radius.

`dialogSize('sm' | 'md' | 'lg')` owns the width and viewport limits with a
type-only MatDialogConfig import; MAT_DIALOG_DEFAULT_OPTIONS is deliberately
not provided at the root, which would put Material's dialog back on the
startup path.

Migrated: the confirm dialog (sm), the add-playlist dialog (lg) and the
keyboard shortcuts dialog (lg, close button only). Slot wrappers render as
display: contents, because a control-flow block at the top level of the
content is projected into the body, not into a named slot.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(ui): name the dialog shell's close button "Close dialog"

A confirm dialog opened with a "Close" dismiss (the download recovery
prompt, the VOD download prompt) had two buttons named "Close" once the
shell added its header ×, and the Electron download-recovery test failed
on a strict-mode violation for `getByRole('button', { name: 'Close' })`.
The × is now named by the new `CLOSE_DIALOG` key ("Close dialog") in every
locale, so a footer "Close" stays the only button of that name; the same
holds for the dialogs PR 3 migrates, whose E2E flows select "Close".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(ui): let short windows scroll the whole dialog shell

With the shell capped at the viewport, a stacked footer (the add-playlist
Xtream mode has five rows) left the body a 40px sliver at 360×480. Under
600px of viewport height the cap comes off and Material's surface scrolls
the whole dialog as the single scroll owner, which is how the dialog
behaved before the shell.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 23:29:24 +02:00

138 lines
5.0 KiB
TypeScript

import { Component, input, Type } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { MatDialogRef } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core';
import { DialogShellComponent } from './dialog-shell.component';
import {
DialogFooterDirective,
DialogFooterStartDirective,
DialogHeaderEndDirective,
} from './dialog-shell.directives';
@Component({
imports: [
DialogShellComponent,
DialogFooterDirective,
DialogFooterStartDirective,
DialogHeaderEndDirective,
],
// The slot wrappers sit at the top level of the content: a control-flow
// block there would be projected into the body, so the conditional
// action lives inside the footer wrapper.
template: `
<app-dialog-shell
heading="Remove playlist"
subtitle="Pick how"
icon="keyboard"
[showClose]="showClose()"
>
<span appDialogHeaderEnd>macOS</span>
<p>Body text</p>
<div appDialogFooterStart><button>Clear</button></div>
<div appDialogFooter>
<button>Cancel</button>
@if (withRemove()) {
<button>Remove</button>
}
</div>
</app-dialog-shell>
`,
})
class FullHostComponent {
readonly showClose = input(true);
readonly withRemove = input(true);
}
@Component({
imports: [DialogShellComponent],
template: `
<app-dialog-shell heading="Keyboard shortcuts">
<p>Body only</p>
</app-dialog-shell>
`,
})
class BareHostComponent {}
describe('DialogShellComponent', () => {
const close = jest.fn();
async function render<T>(
host: Type<T>,
inputs: Partial<Record<string, unknown>> = {}
) {
await TestBed.configureTestingModule({
imports: [host, TranslateModule.forRoot()],
providers: [{ provide: MatDialogRef, useValue: { close } }],
}).compileComponents();
const fixture = TestBed.createComponent(host);
for (const [name, value] of Object.entries(inputs)) {
fixture.componentRef.setInput(name, value);
}
fixture.detectChanges();
return fixture.nativeElement as HTMLElement;
}
beforeEach(() => close.mockClear());
it('names the dialog by the heading and projects the header, body and footer slots in order, including a conditional action', async () => {
const root = await render(FullHostComponent);
const title = root.querySelector('h2.app-dialog__title');
expect(title?.textContent?.trim()).toBe('Remove playlist');
expect(title?.id).toMatch(/^mat-mdc-dialog-title-/);
expect(
root.querySelector('.app-dialog__subtitle')?.textContent?.trim()
).toBe('Pick how');
expect(
root.querySelector('.app-dialog__icon mat-icon')?.textContent
).toBe('keyboard');
expect(
root.querySelector('.app-dialog__header-end')?.textContent?.trim()
).toBe('macOS');
expect(root.querySelector('.app-dialog__body')?.textContent).toContain(
'Body text'
);
const footerTexts = Array.from(
root.querySelectorAll('.app-dialog__footer button')
).map((button) => button.textContent?.trim());
expect(footerTexts).toEqual(['Clear', 'Cancel', 'Remove']);
});
it('drops a conditional action from the footer without losing the others', async () => {
const root = await render(FullHostComponent, { withRemove: false });
const footerTexts = Array.from(
root.querySelectorAll('.app-dialog__footer button')
).map((button) => button.textContent?.trim());
expect(footerTexts).toEqual(['Clear', 'Cancel']);
});
it('renders no footer, icon tile or subtitle when nothing is projected or set', async () => {
const root = await render(BareHostComponent);
expect(root.querySelector('.app-dialog__footer')).toBeNull();
expect(root.querySelector('.app-dialog__icon')).toBeNull();
expect(root.querySelector('.app-dialog__subtitle')).toBeNull();
expect(root.querySelector('.app-dialog__body')?.textContent).toContain(
'Body only'
);
});
it('closes through the header button, which comes last in the DOM so autofocus lands in the body', async () => {
const root = await render(FullHostComponent);
const buttons = Array.from(root.querySelectorAll('button'));
const closeButton = buttons.at(-1) as HTMLButtonElement;
expect(closeButton.classList).toContain('app-dialog__close');
expect(closeButton.getAttribute('aria-label')).toBe('CLOSE_DIALOG');
closeButton.click();
expect(close).toHaveBeenCalledTimes(1);
});
it('hides the close button on request', async () => {
const root = await render(FullHostComponent, { showClose: false });
expect(root.querySelector('.app-dialog__close')).toBeNull();
});
});