Files
assistant-storefront/app/javascript/dashboard/composables/spec/useAccount.spec.js
Liang XJ 092fb2e083
Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Initial commit: Add logistics and order_detail message types
- Add Logistics component with progress tracking
- Add OrderDetail component for order information
- Support data-driven steps and actions
- Add blue color scale to widget SCSS
- Fix node overflow and progress bar rendering issues
- Add English translations for dashboard components

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 11:16:56 +08:00

118 lines
3.2 KiB
JavaScript

import { defineComponent, h } from 'vue';
import { createStore } from 'vuex';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { useAccount } from '../useAccount';
import { useRoute } from 'vue-router';
import { mount } from '@vue/test-utils';
const store = createStore({
modules: {
auth: {
namespaced: false,
getters: {
getCurrentAccountId: () => 1,
getCurrentUser: () => ({
accounts: [
{ id: 1, name: 'Chatwoot', role: 'administrator' },
{ id: 2, name: 'GitX', role: 'agent' },
],
}),
},
},
accounts: {
namespaced: true,
getters: {
getAccount: () => id => ({ id, name: 'Chatwoot' }),
},
},
},
});
const mountParams = {
global: {
plugins: [store],
},
};
vi.mock('vue-router');
describe('useAccount', () => {
beforeEach(() => {
useRoute.mockReturnValue({
params: {
accountId: '123',
},
});
});
const createComponent = () =>
defineComponent({
setup() {
return useAccount();
},
render() {
return h('div'); // Dummy render to satisfy mount
},
});
it('returns accountId as a computed property', () => {
const wrapper = mount(createComponent(), mountParams);
const { accountId } = wrapper.vm;
expect(accountId).toBe(123);
});
it('generates account-scoped URLs correctly', () => {
const wrapper = mount(createComponent(), mountParams);
const { accountScopedUrl } = wrapper.vm;
const result = accountScopedUrl('settings/inbox/new');
expect(result).toBe('/app/accounts/123/settings/inbox/new');
});
it('handles URLs with leading slash', () => {
const wrapper = mount(createComponent(), mountParams);
const { accountScopedUrl } = wrapper.vm;
const result = accountScopedUrl('users');
expect(result).toBe('/app/accounts/123/users'); // Ensures no double slashes
});
it('handles empty URL', () => {
const wrapper = mount(createComponent(), mountParams);
const { accountScopedUrl } = wrapper.vm;
const result = accountScopedUrl('');
expect(result).toBe('/app/accounts/123/');
});
it('returns current account based on accountId', () => {
const wrapper = mount(createComponent(), mountParams);
const { currentAccount } = wrapper.vm;
expect(currentAccount).toEqual({ id: 123, name: 'Chatwoot' });
});
it('returns an account-scoped route', () => {
const wrapper = mount(createComponent(), mountParams);
const { accountScopedRoute } = wrapper.vm;
const result = accountScopedRoute('accountDetail', { userId: 456 }, {});
expect(result).toEqual({
name: 'accountDetail',
params: { accountId: 123, userId: 456 },
query: {},
});
});
it('returns route with correct params', () => {
const wrapper = mount(createComponent(), mountParams);
const { route } = wrapper.vm;
expect(route.params).toEqual({ accountId: '123' });
});
it('handles non-numeric accountId gracefully', async () => {
useRoute.mockReturnValueOnce({
params: { accountId: 'abc' },
});
const wrapper = mount(createComponent(), mountParams);
const { accountId } = wrapper.vm;
expect(accountId).toBeNaN(); // Handles invalid numeric conversion
});
});