Files
tilbudgivern/tests/smart-pakker-integration.spec.js

102 lines
4.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// @ts-check
const { test, expect } = require('@playwright/test');
const BASE_URL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:4032';
async function loginIfNeeded(page) {
const loginHeading = page.getByRole('heading', { name: /Log ind/i });
const isLogin = await loginHeading.isVisible().catch(() => false);
if (!isLogin) return;
const username = 'toemrer';
const password = process.env.AUTH_PASSWORD;
await page.locator('input[type="text"]').first().fill(username);
await page.locator('input[type="password"]').first().fill(password);
await page.getByRole('button', { name: /Log ind/i }).click();
await page.waitForTimeout(1500);
}
test.describe('Smart Pakker & Opgaver Integration', () => {
test('Access Smart Pakker menu and verify dashboard', async ({ page }) => {
await page.goto(BASE_URL + '/');
await page.waitForLoadState('networkidle');
await loginIfNeeded(page);
console.log('\n📦 Testing Smart Pakker & Opgaver Menu\n');
// Look for Smart Pakker button (may be labeled as "Smart Pakker & Opgaver")
const smartPakkerBtn = page.getByRole('button', { name: /Smart Pakker|📦/i });
const btnVisible = await smartPakkerBtn.isVisible().catch(() => false);
console.log(` ${btnVisible ? '✅' : '❌'} Smart Pakker menu button found: ${btnVisible}`);
if (btnVisible) {
await smartPakkerBtn.click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(500);
// Check if dashboard loaded
const pageText = await page.locator('body').textContent();
const hasPakker = pageText.toLowerCase().includes('smart pakke') ||
pageText.toLowerCase().includes('pakker');
console.log(` ${hasPakker ? '✅' : '⚠️'} Smart Pakker content loaded: ${hasPakker}`);
// Look for test package 229
const testPakkeFound = pageText.toLowerCase().includes('test pakke');
console.log(` ${testPakkeFound ? '✅' : '⚠️'} Test package found: ${testPakkeFound}`);
}
expect(btnVisible).toBeTruthy();
console.log('\n✅ Smart Pakker menu test passed\n');
});
test('Access Opgaver (Tasks) menu', async ({ page }) => {
await page.goto(BASE_URL + '/');
await page.waitForLoadState('networkidle');
await loginIfNeeded(page);
console.log('\n📋 Testing Opgaver Menu\n');
// Click Smart Pakker first
const smartPakkerBtn = page.getByRole('button', { name: /Smart Pakker|📦/i });
const btnVisible = await smartPakkerBtn.isVisible().catch(() => false);
if (btnVisible) {
await smartPakkerBtn.click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(500);
// Look for Opgaver menu item (may be a ListItem, not just button)
const opgaverItem = page.locator('text=/Opgaver|📋/i');
const opgaverVisible = await opgaverItem.isVisible().catch(() => false);
console.log(` ${opgaverVisible ? '✅' : '❌'} Opgaver menu item found: ${opgaverVisible}`);
if (opgaverVisible) {
// Click on the Opgaver item
await opgaverItem.click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(500);
const opgaverText = await page.locator('body').textContent();
const hasOpgaver = opgaverText.toLowerCase().includes('opgaver') ||
opgaverText.toLowerCase().includes('forberedelse') ||
opgaverText.toLowerCase().includes('montering');
console.log(` ${hasOpgaver ? '✅' : '⚠️'} Opgaver content loaded: ${hasOpgaver}`);
// Look for test tasks
const testTaskFound = opgaverText.toLowerCase().includes('forberedelse');
console.log(` ${testTaskFound ? '✅' : '⚠️'} Test task found: ${testTaskFound}`);
expect(opgaverVisible).toBeTruthy();
} else {
console.log(' Opgaver menu not found, checking if tasks are loaded in current view...');
const pageText = await page.locator('body').textContent();
const hasOpgaver = pageText.toLowerCase().includes('forberedelse');
console.log(` ${hasOpgaver ? '✅' : '⚠️'} Tasks data present: ${hasOpgaver}`);
}
}
console.log('\n✅ Opgaver menu test passed\n');
});
});