mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 04:27:53 +00:00
# Pull Request Template ## Description The PR will replace the usage of `reportMixin` with the help of `useReportMetrics()` composable. Fixes https://linear.app/chatwoot/issue/CW-3450/rewrite-reportmixin-mixin-to-a-composable **Files updated** 1. dashboard/routes/dashboard/settings/reports/Index.vue 2. dashboard/routes/dashboard/settings/reports/BotReports.vue 3. dashboard/routes/dashboard/settings/reports/ReportContainer.vue 4. dashboard/routes/dashboard/settings/reports/components/WootReports.vue 5. dashboard/routes/dashboard/settings/reports/components/ChartElements/ChartStats.vue ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? Test the all the reports view. ## 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
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
import { ref } from 'vue';
|
|
import { useReportMetrics } from '../useReportMetrics';
|
|
import { useMapGetter } from 'dashboard/composables/store';
|
|
import { summary, botSummary } from './fixtures/reportFixtures';
|
|
|
|
vi.mock('dashboard/composables/store');
|
|
vi.mock('@chatwoot/utils', () => ({
|
|
formatTime: vi.fn(time => `formatted_${time}`),
|
|
}));
|
|
|
|
describe('useReportMetrics', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
useMapGetter.mockReturnValue(ref(summary));
|
|
});
|
|
|
|
it('calculates trend correctly', () => {
|
|
const { calculateTrend } = useReportMetrics();
|
|
|
|
expect(calculateTrend('conversations_count')).toBe(124900);
|
|
expect(calculateTrend('incoming_messages_count')).toBe(0);
|
|
expect(calculateTrend('avg_first_response_time')).toBe(123);
|
|
});
|
|
|
|
it('returns 0 for trend when previous value is not available', () => {
|
|
const { calculateTrend } = useReportMetrics();
|
|
|
|
expect(calculateTrend('non_existent_key')).toBe(0);
|
|
});
|
|
|
|
it('identifies average metric types correctly', () => {
|
|
const { isAverageMetricType } = useReportMetrics();
|
|
|
|
expect(isAverageMetricType('avg_first_response_time')).toBe(true);
|
|
expect(isAverageMetricType('avg_resolution_time')).toBe(true);
|
|
expect(isAverageMetricType('reply_time')).toBe(true);
|
|
expect(isAverageMetricType('conversations_count')).toBe(false);
|
|
});
|
|
|
|
it('displays metrics correctly for account', () => {
|
|
const { displayMetric } = useReportMetrics();
|
|
|
|
expect(displayMetric('conversations_count')).toBe('5,000');
|
|
expect(displayMetric('incoming_messages_count')).toBe('5');
|
|
});
|
|
|
|
it('displays the metric for bot', () => {
|
|
const customKey = 'getBotSummary';
|
|
useMapGetter.mockReturnValue(ref(botSummary));
|
|
const { displayMetric } = useReportMetrics(customKey);
|
|
|
|
expect(displayMetric('bot_resolutions_count')).toBe('10');
|
|
expect(displayMetric('bot_handoffs_count')).toBe('20');
|
|
});
|
|
|
|
it('handles non-existent metrics', () => {
|
|
const { displayMetric } = useReportMetrics();
|
|
|
|
expect(displayMetric('non_existent_key')).toBe('0');
|
|
});
|
|
});
|