feat(badges): labeled align-text-in-box section and Ctrl+Z/Ctrl+Y shortcuts

Replace the cryptic single-letter text alignment buttons with a labeled 'Align text in box' section (horizontal + vertical icon groups); make wrapped text honor textAlign via full-width span; add undo/redo keyboard shortcuts (Ctrl/Cmd+Z, Ctrl+Y, Ctrl/Cmd+Shift+Z) gated behind the typing guard; 7 new e2e tests (20 total).
This commit is contained in:
Lago committed 2026-10-16 07:57:50 +02:00
1 parent ab25c102dc
commit 6b277a2a67
3 files changed
+156 -18

No files matched your search

+95
View File
@@ -136,6 +136,33 @@ test('the Delete key removes the selected element', async ({ page }) => {
await expect(page.locator('.badge-el')).toHaveCount(1);
});
test('Ctrl+Z undoes and Ctrl+Y redoes element changes', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
await page.getByRole('button', { name: 'Text', exact: true }).click();
await expect(page.locator('.badge-el')).toHaveCount(3);
await page.keyboard.press('Control+z');
await expect(page.locator('.badge-el')).toHaveCount(2);
await page.keyboard.press('Control+y');
await expect(page.locator('.badge-el')).toHaveCount(3);
// Ctrl+Shift+Z is accepted as an alternative redo.
await page.keyboard.press('Control+z');
await page.keyboard.press('Control+Shift+z');
await expect(page.locator('.badge-el')).toHaveCount(3);
});
test('Ctrl+Z is ignored while typing in a panel field', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
await page.locator('.badge-el').first().click();
await page.getByRole('button', { name: 'Text', exact: true }).click();
await expect(page.locator('.badge-el')).toHaveCount(3);
// Focus a text input so the native field undo wins and the editor stays put.
await page.getByLabel('x (mm)').click();
await page.keyboard.press('Control+z');
await expect(page.locator('.badge-el')).toHaveCount(3);
});
test('a text box can bind the company / organizer field', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
@@ -181,3 +208,71 @@ test('dragging near the page centre shows a smart guide and snaps', async ({ pag
// After snapping, the QR centre sits on the page centre (x = 50 - w/2 = 39mm).
await expect(page.getByLabel('x (mm)')).toHaveValue('39');
});
test('the text panel exposes a labelled "Align text in box" section', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
await page.locator('.badge-el').first().click();
await expect(page.getByText('Align text in box', { exact: true })).toBeVisible();
await expect(page.getByText('Horizontal', { exact: true })).toBeVisible();
await expect(page.getByText('Vertical', { exact: true })).toBeVisible();
// The default layout text box starts left/middle, so those buttons are pressed.
await expect(page.getByRole('button', { name: 'Align text left' })).toHaveAttribute('aria-pressed', 'true');
await expect(page.getByRole('button', { name: 'Center text vertically' })).toHaveAttribute('aria-pressed', 'true');
});
test('aligning text right inside its box updates the rendered text', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
await page.locator('.badge-el').first().click();
const body = page.locator('.badge-text-body').first();
await expect(body).toHaveCSS('justify-content', 'flex-start');
await page.getByRole('button', { name: 'Align text right' }).click();
await expect(body).toHaveCSS('justify-content', 'flex-end');
await expect(body).toHaveCSS('text-align', 'right');
await expect(page.getByRole('button', { name: 'Align text right' })).toHaveAttribute('aria-pressed', 'true');
await expect(page.getByRole('button', { name: 'Align text left' })).toHaveAttribute('aria-pressed', 'false');
});
test('aligning text to the bottom of its box updates the rendered text', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page);
await page.locator('.badge-el').first().click();
const body = page.locator('.badge-text-body').first();
await expect(body).toHaveCSS('align-items', 'center');
await page.getByRole('button', { name: 'Align text to bottom' }).click();
await expect(body).toHaveCSS('align-items', 'flex-end');
});
test('text alignment inside the box persists through save', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
const { saves } = await openBadgeEditor(page);
await page.locator('.badge-el').first().click();
await page.getByRole('button', { name: 'Center text', exact: true }).click();
await page.getByRole('button', { name: 'Align text to top' }).click();
await page.getByRole('button', { name: 'Save' }).click();
await expect.poll(() => saves.length).toBe(1);
const elements = saves[0].p_elements as Record<string, unknown>[];
expect(elements[0]).toMatchObject({ id: 'e-text', align_h: 'center', align_v: 'top' });
});
test('text alignment survives a reload of the saved layout', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openBadgeEditor(page, {
layouts: [{
id: 'l-default', event_id: eventId, name: 'Default', is_default: true,
page_width_mm: 100, page_height_mm: 70, created_at: '2026-10-23T10:00:00Z', updated_at: '2026-10-23T10:00:00Z',
elements: [
{ id: 'e-text', type: 'text', x: 10, y: 10, width: 60, height: 30, rotation: 0, content: 'static', text: 'Hello', font: 'Open Sans', font_size: 13, line_height: 1, color: '#000000', bold: false, italic: false, align_h: 'right', align_v: 'bottom', transform: 'none' },
],
}],
});
await page.locator('.badge-el').first().click();
await expect(page.getByRole('button', { name: 'Align text right' })).toHaveAttribute('aria-pressed', 'true');
await expect(page.getByRole('button', { name: 'Align text to bottom' })).toHaveAttribute('aria-pressed', 'true');
const body = page.locator('.badge-text-body').first();
await expect(body).toHaveCSS('justify-content', 'flex-end');
await expect(body).toHaveCSS('align-items', 'flex-end');
await expect(body).toHaveCSS('text-align', 'right');
});