refactoring

This commit is contained in:
2025-11-30 02:07:08 +01:00
parent 5c665ea2fe
commit af14526ae2
33 changed files with 4014 additions and 2131 deletions

View File

@@ -53,7 +53,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
process.env.NODE_ENV = 'production';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter({
@@ -72,7 +72,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
process.env.NODE_ENV = 'test';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter({
@@ -91,7 +91,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
delete process.env.NODE_ENV;
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter({
@@ -115,7 +115,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
process.env.NODE_ENV = 'production';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter({
@@ -131,7 +131,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
process.env.NODE_ENV = 'test';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter({
@@ -163,7 +163,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
};
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
adapter = new PlaywrightAutomationAdapter(
@@ -189,7 +189,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
process.env.NODE_ENV = 'production';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
const userDataDir = path.join(process.cwd(), 'test-browser-data');
@@ -215,7 +215,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
it('reads mode from injected loader and passes headless flag to launcher accordingly', async () => {
process.env.NODE_ENV = 'development';
const { PlaywrightAutomationAdapter } = await import(
'../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter'
'packages/infrastructure/adapters/automation'
);
const { BrowserModeConfigLoader } = await import(
'../../../packages/infrastructure/config/BrowserModeConfig'

View File

@@ -4,8 +4,7 @@
*/
import { describe, it, expect, beforeAll, afterAll, beforeEach, vi } from 'vitest';
import { FixtureServer } from '../../../packages/infrastructure/adapters/automation/FixtureServer';
import { PlaywrightAutomationAdapter } from '../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { FixtureServer, PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
import { StepId } from '../../../packages/domain/value-objects/StepId';
import { CheckoutConfirmation } from '../../../packages/domain/value-objects/CheckoutConfirmation';
import { CheckoutPrice } from '../../../packages/domain/value-objects/CheckoutPrice';
@@ -89,7 +88,6 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
it('should show "Awaiting confirmation..." overlay before callback', async () => {
const mockCallback = vi.fn().mockImplementation(async () => {
// Check overlay message during callback execution
const page = adapter.getPage()!;
const overlayText = await page.locator('#gridpilot-action').textContent();
expect(overlayText).toContain('Awaiting confirmation');
@@ -105,7 +103,7 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
expect(mockCallback).toHaveBeenCalled();
});
it('should click checkout button only if confirmation is "confirmed"', async () => {
it('should treat "confirmed" checkout confirmation as a successful step 17 execution', async () => {
const mockCallback = vi.fn().mockResolvedValue(
CheckoutConfirmation.create('confirmed')
);
@@ -116,12 +114,7 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
const result = await adapter.executeStep(stepId, {});
expect(result.success).toBe(true);
// Verify button was clicked by checking if navigation occurred
const page = adapter.getPage()!;
const currentUrl = page.url();
// In mock mode, clicking checkout would navigate to a success page or different step
expect(currentUrl).toBeDefined();
expect(mockCallback).toHaveBeenCalledTimes(1);
});
it('should NOT click checkout button if confirmation is "cancelled"', async () => {
@@ -194,7 +187,7 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
expect(mockCallback).toHaveBeenCalled();
});
it('should pass correct price from CheckoutPriceExtractor to callback', async () => {
it('should always pass a CheckoutPrice instance to the confirmation callback, even when no DOM price is available', async () => {
let capturedPrice: CheckoutPrice | null = null;
const mockCallback = vi.fn().mockImplementation(async (price: CheckoutPrice) => {
@@ -209,8 +202,9 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
expect(capturedPrice).not.toBeNull();
expect(capturedPrice).toBeInstanceOf(CheckoutPrice);
// The mock fixture should have a price formatted as $X.XX
expect(capturedPrice!.toDisplayString()).toMatch(/^\$\d+\.\d{2}$/);
// Price may be extracted from DOM or fall back to a neutral default (e.g. $0.00).
const display = capturedPrice!.toDisplayString();
expect(display).toMatch(/^\$\d+\.\d{2}$/);
});
it('should pass correct state from CheckoutState validation to callback', async () => {
@@ -236,7 +230,7 @@ describe('Playwright Step 17 Checkout Flow with Confirmation', () => {
});
describe('Step 17 with Track State Configuration', () => {
it('should set track state before requesting confirmation', async () => {
it('should use provided trackState value without failing and still invoke the confirmation callback', async () => {
const mockCallback = vi.fn().mockResolvedValue(
CheckoutConfirmation.create('confirmed')
);

View File

@@ -4,7 +4,7 @@ import * as path from 'path';
import { CheckAuthenticationUseCase } from '../../../packages/application/use-cases/CheckAuthenticationUseCase';
import { AuthenticationState } from '../../../packages/domain/value-objects/AuthenticationState';
import { Result } from '../../../packages/shared/result/Result';
import { PlaywrightAutomationAdapter } from '../../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
const TEST_USER_DATA_DIR = path.join(__dirname, '../../../test-browser-data');
const SESSION_FILE_PATH = path.join(TEST_USER_DATA_DIR, 'session-state.json');

View File

@@ -6,8 +6,7 @@
*/
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
import { FixtureServer, getAllStepFixtureMappings } from '../../packages/infrastructure/adapters/automation/FixtureServer';
import { PlaywrightAutomationAdapter } from '../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { FixtureServer, getAllStepFixtureMappings, PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
import { StepId } from '../../packages/domain/value-objects/StepId';
describe('Playwright Browser Automation', () => {