wip
This commit is contained in:
@@ -22,7 +22,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as Parameters<Page['locator']>[0] extends string ? ReturnType<Page['locator']> : never);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -41,8 +41,8 @@ describe('AuthenticationGuard', () => {
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator)
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as any)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as any);
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -66,9 +66,9 @@ describe('AuthenticationGuard', () => {
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator)
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as any)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as any)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as any);
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -112,7 +112,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -125,7 +125,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockRejectedValue(new Error('Page not ready')),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const result = await guard.checkForLoginUI();
|
||||
|
||||
@@ -141,7 +141,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
await expect(guard.failFastIfUnauthenticated()).rejects.toThrow(
|
||||
'Authentication required: Login UI detected on page'
|
||||
@@ -154,7 +154,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
await expect(guard.failFastIfUnauthenticated()).resolves.toBeUndefined();
|
||||
});
|
||||
@@ -167,7 +167,9 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(
|
||||
mockLocator as unknown as ReturnType<Page['locator']>,
|
||||
);
|
||||
|
||||
await expect(guard.failFastIfUnauthenticated()).rejects.toThrow(
|
||||
'Authentication required: Login UI detected on page'
|
||||
@@ -181,7 +183,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockRejectedValue(new Error('Network timeout')),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
// Should not throw, checkForLoginUI catches errors
|
||||
await expect(guard.failFastIfUnauthenticated()).resolves.toBeUndefined();
|
||||
@@ -196,7 +198,7 @@ describe('AuthenticationGuard', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
vi.mocked(mockPage.content).mockResolvedValue(`
|
||||
<form action="/login">
|
||||
<button>Log in</button>
|
||||
@@ -226,9 +228,9 @@ describe('AuthenticationGuard', () => {
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator)
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as any)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as any)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as any);
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
vi.mocked(mockPage.content).mockResolvedValue(`
|
||||
<div class="dashboard">
|
||||
@@ -261,9 +263,9 @@ describe('AuthenticationGuard', () => {
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator)
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as any)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as any)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as any);
|
||||
.mockReturnValueOnce(mockNotLoggedInLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockLoginButtonLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockAriaLabelLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
vi.mocked(mockPage.content).mockResolvedValue(`
|
||||
<div class="authenticated-page">
|
||||
@@ -287,18 +289,20 @@ describe('AuthenticationGuard', () => {
|
||||
count: vi.fn().mockResolvedValue(1),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
// This method doesn't exist yet - will be added in GREEN phase
|
||||
const guard = new AuthenticationGuard(mockPage);
|
||||
|
||||
// Mock the method for testing purposes
|
||||
(guard as any).checkForAuthenticatedUI = async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
return userMenuCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as any).checkForAuthenticatedUI();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI =
|
||||
async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
return userMenuCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI();
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(mockPage.locator).toHaveBeenCalledWith('[data-testid="user-menu"]');
|
||||
@@ -313,20 +317,21 @@ describe('AuthenticationGuard', () => {
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator)
|
||||
.mockReturnValueOnce(mockUserMenuLocator as any)
|
||||
.mockReturnValueOnce(mockLogoutButtonLocator as any);
|
||||
.mockReturnValueOnce(mockUserMenuLocator as unknown as ReturnType<Page['locator']>)
|
||||
.mockReturnValueOnce(mockLogoutButtonLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
// Mock the method for testing purposes
|
||||
const guard = new AuthenticationGuard(mockPage);
|
||||
(guard as any).checkForAuthenticatedUI = async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
if (userMenuCount > 0) return true;
|
||||
|
||||
const logoutCount = await mockPage.locator('button:has-text("Log out")').count();
|
||||
return logoutCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as any).checkForAuthenticatedUI();
|
||||
(guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI =
|
||||
async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
if (userMenuCount > 0) return true;
|
||||
|
||||
const logoutCount = await mockPage.locator('button:has-text("Log out")').count();
|
||||
return logoutCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI();
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -336,17 +341,18 @@ describe('AuthenticationGuard', () => {
|
||||
count: vi.fn().mockResolvedValue(0),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
// Mock the method for testing purposes
|
||||
const guard = new AuthenticationGuard(mockPage);
|
||||
(guard as any).checkForAuthenticatedUI = async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
const logoutCount = await mockPage.locator('button:has-text("Log out")').count();
|
||||
return userMenuCount > 0 || logoutCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as any).checkForAuthenticatedUI();
|
||||
(guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI =
|
||||
async () => {
|
||||
const userMenuCount = await mockPage.locator('[data-testid="user-menu"]').count();
|
||||
const logoutCount = await mockPage.locator('button:has-text("Log out")').count();
|
||||
return userMenuCount > 0 || logoutCount > 0;
|
||||
};
|
||||
|
||||
const result = await (guard as unknown as { checkForAuthenticatedUI: () => Promise<boolean> }).checkForAuthenticatedUI();
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
@@ -17,7 +17,8 @@ import { ipcMain } from 'electron';
|
||||
describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
let mockWindow: BrowserWindow;
|
||||
let adapter: ElectronCheckoutConfirmationAdapter;
|
||||
let ipcMainOnCallback: ((event: any, decision: 'confirmed' | 'cancelled' | 'timeout') => void) | null = null;
|
||||
type IpcEventLike = { sender?: unknown };
|
||||
let ipcMainOnCallback: ((event: IpcEventLike, decision: 'confirmed' | 'cancelled' | 'timeout') => void) | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -26,7 +27,7 @@ describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
// Capture the IPC handler callback
|
||||
vi.mocked(ipcMain.on).mockImplementation((channel, callback) => {
|
||||
if (channel === 'checkout:confirm') {
|
||||
ipcMainOnCallback = callback as any;
|
||||
ipcMainOnCallback = callback as (event: IpcEventLike, decision: 'confirmed' | 'cancelled' | 'timeout') => void;
|
||||
}
|
||||
return ipcMain;
|
||||
});
|
||||
@@ -56,7 +57,7 @@ describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
// Simulate immediate confirmation via IPC
|
||||
setTimeout(() => {
|
||||
if (ipcMainOnCallback) {
|
||||
ipcMainOnCallback({} as any, 'confirmed');
|
||||
ipcMainOnCallback({} as IpcEventLike, 'confirmed');
|
||||
}
|
||||
}, 10);
|
||||
|
||||
@@ -90,7 +91,7 @@ describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
|
||||
setTimeout(() => {
|
||||
if (ipcMainOnCallback) {
|
||||
ipcMainOnCallback({} as any, 'confirmed');
|
||||
ipcMainOnCallback({} as IpcEventLike, 'confirmed');
|
||||
}
|
||||
}, 10);
|
||||
|
||||
@@ -115,7 +116,7 @@ describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
|
||||
setTimeout(() => {
|
||||
if (ipcMainOnCallback) {
|
||||
ipcMainOnCallback({} as any, 'cancelled');
|
||||
ipcMainOnCallback({} as IpcEventLike, 'cancelled');
|
||||
}
|
||||
}, 10);
|
||||
|
||||
@@ -168,7 +169,7 @@ describe('ElectronCheckoutConfirmationAdapter', () => {
|
||||
|
||||
// Confirm first request to clean up
|
||||
if (ipcMainOnCallback) {
|
||||
ipcMainOnCallback({} as any, 'confirmed');
|
||||
ipcMainOnCallback({} as IpcEventLike, 'confirmed');
|
||||
}
|
||||
|
||||
await promise1;
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('Wizard Dismissal Detection', () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
// Simulate the isWizardModalDismissed logic
|
||||
const isWizardModalDismissed = async (): Promise<boolean> => {
|
||||
@@ -63,7 +63,7 @@ describe('Wizard Dismissal Detection', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const isWizardModalDismissed = async (): Promise<boolean> => {
|
||||
const modalVisible = await mockPage.locator(modalSelector).isVisible().catch(() => false);
|
||||
@@ -92,7 +92,7 @@ describe('Wizard Dismissal Detection', () => {
|
||||
isVisible: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as any);
|
||||
vi.mocked(mockPage.locator).mockReturnValue(mockLocator as unknown as ReturnType<Page['locator']>);
|
||||
|
||||
const isWizardModalDismissed = async (): Promise<boolean> => {
|
||||
const modalVisible = await mockPage.locator(modalSelector).isVisible().catch(() => false);
|
||||
|
||||
Reference in New Issue
Block a user