mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-04 11:55:24 +00:00
# Pull Request Template ## Description This PR will replace the usage of `agentMixin`with the utility helpers functions. **Files updated** 1. dashboard/components/widgets/conversation/contextMenu/Index.vue 2. dashboard/components/widgets/conversation/ConversationHeader.vue **(Not used)** 3. dashboard/routes/dashboard/commands/commandbar.vue 4. dashboard/routes/dashboard/conversation/ConversationAction.vue 5. dashboard/routes/dashboard/conversation/ConversationParticipant.vue Fixes https://linear.app/chatwoot/issue/CW-3442/rewrite-agentmixin-mixin-to-a-composable ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? **Test cases** 1. See agent list sorting based on availability, if agents are on the same status, then sorted by name. 2. Test actions like assigning/unassigning agent from conversation sidebar, CMD bar, Context menu. 3. Test actions like adding/removing participants from conversation sidebar. 4. See agent list is generated properly, none value. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
92 lines
3.0 KiB
JavaScript
92 lines
3.0 KiB
JavaScript
import { ref } from 'vue';
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { useAgentsList } from '../useAgentsList';
|
|
import { useMapGetter } from 'dashboard/composables/store';
|
|
import { allAgentsData, formattedAgentsData } from './fixtures/agentFixtures';
|
|
import * as agentHelper from 'dashboard/helper/agentHelper';
|
|
|
|
vi.mock('dashboard/composables/store');
|
|
vi.mock('dashboard/helper/agentHelper');
|
|
|
|
const mockUseMapGetter = (overrides = {}) => {
|
|
const defaultGetters = {
|
|
getCurrentUser: ref(allAgentsData[0]),
|
|
getSelectedChat: ref({ inbox_id: 1, meta: { assignee: true } }),
|
|
getCurrentAccountId: ref(1),
|
|
'inboxAssignableAgents/getAssignableAgents': ref(() => allAgentsData),
|
|
};
|
|
|
|
const mergedGetters = { ...defaultGetters, ...overrides };
|
|
|
|
useMapGetter.mockImplementation(getter => mergedGetters[getter]);
|
|
};
|
|
|
|
describe('useAgentsList', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
agentHelper.getAgentsByUpdatedPresence.mockImplementation(agents => agents);
|
|
agentHelper.getSortedAgentsByAvailability.mockReturnValue(
|
|
formattedAgentsData.slice(1)
|
|
);
|
|
agentHelper.getCombinedAgents.mockImplementation(
|
|
(agents, includeNone, isAgentSelected) => {
|
|
if (includeNone && isAgentSelected) {
|
|
return [agentHelper.createNoneAgent, ...agents];
|
|
}
|
|
return agents;
|
|
}
|
|
);
|
|
|
|
mockUseMapGetter();
|
|
});
|
|
|
|
it('returns agentsList and assignableAgents', () => {
|
|
const { agentsList, assignableAgents } = useAgentsList();
|
|
|
|
expect(assignableAgents.value).toEqual(allAgentsData);
|
|
expect(agentsList.value).toEqual([
|
|
agentHelper.createNoneAgent,
|
|
...formattedAgentsData.slice(1),
|
|
]);
|
|
});
|
|
|
|
it('includes None agent when includeNoneAgent is true', () => {
|
|
const { agentsList } = useAgentsList(true);
|
|
|
|
expect(agentsList.value[0]).toEqual(agentHelper.createNoneAgent);
|
|
expect(agentsList.value.length).toBe(formattedAgentsData.length);
|
|
});
|
|
|
|
it('excludes None agent when includeNoneAgent is false', () => {
|
|
const { agentsList } = useAgentsList(false);
|
|
|
|
expect(agentsList.value[0]).not.toEqual(agentHelper.createNoneAgent);
|
|
expect(agentsList.value.length).toBe(formattedAgentsData.length - 1);
|
|
});
|
|
|
|
it('handles empty assignable agents', () => {
|
|
mockUseMapGetter({
|
|
'inboxAssignableAgents/getAssignableAgents': ref(() => []),
|
|
});
|
|
agentHelper.getSortedAgentsByAvailability.mockReturnValue([]);
|
|
|
|
const { agentsList, assignableAgents } = useAgentsList();
|
|
|
|
expect(assignableAgents.value).toEqual([]);
|
|
expect(agentsList.value).toEqual([agentHelper.createNoneAgent]);
|
|
});
|
|
|
|
it('handles missing inbox_id', () => {
|
|
mockUseMapGetter({
|
|
getSelectedChat: ref({ meta: { assignee: true } }),
|
|
'inboxAssignableAgents/getAssignableAgents': ref(() => []),
|
|
});
|
|
agentHelper.getSortedAgentsByAvailability.mockReturnValue([]);
|
|
|
|
const { agentsList, assignableAgents } = useAgentsList();
|
|
|
|
expect(assignableAgents.value).toEqual([]);
|
|
expect(agentsList.value).toEqual([agentHelper.createNoneAgent]);
|
|
});
|
|
});
|