Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import Mentions from './Mentions.vue';

describe('Mentions.vue rendering', () => {
let wrapper: ReturnType<typeof mount> | undefined;
let documentMousedown: ReturnType<typeof vi.fn> | undefined;

afterEach(() => {
wrapper?.unmount();
if (documentMousedown) document.removeEventListener('mousedown', documentMousedown);
});

it('keeps the user row mounted through the first click', () => {
const user = { name: 'Alice', email: 'alice@example.com', role: 'editor' };
const insertMention = vi.fn();
documentMousedown = vi.fn();
document.addEventListener('mousedown', documentMousedown);

wrapper = mount(Mentions, {
props: {
users: [user],
insertMention,
},
});

const row = wrapper.get('.user-row');
const mousedown = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
row.element.dispatchEvent(mousedown);

expect(mousedown.defaultPrevented).toBe(true);
expect(documentMousedown).not.toHaveBeenCalled();

row.element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
expect(insertMention).toHaveBeenCalledOnce();
expect(insertMention).toHaveBeenCalledWith(user);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const props = defineProps({
type: String,
default: '',
},
inserMention: {
insertMention: {
type: Function,
required: true,
},
Expand All @@ -33,7 +33,7 @@ const getFilteredUsers = computed(() => {
});

const handleClick = (user) => {
props.inserMention(user);
props.insertMention(user);
};

const handleKeydown = (event) => {
Expand All @@ -50,7 +50,7 @@ const handleKeydown = (event) => {
} else if (event.key === 'Enter') {
const user = getFilteredUsers.value[activeUserIndex.value];
if (user) {
props.inserMention(user);
props.insertMention(user);
}
}
};
Expand All @@ -70,6 +70,7 @@ const handleFocus = () => {
>
<div
v-for="(user, index) in getFilteredUsers"
@mousedown.stop.prevent
@click.stop.prevent="handleClick(user)"
@mouseenter="activeUserIndex = index"
@mouseleave="activeUserIndex = null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Popover {
props: {
users: this.editor.users,
mention: atMention,
inserMention: (user) => {
insertMention: (user) => {
const { $from } = this.state.selection;
const length = atMention.length;
const attributes = { ...user };
Expand Down
Loading