Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions e2e-tests/tests/visuals/sd-export-reimport.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { test, expect } from '@playwright/test';
import fs from 'fs';
import path from 'path';
import config from '../../test-config';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve missing test-config import

The new visual spec imports ../../test-config, but there is no test-config module anywhere under e2e-tests (verified with find e2e-tests -maxdepth 3 -type f -name 'test-config.*'), so loading the spec will throw Cannot find module '../../test-config' before any tests execute. The suite cannot run until the config file is added or the import path corrected.

Useful? React with 👍 / 👎.


const APP_URL = process.env.SUPERDOC_E2E_APP_URL ?? 'http://localhost:4173/';
const ROUND_TRIP_EXPORT_DIR = './test-results/sd-export-reimport';
const IGNORED_DOCUMENTS = [
'advanced-tables',
'msa-list-base-indent',
'custom-list-numbering',
'sdpr',
'ooxml-rFonts-rstyle-linked-combos-demo',
'ooxml-color-rstyle-linked-combos-demo',
'ooxml-underline-rstyle-linked-combos-demo',
'table-of-contents',
'table-of-contents-sdt',
'tiny-spacing', // FIXME: exportDocx returns undefined for this doc
];

const documents = fs
.readdirSync(config.basicDocumentsFolder)
.filter((name) => !config.ignoreDocuments.includes(name))
.filter((name) => /\.docx$/i.test(name))
.map((name) => ({
fileName: name,
baseName: name.replace(/\.docx$/i, ''),
}))
.filter(({ baseName }) => !IGNORED_DOCUMENTS.includes(baseName));

const ensureDir = (dir) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
};

const waitForEditorReady = async (page) => {
const superEditor = page.locator('div.super-editor').first();
await expect(superEditor).toBeVisible({ timeout: 10_000 });
await page.waitForFunction(
() => {
const superdoc = window.superdoc ?? window.superdocdev;
const editor = superdoc?.activeEditor ?? window.editor;
return superdoc !== undefined && editor !== undefined && typeof editor.exportDocx === 'function';
},
null,
{ polling: 100, timeout: 10_000 },
);
await page.evaluate(() => {
const superdoc = window.superdoc ?? window.superdocdev;
if (superdoc) {
window.superdoc = superdoc;
window.editor = superdoc.activeEditor;
}
});
};

const uploadDocument = async (page, filePath) => {
await page.locator('input[type="file"]').setInputFiles(filePath);
await waitForEditorReady(page);
};

const exportDocxAsBuffer = async (page) => {
const serialized = await page.evaluate(async () => {
const superdoc = window.superdoc ?? window.superdocdev;
const activeEditor = superdoc?.activeEditor ?? window.editor;
if (!activeEditor || typeof activeEditor.exportDocx !== 'function') {
throw new Error('Active editor with exportDocx is not available.');
}
const blob = await activeEditor.exportDocx({
isFinalDoc: true,
});
const arrayBuffer = await blob.arrayBuffer();
return Array.from(new Uint8Array(arrayBuffer));
});

return Buffer.from(serialized);
};

ensureDir(ROUND_TRIP_EXPORT_DIR);

test.describe('SD x SD export (visual)', () => {
for (const document of documents) {
test(document.fileName, async ({ page }) => {
test.setTimeout(60_000);

await page.goto(APP_URL);
await uploadDocument(page, path.join(config.basicDocumentsFolder, document.fileName));

const exportedDocx = await exportDocxAsBuffer(page);
const exportedDocPath = path.join(ROUND_TRIP_EXPORT_DIR, `${document.baseName}-roundtrip.docx`);
fs.writeFileSync(exportedDocPath, exportedDocx);

await page.goto(APP_URL);
await uploadDocument(page, exportedDocPath);

await expect(page).toHaveScreenshot({
name: `${document.baseName}.png`,
fullPage: true,
timeout: 30_000,
});
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one correct @priya-harbour ? it seems like it's empty, just to confirm we're not missing anything here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @chittolinag , No, I am updating the screenshots, so I will ping you once everything is ready

Loading