mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
9018ee8980
SonarCloud measured 16.9% coverage on this PR's new code. Tests now cover the WebGL globe engine (boot, caching, input, camera, regions, prefetch) and renderer (against a fake WebGL2 context that reads the real shaders), the paint, labels, sky and pins, the central useAtlasGlobe hook and the hub hooks, the snapshot, account queue and Atlas repos, every desktop and phone hub view, the server's people, flights and mesh routes, the shared badge rules, and the new view transition, warm bags and kept planner maps.
64 lines
3.0 KiB
TypeScript
64 lines
3.0 KiB
TypeScript
import userEvent from '@testing-library/user-event';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import MAdminAddonManager from '../../../../src/mobile/screens/admin/MAdminAddonManager';
|
|
import { useAddonStore } from '../../../../src/store/addonStore';
|
|
import { useAuthStore } from '../../../../src/store/authStore';
|
|
import { useSettingsStore } from '../../../../src/store/settingsStore';
|
|
import { buildSettings } from '../../../helpers/factories';
|
|
import { server } from '../../../helpers/msw/server';
|
|
import { render, screen, waitFor } from '../../../helpers/render';
|
|
import { resetAllStores, seedStore } from '../../../helpers/store';
|
|
|
|
// FE-ATLAS2-REST-050 to 052: the Atlas ranking row under the Atlas addon on the phone admin screen.
|
|
|
|
const RANKING = 'Ranking and profiles';
|
|
|
|
function atlasAddon(enabled: boolean) {
|
|
return { id: 'atlas', name: 'Atlas', description: 'World map', icon: 'Globe', type: 'trip', enabled };
|
|
}
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
seedStore(useSettingsStore, { settings: buildSettings({ dark_mode: false }) });
|
|
useAuthStore.setState({ atlasCompareEnabled: false });
|
|
vi.spyOn(useAddonStore.getState(), 'loadAddons').mockResolvedValue(undefined);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('MAdminAddonManager: Atlas ranking', () => {
|
|
it('FE-ATLAS2-REST-050: an enabled Atlas shows the ranking switch, off as the app config says', async () => {
|
|
server.use(http.get('/api/admin/addons', () => HttpResponse.json({ addons: [atlasAddon(true)] })));
|
|
render(<MAdminAddonManager />);
|
|
const toggle = await screen.findByRole('switch', { name: RANKING });
|
|
expect(toggle).toHaveAttribute('aria-checked', 'false');
|
|
});
|
|
|
|
it('FE-ATLAS2-REST-051: the switch stays away while Atlas itself is off', async () => {
|
|
server.use(http.get('/api/admin/addons', () => HttpResponse.json({ addons: [atlasAddon(false)] })));
|
|
render(<MAdminAddonManager />);
|
|
await waitFor(() => expect(screen.getAllByRole('switch').length).toBeGreaterThan(0));
|
|
expect(screen.queryByRole('switch', { name: RANKING })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-ATLAS2-REST-052: flipping it saves atlas_compare_enabled and shows it on', async () => {
|
|
const user = userEvent.setup();
|
|
const bodies: unknown[] = [];
|
|
server.use(
|
|
http.get('/api/admin/addons', () => HttpResponse.json({ addons: [atlasAddon(true)] })),
|
|
http.put('/api/auth/app-settings', async ({ request }) => {
|
|
bodies.push(await request.json());
|
|
return HttpResponse.json({ success: true });
|
|
})
|
|
);
|
|
render(<MAdminAddonManager />);
|
|
await user.click(await screen.findByRole('switch', { name: RANKING }));
|
|
await waitFor(() => expect(bodies).toEqual([{ atlas_compare_enabled: true }]));
|
|
await waitFor(() => expect(screen.getByRole('switch', { name: RANKING })).toHaveAttribute('aria-checked', 'true'));
|
|
expect(useAuthStore.getState().atlasCompareEnabled).toBe(true);
|
|
});
|
|
});
|