Fixes failing test #122

This commit is contained in:
Jonathan Hornung 2025-08-16 18:21:01 +02:00
commit a74eec74ee

View file

@ -22,7 +22,7 @@ beforeEach(async () => {
afterEach(async () => { afterEach(async () => {
// console.log('Messages:', JSON.stringify(messages, null, 2)); // console.log('Messages:', JSON.stringify(messages, null, 2));
const testName = expect.getState().currentTestName; const testName = expect.getState().currentTestName;
console.log(`[${testName}] Messages:`, JSON.stringify(messages.map(({text}) => text), null, 2)); console.log(`[${testName}] Messages:`, JSON.stringify(messages.map(({ text }) => text), null, 2));
const errors = messages.filter(msg => const errors = messages.filter(msg =>
msg.type === 'error' && msg.type === 'error' &&
@ -33,13 +33,13 @@ afterEach(async () => {
}); });
function loadSrc(src) { function loadSrc(src) {
return page.goto(baseUrl + '#src=' + encodeURIComponent(src)); return page.goto(`${baseUrl}#src=${encodeURIComponent(src)}`);
} }
function loadPath(path) { function loadPath(path) {
return page.goto(baseUrl + '#path=' + encodeURIComponent(path)); return page.goto(`${baseUrl}#path=${encodeURIComponent(path)}`);
} }
function loadUrl(url) { function loadUrl(url) {
return page.goto(baseUrl + '#url=' + encodeURIComponent(url)); return page.goto(`${baseUrl}#url=${encodeURIComponent(url)}`);
} }
async function waitForViewer() { async function waitForViewer() {
await page.waitForSelector('model-viewer'); await page.waitForSelector('model-viewer');
@ -63,19 +63,34 @@ function expect3DManifold() {
} }
function waitForCustomizeButton() { function waitForCustomizeButton() {
return page.waitForFunction(() => { return page.waitForFunction(() => {
const buttons = document.querySelectorAll('input[role=switch]'); // Try multiple selectors for PrimeReact components
for (const button of buttons) { // ToggleButton might render as button or input elements
if (button.parentElement.innerText === 'Customize') { const selectors = [
return button; 'input[role=switch]',
'button',
'[role=tab]',
'.p-togglebutton',
'.p-tabmenu-nav a'
];
for (const selector of selectors) {
const elements = document.querySelectorAll(selector);
for (const element of elements) {
const text = element.textContent || element.innerText || '';
const parentText = element.parentElement?.textContent || element.parentElement?.innerText || '';
if (text.includes('Customize') || parentText.includes('Customize')) {
return element;
} }
} }
}); }
return null;
}, { timeout: 45000 }); // Increase timeout to 45 seconds
} }
function waitForLabel(text) { function waitForLabel(text) {
return page.waitForFunction((text) => { return page.waitForFunction(() => {
return Array.from(document.querySelectorAll('label')).find(el => el.textContent === 'myVar'); return Array.from(document.querySelectorAll('label')).find(el => el.textContent === 'myVar');
// return Array.from(document.querySelectorAll('label')).find(el => el.textContent === text); // return Array.from(document.querySelectorAll('label')).find(el => el.textContent === text);
}, {}, text); });
} }
describe('e2e', () => { describe('e2e', () => {
@ -128,8 +143,17 @@ describe('e2e', () => {
].join('\r\n')); ].join('\r\n'));
await waitForViewer(); await waitForViewer();
expect3DPolySet(); expect3DPolySet();
// Wait for syntax checking to complete and parameters to be detected
await page.waitForFunction(() => {
// Look for any indication that parameters have been processed
const messages = Array.from(document.querySelectorAll('*')).map(el => el.textContent || '').join(' ');
return messages.includes('myVar') || messages.includes('Customize');
}, { timeout: 30000 });
await (await waitForCustomizeButton()).click(); await (await waitForCustomizeButton()).click();
await page.waitForSelector('fieldset'); await page.waitForSelector('fieldset');
await waitForLabel('myVar'); await waitForLabel('myVar');
}, longTimeout); }, longTimeout);
}); });