Adds readOnly test for code

This commit is contained in:
Steve Ruiz 2021-06-25 12:05:29 +01:00
parent 0ee26a8493
commit 3c26ffaae3
2 changed files with 18 additions and 1 deletions

View file

@ -117,6 +117,19 @@ describe('selection', () => {
/* -------------------- Readonly -------------------- */
it('does not saves changes to code when readonly', () => {
null
state.send('CLEARED_PAGE')
expect(getShapes(state.data).length).toBe(0)
const code = `// hello world!`
state
.send('SAVED_CODE', { code })
.send('TOGGLED_READ_ONLY')
.send('SAVED_CODE', { code: '' })
expect(state.data.document.code[state.data.currentCodeFileId].code).toBe(
code
)
})
})

View file

@ -173,6 +173,7 @@ const state = createState({
else: ['zoomCameraToActual'],
},
on: {
TOGGLED_READ_ONLY: 'toggleReadOnly',
LOADED_FONTS: 'resetShapes',
USED_PEN_DEVICE: 'enablePenLock',
DISABLED_PEN_LOCK: 'disablePenLock',
@ -1121,6 +1122,9 @@ const state = createState({
},
},
actions: {
toggleReadOnly(data) {
data.isReadOnly = !data.isReadOnly
},
/* ---------------------- Pages --------------------- */
changePage(data, payload: { id: string }) {
commands.changePage(data, payload.id)