Skip to content

Commit

Permalink
Test loading demo by path
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 25, 2024
1 parent 38745be commit e9277f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/state/fragment-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export async function readStateFromFragment(): Promise<State | null> {
// For testing
const src = decodeURIComponent(serialized.substring('src:'.length));
return createInitialState(null, src);
} else if (serialized.startsWith('testpath:')) {
// For testing
const path = decodeURIComponent(serialized.substring('testpath:'.length));
return createInitialState(null, '...', path);
}
let obj;
try {
Expand Down
6 changes: 3 additions & 3 deletions src/state/initial-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { State } from './app-state';
export const defaultSourcePath = '/playground.scad';
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'];
const mode: Mode = window.matchMedia("(min-width: 768px)").matches
? 'multi' : 'single';

const initialState: State = {
params: {
activePath: defaultSourcePath,
sources: [{path: defaultSourcePath, content}],
activePath: activePath,
sources: [{path: activePath, content}],
features: [],
exportFormat2D: 'svg',
exportFormat3D: 'glb',
Expand Down
12 changes: 11 additions & 1 deletion tests/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ beforeEach(async () => {

afterEach(async () => {
// 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 =>
msg.type === 'error' &&
Expand All @@ -34,6 +35,9 @@ afterEach(async () => {
function loadSrc(src) {
return page.goto(url + '#src:' + encodeURIComponent(src));
}
function loadPath(path) {
return page.goto(url + '#testpath:' + encodeURIComponent(path));
}
async function waitForViewer() {
await page.waitForSelector('model-viewer');
await page.waitForFunction(() => {
Expand Down Expand Up @@ -102,6 +106,12 @@ describe('e2e', () => {
expect3DManifold();
}, 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 () => {
await loadSrc([
'myVar = 10;',
Expand Down

0 comments on commit e9277f4

Please sign in to comment.