test: add badge interaction test + README; ignore disabled tests in Playwright config
This commit is contained in:
114
tests/event_badge_interaction.test.ts
Normal file
114
tests/event_badge_interaction.test.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
|
||||
|
||||
const testEventId = 'pjrcghqwert';
|
||||
|
||||
test.describe('Event Badge - interaction', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
page.on('pageerror', (err) => console.error(`BROWSER ERROR: ${err.message}`));
|
||||
page.on('console', (msg) => {
|
||||
if (msg.type() === 'error' || msg.type() === 'warn')
|
||||
console.error(`BROWSER [${msg.type().toUpperCase()}]: ${msg.text()}`);
|
||||
});
|
||||
|
||||
await page.route('**/v3/**', async (route) => {
|
||||
const req = route.request();
|
||||
const url = req.url();
|
||||
|
||||
if (url.includes('site_domain/search')) {
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ data: [{ id: 'test-site-domain-id', site_id: 'test-site-id', account_id: '_XY7DXtc9MY' }] })
|
||||
});
|
||||
}
|
||||
|
||||
if (url.includes(`/v3/crud/event/${testEventId}`) && req.method() === 'GET') {
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ data: {
|
||||
id: testEventId,
|
||||
event_id: testEventId,
|
||||
name: 'Test Event for Badge Interaction',
|
||||
cfg_json: {},
|
||||
mod_pres_mgmt_json: {},
|
||||
mod_badges_json: {},
|
||||
mod_abstracts_json: {},
|
||||
mod_exhibits_json: {},
|
||||
mod_meetings_json: {}
|
||||
} })
|
||||
});
|
||||
}
|
||||
|
||||
if (url.includes(`/v3/crud/event/${testEventId}/event_badge`) && req.method() === 'POST') {
|
||||
const post = await req.postData();
|
||||
console.log('Captured POST to event_badge endpoint:', url, post ? post.slice(0,200) : '');
|
||||
const body = post ? JSON.parse(post) : {};
|
||||
const created = { ...body, event_badge_id: 'new-badge-1' };
|
||||
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: created }) });
|
||||
}
|
||||
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||
});
|
||||
|
||||
page.on('dialog', async (dialog) => {
|
||||
await dialog.accept();
|
||||
});
|
||||
|
||||
await page.addInitScript(
|
||||
({ defaults, eventId }) => {
|
||||
const testData = {
|
||||
...defaults,
|
||||
account_id: '_XY7DXtc9MY',
|
||||
manager_access: true,
|
||||
administrator_access: true,
|
||||
edit_mode: true,
|
||||
mod: { ...defaults.mod, events: { ...defaults.mod.events, event_id: eventId } }
|
||||
};
|
||||
window.localStorage.setItem('ae_loc', JSON.stringify(testData));
|
||||
},
|
||||
{ defaults: ae_app_local_data_defaults, eventId: testEventId }
|
||||
);
|
||||
});
|
||||
|
||||
test('creates a badge via UI and posts to nested endpoint', async ({ page }) => {
|
||||
await page.goto(`/events/${testEventId}/settings`);
|
||||
|
||||
const addBtn = page.getByRole('button', { name: 'Add New Badge' });
|
||||
await expect(addBtn).toBeVisible();
|
||||
await addBtn.click();
|
||||
|
||||
const form = page.locator('form:has-text("Create Badge")');
|
||||
await expect(form).toBeVisible();
|
||||
|
||||
const fullNameInput = form.locator('label:has-text("Full Name Override") input');
|
||||
await expect(fullNameInput).toBeVisible();
|
||||
await fullNameInput.fill('Test User');
|
||||
|
||||
const emailInput = form.locator('label:has-text("Email") input');
|
||||
await emailInput.fill('testuser@example.com');
|
||||
|
||||
const select = form.locator('label:has-text("Badge Type") select');
|
||||
await select.selectOption('test');
|
||||
|
||||
const checkbox = form.locator('label:has-text("Allow Tracking") input[type="checkbox"]');
|
||||
await checkbox.check();
|
||||
|
||||
const [request] = await Promise.all([
|
||||
page.waitForRequest((r) => r.url().includes(`/v3/crud/event/${testEventId}/event_badge`) && r.method() === 'POST'),
|
||||
page.getByRole('button', { name: 'Create Badge' }).click()
|
||||
]);
|
||||
|
||||
const postBody = request.postData();
|
||||
const postJson = postBody ? JSON.parse(postBody) : {};
|
||||
expect(postJson.email).toBe('testuser@example.com');
|
||||
expect(postJson.full_name_override).toBe('Test User');
|
||||
|
||||
const response = await page.waitForResponse((r) => r.url().includes(`/v3/crud/event/${testEventId}/event_badge`) && (r.status() === 201 || r.status() === 200));
|
||||
const respJson = await response.json();
|
||||
expect(respJson).toBeDefined();
|
||||
expect(respJson.data).toBeDefined();
|
||||
expect(respJson.data.event_badge_id).toBe('new-badge-1');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user