mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-05 02:44:36 +03:00
feat(xml-diff): add XML diff tool
Compare two pasted XML documents and highlight the differences, mirroring the JSON diff tool's UI and diff engine. XML is parsed with a native DOMParser-based normalizer (attributes as @name, text-only leaves as plain strings) instead of xml-js, and a reconciliation step coerces mismatched single/repeated element shapes into arrays before diffing so a repeated element compares cleanly instead of producing a garbled type-mismatch diff. From PR #1840 Fix #1839 Co-Authored-By: @sharevb Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
authored and
1 parent
5bbc672017
commit
e8f0677f94
29 files changed
+761
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - XML diff', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/xml-diff');
|
||||
});
|
||||
|
||||
test('Has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('XML diff - IT Tools');
|
||||
});
|
||||
|
||||
test('Identical XMLs have a custom result message', async ({ page }) => {
|
||||
await page.getByTestId('leftXml').fill('<foo><bar>baz</bar></foo>');
|
||||
await page.getByTestId('rightXml').fill('<foo>\n <bar>baz</bar>\n</foo>');
|
||||
|
||||
const result = await page.getByTestId('diff-result').innerText();
|
||||
|
||||
expect(result).toContain('The provided XMLs are the same');
|
||||
});
|
||||
|
||||
test('Different XMLs have differences listed', async ({ page }) => {
|
||||
await page.getByTestId('leftXml').fill('<root foo="bar"/>');
|
||||
await page.getByTestId('rightXml').fill('<root foo="buz" baz="qux"/>');
|
||||
|
||||
const result = await page.getByTestId('diff-result').innerText();
|
||||
|
||||
expect(result).toContain('{\n@foo: "bar""buz",\n@baz: "qux",\n},');
|
||||
});
|
||||
|
||||
test('Different XMLs have only differences listed when "Only show differences" is checked', async ({ page }) => {
|
||||
await page.getByTestId('leftXml').fill('<root foo="bar"/>');
|
||||
await page.getByTestId('rightXml').fill('<root foo="bar" baz="qux"/>');
|
||||
await page.getByRole('switch').click();
|
||||
|
||||
const result = await page.getByTestId('diff-result').innerText();
|
||||
|
||||
expect(result).toContain('{\n@baz: "qux",\n},');
|
||||
expect(result).not.toContain('foo');
|
||||
});
|
||||
|
||||
test('An element going from a single occurrence to several is diffed cleanly, not as a type change', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.getByTestId('leftXml').fill('<root><item>A</item></root>');
|
||||
await page.getByTestId('rightXml').fill('<root><item>A</item><item>B</item></root>');
|
||||
|
||||
const result = await page.getByTestId('diff-result').innerText();
|
||||
|
||||
expect(result).toContain('item: [\n"A",\n"B",\n],');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user