Skip to content

Commit ed936c8

Browse files
committed
feat(routines): comment-count badge in Month view chips (TM-926)
1 parent 6264c45 commit ed936c8

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎src/components/dailyRoutine/views/MonthView.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
>{{ e.time }}</span
8383
>
8484
<span class="truncate">{{ e.title }}</span>
85+
<CommentCountBadge :count="e.comments_count ?? 0" />
8586
</div>
8687
<div
8788
v-if="byDay[i].length > maxChips"
@@ -95,6 +96,7 @@
9596
</template>
9697

9798
<script setup lang="ts">
99+
import CommentCountBadge from '../CommentCountBadge.vue';
98100
import { useRoutineDrag } from '@/composable/useRoutineDrag';
99101
import type { RoutineEntry } from '@/types/dailyRoutine';
100102
import { hexAlpha } from '@/utils/dailyRoutines/categoryMap';
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { readFileSync } from 'fs';
2+
import { join } from 'path';
3+
import { createSSRApp } from 'vue';
4+
import { renderToString } from '@vue/server-renderer';
5+
6+
const templateOf = (file: string): string => {
7+
const src = readFileSync(join(__dirname, file), 'utf8');
8+
const m = src.match(/<template>([\s\S]*)<\/template>\s*<script/);
9+
return m ? m[1] : '';
10+
};
11+
12+
const badge = {
13+
template: templateOf('../../CommentCountBadge.vue'),
14+
props: ['count'],
15+
components: { MessageCircle: { template: '<i />' } },
16+
};
17+
18+
const entry = (over: Record<string, unknown>) => ({
19+
task_id: 1,
20+
date: '2026-10-12',
21+
title: 'Stretch',
22+
time: '08:00',
23+
completed: false,
24+
routine_category: { color: '#ff0000' },
25+
...over,
26+
});
27+
28+
const render = async (entries: unknown[]) => {
29+
const app = createSSRApp({
30+
template: templateOf('../MonthView.vue'),
31+
components: { CommentCountBadge: badge },
32+
setup: () => ({
33+
dowLabels: ['M'],
34+
days: [new Date(2026, 9, 12)],
35+
byDay: [entries],
36+
maxChips: 3,
37+
hoverKey: '',
38+
today: new Date(2026, 9, 12),
39+
fmtIso: () => '2026-10-12',
40+
isSameDay: () => false,
41+
hexAlpha: () => '#fff',
42+
cellStyle: () => ({}),
43+
dayLabelStyle: () => ({}),
44+
onCellClick: () => undefined,
45+
}),
46+
});
47+
app.config.globalProperties.$t = (_k: string, p?: { n: number }) =>
48+
`${p?.n} comments`;
49+
return renderToString(app);
50+
};
51+
52+
describe('MonthView comment badge', () => {
53+
it('shows the count when comments_count > 0', async () => {
54+
const html = await render([entry({ comments_count: 3 })]);
55+
expect(html).toContain('data-testid="routine-comment-count"');
56+
expect(html).toContain('>3<');
57+
});
58+
59+
it('renders nothing when comments_count is 0 or missing', async () => {
60+
expect(await render([entry({ comments_count: 0 })])).not.toContain(
61+
'routine-comment-count',
62+
);
63+
expect(await render([entry({})])).not.toContain('routine-comment-count');
64+
});
65+
});

0 commit comments

Comments
 (0)