enso/app/gui2/stories/MockProjectStoreWrapper.vue
Ilya Bogdanov f96e5dddd6
e2e tests for collapsing and entering nodes (#8758)
Related to https://github.com/enso-org/enso/issues/8518

These tests already caught one regression in nav breadcrumbs: https://github.com/enso-org/enso/issues/8756

It also provides API for mocking expression updates for arbitrary nodes on the screen. The implementation is a bit convoluted and includes setting a callback on `window`, but it looks like the only possible solution given our architecture and playwright restrictions.
2024-01-18 13:45:18 +00:00

38 lines
1.1 KiB
Vue

<script setup lang="ts">
import { useProjectStore } from '@/stores/project'
import { useObserveYjs } from '@/util/crdt'
import { computed, watchEffect } from 'vue'
const props = defineProps<{ modelValue: string }>()
const emit = defineEmits<{ 'update:modelValue': [modelValue: string] }>()
const projectStore = useProjectStore()
const mod = projectStore.projectModel.createNewModule('Main.enso')
projectStore.setObservedFileName('Main.enso')
mod.doc.ydoc.emit('load', [])
function applyEdits(module: NonNullable<typeof projectStore.module>, newText: string) {
module.transact(() => {
projectStore.module?.doc.setCode(newText)
})
}
watchEffect(() => projectStore.module && applyEdits(projectStore.module, props.modelValue))
const data = computed(() => projectStore.module?.doc.data)
const text = computed(() => projectStore.module?.doc.getCode())
useObserveYjs(data, () => {
if (text.value) {
const newValue = text.value?.toString()
if (newValue !== props.modelValue) {
emit('update:modelValue', newValue)
}
}
})
</script>
<template>
<slot></slot>
</template>