Files
it-tools/src/tools/integer-base-converter/integer-base-converter.e2e.spec.ts
T
Robert Dobre 4379630758 feat(integer base converter): bit fields (#605)
Read single bits and bit fields (ranges) of the input number:
- positions as a list: 2, 12, 4-7, 7:4 (0 = LSB); invalid, negative,
  duplicate or too large positions are skipped and reported
- interactive bit strip: click to toggle a bit, drag or Shift+click to
  add a field, keyboard navigation with arrow keys
- results table with click to copy, overlap hints and optional field
  values in hex, octal, base64, a custom base and decimal
- positions and selected bases are kept in the URL and local storage
2026-11-29 21:47:18 +01:00

68 lines
2.8 KiB
TypeScript

import { expect, test } from '@playwright/test';
test.describe('Tool - Integer base converter - Bit fields', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/base-converter?num=0x1234');
});
test('Extracts single bits and fields', async ({ page }) => {
await page.getByTestId('bit-positions').fill('2, 12, 7:4, 5');
const rows = page.getByTestId('bit-fields-results').locator('tbody tr');
await expect(rows).toHaveCount(4);
await expect(rows.nth(0)).toContainText('bit 2');
await expect(rows.nth(0)).toContainText('1');
await expect(rows.nth(2)).toContainText('bits 7..4');
await expect(rows.nth(2)).toContainText('0011');
await expect(rows.nth(3)).toContainText('also in 7..4');
});
test('Shows the selected bases for fields only', async ({ page }) => {
await page.getByTestId('bit-positions').fill('2, 7:4');
await page.getByTestId('bit-fields-base-hex').click();
await page.getByTestId('bit-fields-base-dec').click();
const header = page.getByTestId('bit-fields-results').locator('thead');
await expect(header).toContainText('Hex');
await expect(header).toContainText('Dec');
const fieldRow = page.getByTestId('bit-fields-results').locator('tbody tr').nth(1);
await expect(fieldRow).toContainText('0x3');
});
test('Ignores invalid positions and reports them', async ({ page }) => {
await page.getByTestId('bit-positions').fill('2, -3, abc');
await expect(page.getByTestId('bit-positions-ignored')).toContainText('"-3" (negative)');
await expect(page.getByTestId('bit-positions-ignored')).toContainText('"abc" (not a position)');
await expect(page.getByTestId('bit-fields-results').locator('tbody tr')).toHaveCount(1);
});
test('Selects bits and fields on the strip', async ({ page }) => {
const positions = page.getByTestId('bit-positions');
await positions.fill('');
await page.locator('[data-bit="2"]').click();
await expect(positions).toHaveValue('2');
const from = await page.locator('[data-bit="11"]').boundingBox();
const to = await page.locator('[data-bit="8"]').boundingBox();
if (!from || !to) {
throw new Error('Bits are not visible');
}
await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2);
await page.mouse.down();
await page.mouse.move(to.x + to.width / 2, to.y + to.height / 2, { steps: 5 });
await page.mouse.up();
await expect(positions).toHaveValue('2, 8-11');
await page.locator('[data-bit="2"]').click();
await expect(positions).toHaveValue('8-11');
});
test('Clears all positions', async ({ page }) => {
await page.getByTestId('bit-positions').fill('2, 4-7');
await page.getByRole('button', { name: 'Clear all' }).click();
await expect(page.getByTestId('bit-positions')).toHaveValue('');
});
});