Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions e2e/farm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,16 @@ function makeMockPosition(lockedAtMs: number) {

async function seedPools(page: Page): Promise<void> {
await page.evaluate((pool) => {
const qc = (window as any).__queryClient;
if (qc) qc.setQueryData(['pools'], [pool]);
window.__e2e?.seedPools([pool]);
}, MOCK_POOL);
}

async function seedPosition(page: Page, lockedAtMs: number): Promise<void> {
const pos = makeMockPosition(lockedAtMs);
await page.evaluate(
({ pool, position, pubKey }) => {
const qc = (window as any).__queryClient;
if (!qc) return;
qc.setQueryData(['pools'], [pool]);
qc.setQueryData(['userPosition', 'all', pubKey], [{ pool, position }]);
window.__e2e?.seedPools([pool]);
window.__e2e?.seedPositions(pubKey, [{ pool, position }]);
},
{ pool: MOCK_POOL, position: pos, pubKey: TEST_PUBLIC_KEY },
);
Expand Down Expand Up @@ -350,8 +347,6 @@ test.describe('Farm E2E', () => {
// After success, update cache to show 0 stake
await page.evaluate(
({ pool, pubKey }) => {
const qc = (window as any).__queryClient;
if (!qc) return;
const emptyPos = {
user: pubKey,
poolId: 'pool-xlm',
Expand All @@ -361,7 +356,7 @@ test.describe('Farm E2E', () => {
isLocked: false,
unlockableAt: 0,
};
qc.setQueryData(['userPosition', 'all', pubKey], [{ pool, position: emptyPos }]);
window.__e2e?.seedPositions(pubKey, [{ pool, position: emptyPos }]);
},
{ pool: MOCK_POOL, pubKey: TEST_PUBLIC_KEY },
);
Expand Down
16 changes: 16 additions & 0 deletions e2e/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { E2ESeedApi } from "../src/lib/e2eSeed";

declare global {
interface Window {
/**
* Installed by `src/context/index.tsx` in development and when
* NEXT_PUBLIC_E2E=true, which is what the Playwright config sets.
*
* Specs seed through this rather than through the QueryClient, so the query
* keys live in one place: `src/lib/e2eSeed.ts`.
*/
__e2e?: E2ESeedApi;
}
}

export {};
13 changes: 4 additions & 9 deletions e2e/lock-unlock-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,15 @@ function makeMockPosition(lockedAtMs: number, amount = '10.0000000') {

async function seedPools(page: Page): Promise<void> {
await page.evaluate((pool) => {
const qc = (window as any).__queryClient;
if (qc) qc.setQueryData(['pools'], [pool]);
window.__e2e?.seedPools([pool]);
}, MOCK_POOL);
}

async function seedPosition(page: Page, lockedAtMs: number): Promise<void> {
await page.evaluate(
({ pool, position, pubKey }) => {
const qc = (window as any).__queryClient;
if (!qc) return;
qc.setQueryData(['pools'], [pool]);
qc.setQueryData(['userPosition', 'all', pubKey], [{ pool, position }]);
window.__e2e?.seedPools([pool]);
window.__e2e?.seedPositions(pubKey, [{ pool, position }]);
},
{ pool: MOCK_POOL, position: makeMockPosition(lockedAtMs), pubKey: TEST_PUBLIC_KEY },
);
Expand All @@ -202,9 +199,7 @@ async function seedPosition(page: Page, lockedAtMs: number): Promise<void> {
async function seedEmptyPosition(page: Page): Promise<void> {
await page.evaluate(
({ pool, position, pubKey }) => {
const qc = (window as any).__queryClient;
if (!qc) return;
qc.setQueryData(['userPosition', 'all', pubKey], [{ pool, position }]);
window.__e2e?.seedPositions(pubKey, [{ pool, position }]);
},
{ pool: MOCK_POOL, position: makeMockPosition(0, '0.0000000'), pubKey: TEST_PUBLIC_KEY },
);
Expand Down
Loading