const { test, expect } = require('@playwright/test'); const BuildCalculatorPage = require('../pages/buildCalculatorPage'); const { Website } = require('../helpers/website'); test.describe('Build Calculator', () => { let website; test.beforeEach(({ page }) => { website = new Website(page); }); test('Add entities via keyboard Q, W, E with Q\'Rath/Orzum', async ({ page }) => { const calc = website.buildCalculatorPage; await calc.goto(); await calc.filter.selectFaction("Q'Rath"); await calc.filter.selectImmortal('Orzum'); await calc.hotkeys.clickKey('TAB'); const keyNames = { Q: 'q', W: 'w', E: 'e', TAB: 'Tab' }; for (const key of ['Q', 'W', 'E', 'TAB']) { const entityNames = await calc.hotkeys.getEntityNamesOnKey(key); if (entityNames.length === 0) continue; await page.keyboard.press(keyNames[key]); const viewName = await calc.entityView.getEntityName(); expect(viewName).toBeTruthy(); expect(entityNames).toContain(viewName); } }); test('Add entities via hotkeys TAB, Q, W, E with Q\'Rath/Orzum', async ({ page }) => { const calc = website.buildCalculatorPage; await calc.goto(); await calc.filter.selectFaction("Q'Rath"); await calc.filter.selectImmortal('Orzum'); for (const key of ['TAB', 'Q', 'W', 'E']) { const entityNames = await calc.hotkeys.getEntityNamesOnKey(key); if (entityNames.length === 0) continue; await calc.hotkeys.clickKey(key); const viewName = await calc.entityView.getEntityName(); expect(viewName).toBeTruthy(); expect(entityNames).toContain(viewName); } }); test('Add Acropolis via Q, verify entity view and timeline, then clear', async ({ page }) => { const calc = website.buildCalculatorPage; await calc.goto(); const buttons = page.locator('.keyContainer > div > div'); console.log('Initial Q button text:', await buttons.filter({ hasText: /^Q/ }).first().textContent()); // Wait for Blazor re-render to complete by waiting for the button text to stabilize // (it goes from QAcropolis → empty during re-render → back to QAcropolis) let tries = 0; let text = ''; while (tries < 20) { await page.waitForTimeout(500); try { text = (await buttons.filter({ hasText: /^Q/ }).first().textContent() || '').trim(); if (text && text.length > 1) break; } catch { } tries++; } console.log(`After Blazor render (${(tries+1)*0.5}s): Q button text: ${JSON.stringify(text)}`); await calc.filter.selectFaction("Q'Rath"); await calc.filter.selectImmortal('Orzum'); await page.waitForTimeout(1000); console.log('After filter Q button text:', await buttons.filter({ hasText: /^Q/ }).first().textContent()); expect(await calc.timeline.containsEntity('Acropolis')).toBe(false); await calc.hotkeys.clickKey('Q'); await page.waitForTimeout(1000); expect(await calc.entityView.getEntityName()).toBe('Acropolis'); expect(await calc.timeline.containsEntity('Acropolis')).toBe(true); await calc.clickClearBuildOrder(); await page.waitForTimeout(1000); expect(await calc.timeline.containsEntity('Acropolis')).toBe(false); expect(await calc.entityView.getEntityName()).toBeNull(); }); test('Missing Requirements toast when building Soul Foundry without Legion Hall', async ({ page }) => { const calc = website.buildCalculatorPage; await calc.goto(); await calc.filter.selectFaction("Q'Rath"); await calc.filter.selectImmortal('Orzum'); await calc.hotkeys.clickKey('E'); const hasToast = await calc.toast.hasToastContaining('Missing Requirements'); expect(hasToast).toBe(true); }); test('Not Enough Ether toast when building Soul Foundry after Legion Hall', async ({ page }) => { const calc = website.buildCalculatorPage; await calc.goto(); await calc.filter.selectFaction("Q'Rath"); await calc.filter.selectImmortal('Orzum'); await calc.hotkeys.clickKey('W'); await calc.hotkeys.clickKey('E'); const hasToast = await calc.toast.hasToastContaining('Not Enough Ether'); expect(hasToast).toBe(true); }); });