Copy the Chatwoot (v4.14.0) frontend runnable subset into frontend/ for customization: - app/javascript/ (Vue SPA: dashboard, widget, sdk, portal, superadmin) - app/views/ (ERB templates for vite-plugin-ruby entrypoint resolution) - app/helpers/, app/assets/ (Rails view helpers, static assets) - enterprise/ (Enterprise edition frontend overlay) - config/vite.json, vite.config.ts, bin/vite (Vite-Rails toolchain) - package.json, pnpm-lock.yaml, tailwind/postcss/eslint configs - Gemfile, Gemfile.lock (vite_rails gem for bin/vite binstub) Excluded Rails backend: controllers, models, services, jobs, mailers, policies, db, lib, spec, public, node_modules. Update references to the new frontend location: - .gitignore: exclude frontend build artifacts (node_modules, tmp, packs), keep frontend/bin/ and frontend/vendor/ via negation - backend/scripts/parity_frontend_smoke.sh: CHATWOOT_DIR default reference/chatwoot -> ../frontend - backend/scripts/parity_frontend_browser_smoke.mjs: same default update - AGENTS.md: add frontend section with Rails/Vite coupling notes - README: architecture tree includes frontend/
164 lines
4.5 KiB
JavaScript
164 lines
4.5 KiB
JavaScript
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
|
|
import ActionCableConnector from '../actionCable';
|
|
|
|
vi.mock('shared/helpers/mitt', () => ({
|
|
emitter: {
|
|
emit: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock('dashboard/composables/useImpersonation', () => ({
|
|
useImpersonation: () => ({
|
|
isImpersonating: { value: false },
|
|
}),
|
|
}));
|
|
|
|
global.chatwootConfig = {
|
|
websocketURL: 'wss://test.chatwoot.com',
|
|
};
|
|
|
|
describe('ActionCableConnector - Copilot Tests', () => {
|
|
let store;
|
|
let actionCable;
|
|
let mockDispatch;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockDispatch = vi.fn();
|
|
store = {
|
|
$store: {
|
|
dispatch: mockDispatch,
|
|
getters: {
|
|
getCurrentAccountId: 1,
|
|
'accounts/isFeatureEnabledonAccount': vi.fn(() => true),
|
|
},
|
|
},
|
|
};
|
|
|
|
actionCable = ActionCableConnector.init(store.$store, 'test-token');
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
describe('copilot event handlers', () => {
|
|
it('should register the copilot.message.created event handler', () => {
|
|
expect(Object.keys(actionCable.events)).toContain(
|
|
'copilot.message.created'
|
|
);
|
|
expect(actionCable.events['copilot.message.created']).toBe(
|
|
actionCable.onCopilotMessageCreated
|
|
);
|
|
});
|
|
|
|
it('should handle the copilot.message.created event through the ActionCable system', () => {
|
|
const copilotData = {
|
|
id: 2,
|
|
content: 'This is a copilot message from ActionCable',
|
|
conversation_id: 456,
|
|
created_at: '2025-05-27T15:58:04-06:00',
|
|
account_id: 1,
|
|
};
|
|
actionCable.onReceived({
|
|
event: 'copilot.message.created',
|
|
data: copilotData,
|
|
});
|
|
expect(mockDispatch).toHaveBeenCalledWith(
|
|
'copilotMessages/upsert',
|
|
copilotData
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('conversation unread count event handlers', () => {
|
|
it('should register the conversation.unread_count_changed event handler', () => {
|
|
expect(Object.keys(actionCable.events)).toContain(
|
|
'conversation.unread_count_changed'
|
|
);
|
|
expect(actionCable.events['conversation.unread_count_changed']).toBe(
|
|
actionCable.onConversationUnreadCountChanged
|
|
);
|
|
});
|
|
|
|
it('should refetch unread counts when unread count changes', () => {
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
expect(mockDispatch).toHaveBeenCalledWith('conversationUnreadCounts/get');
|
|
});
|
|
|
|
it('does not refetch unread counts when unread count feature is disabled', () => {
|
|
store.$store.getters[
|
|
'accounts/isFeatureEnabledonAccount'
|
|
].mockReturnValue(false);
|
|
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
expect(mockDispatch).not.toHaveBeenCalledWith(
|
|
'conversationUnreadCounts/get'
|
|
);
|
|
});
|
|
|
|
it('should throttle unread count refetches for repeated events', () => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
|
|
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
expect(mockDispatch).toHaveBeenCalledTimes(1);
|
|
|
|
vi.advanceTimersByTime(4999);
|
|
expect(mockDispatch).toHaveBeenCalledTimes(1);
|
|
|
|
vi.advanceTimersByTime(1);
|
|
expect(mockDispatch).toHaveBeenCalledTimes(2);
|
|
expect(mockDispatch).toHaveBeenLastCalledWith(
|
|
'conversationUnreadCounts/get'
|
|
);
|
|
});
|
|
|
|
it('clears pending unread count refetch before immediate refetch', () => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
|
|
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
vi.advanceTimersByTime(1000);
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
vi.setSystemTime(new Date('2026-01-01T00:00:06Z'));
|
|
actionCable.onReceived({
|
|
event: 'conversation.unread_count_changed',
|
|
data: { account_id: 1 },
|
|
});
|
|
|
|
expect(mockDispatch).toHaveBeenCalledTimes(2);
|
|
|
|
vi.advanceTimersByTime(4000);
|
|
expect(mockDispatch).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|
|
});
|