This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into andarist/fix-app-remounting
# Conflicts: # src/App.tsx # src/AppHead.tsx # src/authMachine.ts # src/pages/[sourceFileId].tsx # src/pages/_app.tsx # src/sourceMachine.ts # tsconfig.json
- Loading branch information
Showing
31 changed files
with
1,039 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'xstate-viz-app': minor | ||
--- | ||
|
||
Embedded Mode! | ||
|
||
The visualizer/inspector can now be used in the embedded mode. In this mode, some parts of the application can be configured such as control buttons, panning, zooming, etc. | ||
The most important parameter to configure embedded mode it the `mode` that can be one of `viz`, `full` or `panels`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"xstate-viz-app": patch | ||
--- | ||
|
||
When you press visualize, machines will now automatically 'fit to view'. This prevents various bugs around state machines appearing not to be visible, when they're actually just off screen. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.next/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import { GetSourceFileSsrQuery } from '../../src/graphql/GetSourceFileSSR.generated'; | ||
|
||
const SOURCE_ID = 'source-file-id'; | ||
|
||
const getSSRParam = ( | ||
data: Partial<GetSourceFileSsrQuery['getSourceFile']> & { id: string }, | ||
) => { | ||
return encodeURIComponent(JSON.stringify({ data, id: data.id })); | ||
}; | ||
|
||
describe('Embedded mode', () => { | ||
describe('default (mode:viz)', () => { | ||
before(() => { | ||
cy.interceptGraphQL({ | ||
getSourceFile: { | ||
id: SOURCE_ID, | ||
text: ` | ||
import { createModel } from "xstate/lib/model"; | ||
import { createMachine } from "xstate"; | ||
createMachine({ | ||
id: "simple", | ||
states: { | ||
a: {}, | ||
b: {}, | ||
}, | ||
}); | ||
`, | ||
}, | ||
}); | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}`, | ||
); | ||
}); | ||
it('panels should be hidden', () => { | ||
cy.getPanelsView().should('be.hidden'); | ||
}); | ||
it('zoom and pan buttons group should be hidden', () => { | ||
cy.getControlButtons().should('not.exist'); | ||
}); | ||
it('canvas header should be hidden', () => { | ||
cy.getCanvasHeader().should('not.exist'); | ||
}); | ||
}); | ||
|
||
describe('mode:panels', () => { | ||
beforeEach(() => { | ||
cy.interceptGraphQL({ | ||
getSourceFile: { | ||
id: SOURCE_ID, | ||
text: ` | ||
import { createModel } from "xstate/lib/model"; | ||
import { createMachine } from "xstate"; | ||
createMachine({ | ||
id: "simple", | ||
states: { | ||
a: {}, | ||
b: {}, | ||
}, | ||
}); | ||
`, | ||
}, | ||
}); | ||
}); | ||
it('should show panels view', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels`, | ||
); | ||
cy.getPanelsView().should('be.visible'); | ||
}); | ||
it('should show CODE panel by default', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels`, | ||
); | ||
cy.findByRole('tab', { name: /code/i }).should( | ||
'have.attr', | ||
'aria-selected', | ||
'true', | ||
); | ||
cy.getMonacoEditor().should('be.visible'); | ||
}); | ||
it('code editor should be readonly', () => { | ||
const editor = cy.getMonacoEditor(); | ||
editor.type('something'); | ||
editor.within(() => | ||
cy.findByText(/cannot edit in read-only editor/i).should('be.visible'), | ||
); | ||
}); | ||
it('an original link to the visualizer should be shown', () => { | ||
cy.findByRole('link', { name: /open in stately\.ai\/viz/i }) | ||
.should('be.visible') | ||
.should(($a) => | ||
$a | ||
.attr('href') | ||
?.includes('/viz/c75ccdc4-418d-4ade-9059-90f0fc4ddbd1'), | ||
); | ||
}); | ||
it('should be able to make code editor editable', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels&readOnly=0`, | ||
); | ||
const editor = cy.getMonacoEditor(); | ||
editor.type('something'); | ||
editor.contains('something'); | ||
}); | ||
it('should be able to choose active panel', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels&panel=state`, | ||
); | ||
cy.findByRole('tab', { name: /state/i }).should( | ||
'have.attr', | ||
'aria-selected', | ||
'true', | ||
); | ||
cy.getStatePanel().should('be.visible'); | ||
}); | ||
it('should be able to hide the original link', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels&showOriginalLink=0`, | ||
); | ||
cy.findByRole('link', { name: /open in stately\.ai\/viz/i }).should( | ||
'not.exist', | ||
); | ||
}); | ||
it('the visualize button should be hidden', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels`, | ||
); | ||
cy.contains('button', /visualize/i).should('not.exist'); | ||
}); | ||
it('the visualize button should be shown if readOnly is disabled', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels&readOnly=0`, | ||
); | ||
cy.findByRole('button', { name: /visualize/i }).should('be.visible'); | ||
}); | ||
it('the "New" and "Login to fork" should be hidden', () => { | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=panels`, | ||
); | ||
[/new/i, /login to fork/i].forEach((text) => { | ||
cy.contains('button', text).should('not.exist'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('mode:full', () => { | ||
before(() => { | ||
cy.interceptGraphQL({ | ||
getSourceFile: { | ||
id: SOURCE_ID, | ||
text: ` | ||
import { createModel } from "xstate/lib/model"; | ||
import { createMachine } from "xstate"; | ||
createMachine({ | ||
id: "simple", | ||
states: { | ||
a: {}, | ||
b: {}, | ||
}, | ||
}); | ||
`, | ||
}, | ||
}); | ||
cy.visit( | ||
`/viz/embed/${SOURCE_ID}?ssr=${getSSRParam({ | ||
id: SOURCE_ID, | ||
})}&mode=full`, | ||
); | ||
}); | ||
it('should show both canvas and panels', () => { | ||
cy.getCanvasGraph().should('be.visible'); | ||
cy.getPanelsView().should('be.visible'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.