Show a bare dash on ownerless school cards.
The design asked for the owner name or an em dash; wrapping the dash in the Owner template produced Хозяин: —. Low-speed clock tests now cover x1/2 and x2 as well as x1.
This commit is contained in:
@@ -37,8 +37,11 @@ describe('MainMenu ownership', () => {
|
||||
const orphan = menu.element.querySelector('[data-school-id="3"]');
|
||||
expect((foreign?.querySelector('.button--danger') as HTMLElement).hidden).toBe(true);
|
||||
expect((orphan?.querySelector('.button--danger') as HTMLElement).hidden).toBe(false);
|
||||
expect(foreign?.textContent).toContain('Bob');
|
||||
expect(orphan?.textContent).toContain(t('schoolOwnerless'));
|
||||
expect(foreign?.querySelector('.card__owner')?.textContent).toBe(t('schoolOwner', { owner: 'Bob' }));
|
||||
expect(orphan?.querySelector('.card__owner')?.textContent).toBe(t('schoolOwnerless'));
|
||||
expect(orphan?.querySelector('.card__owner')?.textContent).not.toBe(
|
||||
t('schoolOwner', { owner: t('schoolOwnerless') }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -181,7 +181,8 @@ export class MainMenu {
|
||||
const menuSchool: MenuSchool = { ...other, mine: false };
|
||||
this.patchCard(menuSchool, 'other', this.othersGrid, {
|
||||
canDelete: other.owner === null,
|
||||
ownerLabel: other.owner ?? t('schoolOwnerless'),
|
||||
ownerLabel:
|
||||
other.owner === null ? t('schoolOwnerless') : t('schoolOwner', { owner: other.owner }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { t } from '../i18n/strings.ts';
|
||||
import { SchoolCard } from './schoolCard.ts';
|
||||
|
||||
describe('SchoolCard ownership', () => {
|
||||
@@ -21,12 +22,41 @@ describe('SchoolCard ownership', () => {
|
||||
onOpen: () => {},
|
||||
onDelete: () => {},
|
||||
canDelete: false,
|
||||
ownerLabel: 'Bob',
|
||||
ownerLabel: t('schoolOwner', { owner: 'Bob' }),
|
||||
},
|
||||
);
|
||||
|
||||
document.body.append(card.element);
|
||||
|
||||
expect((card.element.querySelector('.button--danger') as HTMLElement).hidden).toBe(true);
|
||||
expect(card.element.querySelector('.card__owner')?.textContent).toBe(t('schoolOwner', { owner: 'Bob' }));
|
||||
});
|
||||
|
||||
it('shows a bare dash on an ownerless card, not Owner: —', () => {
|
||||
const card = new SchoolCard(
|
||||
{
|
||||
id: 3,
|
||||
name: 'Orphan',
|
||||
gameTime: '2012-03-31T06:00:00.000Z',
|
||||
running: true,
|
||||
speedIndex: 1,
|
||||
seed: 2,
|
||||
mine: false,
|
||||
owner: null,
|
||||
},
|
||||
{
|
||||
onOpen: () => {},
|
||||
onDelete: () => {},
|
||||
canDelete: true,
|
||||
ownerLabel: t('schoolOwnerless'),
|
||||
},
|
||||
);
|
||||
|
||||
document.body.append(card.element);
|
||||
|
||||
expect(card.element.querySelector('.card__owner')?.textContent).toBe(t('schoolOwnerless'));
|
||||
expect(card.element.querySelector('.card__owner')?.textContent).not.toBe(
|
||||
t('schoolOwner', { owner: t('schoolOwnerless') }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,6 +68,7 @@ export class SchoolCard {
|
||||
this.update(this.school);
|
||||
}
|
||||
|
||||
/** `label` is already painted: `Owner: Bob` or a bare dash — do not wrap it again. */
|
||||
setOwnerLabel(label: string | null): void {
|
||||
if (label === null) {
|
||||
this.owner.hidden = true;
|
||||
@@ -76,7 +77,7 @@ export class SchoolCard {
|
||||
}
|
||||
|
||||
this.owner.hidden = false;
|
||||
this.owner.textContent = t('schoolOwner', { owner: label });
|
||||
this.owner.textContent = label;
|
||||
}
|
||||
|
||||
update(school: MenuSchool): void {
|
||||
|
||||
Reference in New Issue
Block a user