test(F7,F8): fix tab flag cache and entry alert specs
Reset the tab feature flag cache between DOM tests so one authenticated response cannot leak into fallback cases, and make the trade execution failure spec submit a valid executable order before asserting the backend error alert. This closes the documented pre-existing web test failures and restores the full Vitest suite to green. Refs: docs/AUDIT_REDESIGN.md items F7 and F8. Co-Authored-By: GPT-5 Codex <noreply@openai.com>
This commit is contained in:
parent
37ef0c2c3f
commit
ece7fa9504
@ -77,6 +77,7 @@ describe('EntryForm DOM flow', () => {
|
|||||||
|
|
||||||
render(<EntryForm onSuccess={onSuccess} />);
|
render(<EntryForm onSuccess={onSuccess} />);
|
||||||
await user.type(screen.getByPlaceholderText('BTC/USD'), 'BTC/USD');
|
await user.type(screen.getByPlaceholderText('BTC/USD'), 'BTC/USD');
|
||||||
|
await user.type(screen.getByPlaceholderText('0'), '1');
|
||||||
await user.click(screen.getByRole('checkbox', { name: /Execute/i }));
|
await user.click(screen.getByRole('checkbox', { name: /Execute/i }));
|
||||||
await user.click(screen.getByRole('button', { name: 'Add' }));
|
await user.click(screen.getByRole('button', { name: 'Add' }));
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// @vitest-environment jsdom
|
// @vitest-environment jsdom
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { renderHook, waitFor } from '@testing-library/react';
|
import { renderHook, waitFor } from '@testing-library/react';
|
||||||
import { useTabFeatureFlags } from './useTabFeatureFlags';
|
import { resetTabFeatureFlagsCacheForTests, useTabFeatureFlags } from './useTabFeatureFlags';
|
||||||
|
|
||||||
const { getPlatformAccessTokenMock } = vi.hoisted(() => ({
|
const { getPlatformAccessTokenMock } = vi.hoisted(() => ({
|
||||||
getPlatformAccessTokenMock: vi.fn<() => Promise<string>>(),
|
getPlatformAccessTokenMock: vi.fn<() => Promise<string>>(),
|
||||||
@ -15,14 +15,9 @@ vi.mock('../lib/runtime', () => ({
|
|||||||
tradingRuntime: { tradingApiUrl: 'http://localhost:4018' },
|
tradingRuntime: { tradingApiUrl: 'http://localhost:4018' },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Reset module-level cache between tests
|
|
||||||
vi.mock('./useTabFeatureFlags', async (importOriginal) => {
|
|
||||||
const mod = await importOriginal<typeof import('./useTabFeatureFlags')>();
|
|
||||||
return mod;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('useTabFeatureFlags DOM behaviour', () => {
|
describe('useTabFeatureFlags DOM behaviour', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
resetTabFeatureFlagsCacheForTests();
|
||||||
getPlatformAccessTokenMock.mockReset();
|
getPlatformAccessTokenMock.mockReset();
|
||||||
vi.stubGlobal('fetch', vi.fn());
|
vi.stubGlobal('fetch', vi.fn());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,6 +13,11 @@ const CACHE_TTL_MS = 30_000;
|
|||||||
let cachedFlags: TabFeatureFlags | null = null;
|
let cachedFlags: TabFeatureFlags | null = null;
|
||||||
let cachedAt = 0;
|
let cachedAt = 0;
|
||||||
|
|
||||||
|
export function resetTabFeatureFlagsCacheForTests(): void {
|
||||||
|
cachedFlags = null;
|
||||||
|
cachedAt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadTabFlags(): Promise<TabFeatureFlags> {
|
async function loadTabFlags(): Promise<TabFeatureFlags> {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (cachedFlags && now - cachedAt < CACHE_TTL_MS) {
|
if (cachedFlags && now - cachedAt < CACHE_TTL_MS) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user