mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat(database): assign and mention identities behind a field option - Collaborator fields get `include_identities` and long text fields `long_text_include_identities`, both off by default. - With the option on, active identities of the workspace can be assigned or suggested as mentions; they are shown with their icon and renamed in realtime, and they never receive notifications. - Turning the collaborator option off backs up the column, deletes the identity assignments and strips identities from the view defaults, so the update can be undone. - Identities can author row comments and be mentioned in them. - Exports write an identity as `Name <identity>`. * refactor: hide internal emails in collaborator exports through one check * fix: import a personal view only for a person, without a query per owner * fix: show collaborator identities with the icon of the user subject type * refactor: drop a redundant local import of the core handler * fix: unify identity icons and space field options * fix: keep identity field menus and saved mentions readable * fix: limit identity mention suggestions to row comments * perf: prefetch available collaborators once per workspace * fix: use workspace members as authors of generated rows * fix: resolve linked collaborator values by member email * fix: use workspace collaborators for field pickers and paste * refactor: move identity avatar styles to the avatar stylesheet * fix: address review feedback on identity collaborators
286 lines
8.8 KiB
JavaScript
286 lines
8.8 KiB
JavaScript
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import RowEditFieldRichText from '@baserow/modules/database/components/row/RowEditFieldRichText'
|
|
import RichTextEditor from '@baserow/modules/core/components/editor/RichTextEditor.vue'
|
|
|
|
describe('RowEditFieldRichText component', () => {
|
|
let testApp = null
|
|
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
})
|
|
|
|
const field = {
|
|
id: 1,
|
|
name: 'Notes',
|
|
order: 0,
|
|
type: 'long_text',
|
|
primary: false,
|
|
long_text_enable_rich_text: true,
|
|
_: { loading: false },
|
|
}
|
|
|
|
const mountComponent = (props = {}) =>
|
|
testApp.mount(RowEditFieldRichText, {
|
|
props: {
|
|
field,
|
|
value: '**bold** text',
|
|
readOnly: false,
|
|
workspaceId: 10,
|
|
...props,
|
|
},
|
|
global: {
|
|
stubs: {
|
|
RichTextEditorBubbleMenu: true,
|
|
RichTextEditorFloatingMenu: true,
|
|
},
|
|
},
|
|
})
|
|
|
|
const userFileName = `${'a'.repeat(32)}_${'b'.repeat(64)}.png`
|
|
|
|
const uploadedUserFile = {
|
|
size: 3,
|
|
mime_type: 'image/png',
|
|
is_image: true,
|
|
image_width: 1,
|
|
image_height: 1,
|
|
uploaded_at: '2026-09-25T10:00:00Z',
|
|
url: `http://localhost:8000/media/user_files/${userFileName}`,
|
|
thumbnails: {
|
|
tiny: {
|
|
url: `http://localhost:8000/media/thumbnails/tiny/${userFileName}`,
|
|
width: null,
|
|
height: 21,
|
|
},
|
|
small: {
|
|
url: `http://localhost:8000/media/thumbnails/small/${userFileName}`,
|
|
width: 48,
|
|
height: 48,
|
|
},
|
|
card_cover: {
|
|
url: `http://localhost:8000/media/thumbnails/card_cover/${userFileName}`,
|
|
width: 300,
|
|
height: 160,
|
|
},
|
|
},
|
|
name: userFileName,
|
|
original_name: 'screenshot.png',
|
|
}
|
|
|
|
const settleUploads = async () => {
|
|
for (let i = 0; i < 10; i += 1) {
|
|
await new Promise((resolve) => setTimeout(resolve))
|
|
}
|
|
}
|
|
|
|
const pasteImage = async (wrapper) => {
|
|
const file = new File(['png'], 'screenshot.png', { type: 'image/png' })
|
|
await wrapper.find('.tiptap').trigger('paste', {
|
|
clipboardData: {
|
|
getData: () => '',
|
|
types: ['Files'],
|
|
items: [{ kind: 'file', type: file.type, getAsFile: () => file }],
|
|
},
|
|
})
|
|
await settleUploads()
|
|
}
|
|
|
|
test('renders the stored Markdown value as rich content', async () => {
|
|
const wrapper = await mountComponent()
|
|
|
|
expect(wrapper.find('.tiptap strong').text()).toBe('bold')
|
|
expect(wrapper.find('.tiptap').attributes('contenteditable')).toBe('true')
|
|
})
|
|
|
|
test('saves the serialized Markdown on blur', async () => {
|
|
const wrapper = await mountComponent()
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
await wrapper.find('.tiptap').trigger('keydown', { key: 'Enter' })
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
const emitted = wrapper.emitted('update')
|
|
expect(emitted).toHaveLength(1)
|
|
const [newValue, oldValue] = emitted[0]
|
|
expect(oldValue).toBe('**bold** text')
|
|
expect(typeof newValue).toBe('string')
|
|
expect(newValue).not.toBe(oldValue)
|
|
expect(newValue).toContain('**bold**')
|
|
})
|
|
|
|
test('does not save when the content did not change', async () => {
|
|
const wrapper = await mountComponent()
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update')).toBeUndefined()
|
|
})
|
|
|
|
test('does not rewrite an untouched legacy value on blur', async () => {
|
|
// This value reserializes differently (' \n' hard break), so a save would rewrite it.
|
|
const wrapper = await mountComponent({ value: 'Line one\nLine two' })
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update')).toBeUndefined()
|
|
})
|
|
|
|
test('renders read-only when the field is not editable', async () => {
|
|
const wrapper = await mountComponent({ readOnly: true })
|
|
|
|
expect(wrapper.find('.tiptap').attributes('contenteditable')).toBe('false')
|
|
})
|
|
|
|
test('keeps the value without throwing when the editor ref is gone', async () => {
|
|
const wrapper = await mountComponent()
|
|
// The child editor unmounts before the modal-close blur reaches beforeSave.
|
|
wrapper.vm.$refs.input = null
|
|
|
|
expect(() => wrapper.vm.beforeSave()).not.toThrow()
|
|
expect(wrapper.vm.beforeSave()).toBe('**bold** text')
|
|
})
|
|
|
|
test('uploads a pasted image and saves its reference on blur', async () => {
|
|
testApp.mock.onPost('/user-files/upload-file/').reply(200, uploadedUserFile)
|
|
const wrapper = await mountComponent()
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
await pasteImage(wrapper)
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(testApp.mock.history.post.map((request) => request.url)).toEqual([
|
|
'/user-files/upload-file/',
|
|
])
|
|
const [[newValue]] = wrapper.emitted('update')
|
|
expect(newValue).toContain(`![screenshot][${userFileName}]`)
|
|
})
|
|
|
|
test('saves an image whose upload finishes after the field lost focus', async () => {
|
|
let finishUpload
|
|
testApp.mock.onPost('/user-files/upload-file/').reply(
|
|
() =>
|
|
new Promise((resolve) => {
|
|
finishUpload = () => resolve([200, uploadedUserFile])
|
|
})
|
|
)
|
|
const wrapper = await mountComponent()
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
await pasteImage(wrapper)
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update')).toBeUndefined()
|
|
|
|
finishUpload()
|
|
await settleUploads()
|
|
|
|
const updates = wrapper.emitted('update')
|
|
expect(updates).toHaveLength(1)
|
|
expect(updates[0][0]).toContain(`![screenshot][${userFileName}]`)
|
|
})
|
|
|
|
test('leaves saving to the blur when the upload finishes while editing', async () => {
|
|
testApp.mock.onPost('/user-files/upload-file/').reply(200, uploadedUserFile)
|
|
const wrapper = await mountComponent()
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
editor.vm.$emit('focus')
|
|
await pasteImage(wrapper)
|
|
|
|
expect(wrapper.emitted('update')).toBeUndefined()
|
|
|
|
editor.vm.$emit('blur')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update')).toHaveLength(1)
|
|
})
|
|
|
|
describe('mentions and images', () => {
|
|
beforeEach(async () => {
|
|
await testApp.store.dispatch('workspace/forceCreate', {
|
|
id: 10,
|
|
name: 'Workspace',
|
|
users: [{ user_id: 5, name: 'Jane Doe' }],
|
|
identities: [{ id: 30, name: 'Ops', user_type: 'identity' }],
|
|
})
|
|
})
|
|
|
|
test('offers workspace mentions and image uploads by default', async () => {
|
|
const wrapper = await mountComponent({ value: 'ping @5' })
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
expect(wrapper.find('.tiptap .rich-text-editor__mention').exists()).toBe(
|
|
true
|
|
)
|
|
expect(editor.props('enableImages')).toBe(true)
|
|
expect(editor.props('uploadFile')).toBeInstanceOf(Function)
|
|
})
|
|
|
|
test('renders a saved identity name when identity suggestions are off', async () => {
|
|
const wrapper = await mountComponent({ value: 'Ask @30' })
|
|
|
|
expect(wrapper.get('.rich-text-editor__mention').text()).toBe('@Ops')
|
|
})
|
|
|
|
test('keeps mentions and images off when disabled', async () => {
|
|
testApp.mock
|
|
.onPost('/user-files/upload-file/')
|
|
.reply(200, uploadedUserFile)
|
|
const wrapper = await mountComponent({
|
|
value: 'ping @5',
|
|
enableMentions: false,
|
|
enableImages: false,
|
|
})
|
|
const editor = wrapper.findComponent(RichTextEditor)
|
|
|
|
expect(wrapper.find('.tiptap .rich-text-editor__mention').exists()).toBe(
|
|
false
|
|
)
|
|
expect(wrapper.find('.tiptap').text()).toBe('ping @5')
|
|
expect(editor.props('mentionableUsers')).toBeNull()
|
|
expect(editor.props('enableImages')).toBe(false)
|
|
expect(editor.props('uploadFile')).toBeNull()
|
|
|
|
await pasteImage(wrapper)
|
|
|
|
expect(testApp.mock.history.post).toHaveLength(0)
|
|
})
|
|
})
|
|
|
|
test.each([{ readOnly: true }, { allowImageUpload: false }])(
|
|
'does not upload a pasted image when %s',
|
|
async (props) => {
|
|
testApp.mock
|
|
.onPost('/user-files/upload-file/')
|
|
.reply(200, uploadedUserFile)
|
|
const wrapper = await mountComponent(props)
|
|
|
|
await pasteImage(wrapper)
|
|
|
|
expect(testApp.mock.history.post).toHaveLength(0)
|
|
expect(wrapper.find('.tiptap img').exists()).toBe(false)
|
|
}
|
|
)
|
|
test('opens an empty editor for a value of the previous field type', async () => {
|
|
const wrapper = await mountComponent({ value: [{ id: 1, value: 'row' }] })
|
|
|
|
expect(wrapper.findComponent(RichTextEditor).props('modelValue')).toBe('')
|
|
})
|
|
})
|