Test loading demo by path

This commit is contained in:
ochafik 2024-12-25 13:58:44 +00:00 • committed by Olivier Chafik
commit 58a513dd11
3 changed files with 18 additions and 4 deletions

View file

@ -57,6 +57,10 @@ export async function readStateFromFragment(): Promise<State | null> {
// For testing // For testing
const src = decodeURIComponent(serialized.substring('src:'.length)); const src = decodeURIComponent(serialized.substring('src:'.length));
return createInitialState(null, src); return createInitialState(null, src);
} else if (serialized.startsWith('testpath:')) {
// For testing
const path = decodeURIComponent(serialized.substring('testpath:'.length));
return createInitialState(null, '...', path);
} }
let obj; let obj;
try { try {

View file

@ -6,7 +6,7 @@ import { State } from './app-state';
export const defaultSourcePath = '/playground.scad'; export const defaultSourcePath = '/playground.scad';
export const defaultModelColor = '#f9d72c'; export const defaultModelColor = '#f9d72c';
export function createInitialState(state: State | null, content: string = defaultScad): State { export function createInitialState(state: State | null, content = defaultScad, activePath = defaultSourcePath): State {
type Mode = State['view']['layout']['mode']; type Mode = State['view']['layout']['mode'];
const mode: Mode = window.matchMedia("(min-width: 768px)").matches const mode: Mode = window.matchMedia("(min-width: 768px)").matches
@ -14,8 +14,8 @@ export function createInitialState(state: State | null, content: string = defaul
const initialState: State = { const initialState: State = {
params: { params: {
activePath: defaultSourcePath, activePath: activePath,
sources: [{path: defaultSourcePath, content}], sources: [{path: activePath, content}],
features: [], features: [],
exportFormat2D: 'svg', exportFormat2D: 'svg',
exportFormat3D: 'glb', exportFormat3D: 'glb',

View file

@ -21,7 +21,8 @@ beforeEach(async () => {
afterEach(async () => { afterEach(async () => {
// console.log('Messages:', JSON.stringify(messages, null, 2)); // console.log('Messages:', JSON.stringify(messages, null, 2));
console.log('Messages:', JSON.stringify(messages.map(({text}) => text), null, 2)); const testName = expect.getState().currentTestName;
console.log(`[${testName}] Messages:`, JSON.stringify(messages.map(({text}) => text), null, 2));
const errors = messages.filter(msg => const errors = messages.filter(msg =>
msg.type === 'error' && msg.type === 'error' &&
@ -34,6 +35,9 @@ afterEach(async () => {
function loadSrc(src) { function loadSrc(src) {
return page.goto(url + '#src:' + encodeURIComponent(src)); return page.goto(url + '#src:' + encodeURIComponent(src));
} }
function loadPath(path) {
return page.goto(url + '#testpath:' + encodeURIComponent(path));
}
async function waitForViewer() { async function waitForViewer() {
await page.waitForSelector('model-viewer'); await page.waitForSelector('model-viewer');
await page.waitForFunction(() => { await page.waitForFunction(() => {
@ -102,6 +106,12 @@ describe('e2e', () => {
expect3DManifold(); expect3DManifold();
}, longTimeout); }, longTimeout);
test('load a demo by path', async () => {
await loadPath('/libraries/closepoints/demo_3D_art.scad');
await waitForViewer();
expect3DPolySet();
}, longTimeout);
test('customizer & windows line endings work', async () => { test('customizer & windows line endings work', async () => {
await loadSrc([ await loadSrc([
'myVar = 10;', 'myVar = 10;',