Merge branch 'review/slice-8-session'
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fetchSchools, type SchoolsResponse } from '../net/api.ts';
|
||||
import { t } from '../i18n/strings.ts';
|
||||
import { MainMenu } from './mainMenu.ts';
|
||||
|
||||
vi.mock('../net/api.ts', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../net/api.ts')>();
|
||||
return {
|
||||
...actual,
|
||||
fetchSchools: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('MainMenu ownership', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('hides delete on another owners card and shows it on an ownerless one', async () => {
|
||||
vi.mocked(fetchSchools).mockResolvedValue(menuState());
|
||||
|
||||
const menu = new MainMenu({
|
||||
onOpenSchool: () => {},
|
||||
onLogout: () => {},
|
||||
});
|
||||
document.body.append(menu.element);
|
||||
await menu.refresh();
|
||||
|
||||
const foreign = menu.element.querySelector('[data-school-id="2"]');
|
||||
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'));
|
||||
});
|
||||
});
|
||||
|
||||
function menuState(): SchoolsResponse {
|
||||
return {
|
||||
maxSchools: 2,
|
||||
maxSchoolsTotal: 16,
|
||||
defaultStartDate: '2012-03-31T06:00:00.000Z',
|
||||
gameMinutesPerRealSecond: 1,
|
||||
schoolWeekDays: 5,
|
||||
schools: [],
|
||||
others: [
|
||||
{
|
||||
id: 2,
|
||||
name: 'Foreign',
|
||||
gameTime: '2012-03-31T06:00:00.000Z',
|
||||
running: true,
|
||||
speedIndex: 1,
|
||||
seed: 1,
|
||||
owner: 'Bob',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Orphan',
|
||||
gameTime: '2012-03-31T06:00:00.000Z',
|
||||
running: true,
|
||||
speedIndex: 1,
|
||||
seed: 2,
|
||||
owner: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user