fix: unify completed item visibility
ci / gitleaks (push) Successful in 10s
ci / docker (push) Successful in 3m41s

This commit is contained in:
2026-09-10 06:42:24 +08:00
parent 306f502908
commit a5ece8ca42
5 changed files with 71 additions and 36 deletions
+29 -9
View File
@@ -373,24 +373,44 @@ describe('task and habit row decoration', () => {
expect(app).toContain('if (restoredNavigation.view === \'tasks\' && restoredNavigation.listId)')
})
it('restores the completed-item visibility choices from local storage', () => {
it('uses one positive completed-item preference across task and habit views', () => {
expect(app).toContain("readStoredBoolean(window.localStorage, SHOW_COMPLETED_STORAGE_KEY, true)")
expect(app).toContain("writeStoredBoolean(window.localStorage, SHOW_COMPLETED_STORAGE_KEY, value)")
expect(mvpPanel).toContain("readStoredBoolean(window.localStorage, HIDE_COMPLETED_HABITS_STORAGE_KEY, false)")
expect(mvpPanel).toContain("writeStoredBoolean(window.localStorage, HIDE_COMPLETED_HABITS_STORAGE_KEY, value)")
expect(app).toContain(':show-completed="showCompleted"')
expect(app).toContain('@update:show-completed="showCompleted = $event"')
expect(mvpPanel).toContain('showCompleted: boolean')
expect(mvpPanel).toContain("'update:showCompleted': [value: boolean]")
expect(mvpPanel).not.toContain('HIDE_COMPLETED_HABITS_STORAGE_KEY')
expect(mvpPanel).not.toContain('dodo.hide-completed-habits')
})
it('can hide completed habits in both Today and full habit views', () => {
expect(mvpPanel).toContain("const hideCompletedHabits = ref(readStoredBoolean(window.localStorage, HIDE_COMPLETED_HABITS_STORAGE_KEY, false))")
expect(mvpPanel).toContain('const visibleTodayHabits = computed')
expect(mvpPanel).toContain('const visibleHabits = computed')
expect(mvpPanel).toContain('v-model="hideCompletedHabits"')
expect(mvpPanel).toContain('隐藏已完成')
it('shows one positive switch before Today content and no switch inside today habits', () => {
expect(app).toContain('class="list-toolbar today-completed-toolbar"')
expect(app.indexOf('class="list-toolbar today-completed-toolbar"')).toBeLessThan(app.indexOf('class="today-board"'))
expect(app).toContain('<input v-model="showCompleted" type="checkbox"> 显示已完成')
const todayHabits = mvpPanel.slice(mvpPanel.indexOf('<!-- 今日习惯'), mvpPanel.indexOf('<!-- 完整习惯列表'))
expect(todayHabits).not.toContain('type="checkbox"')
expect(todayHabits).not.toContain('显示已完成')
expect(todayHabits).not.toContain('隐藏已完成')
})
it('filters habits with the shared preference and disables sorting while completed items are hidden', () => {
expect(mvpPanel).toContain('const visibleTodayHabits = computed(() => props.showCompleted ? todayHabits.value')
expect(mvpPanel).toContain('const visibleHabits = computed(() => props.showCompleted ? habits.value')
expect(mvpPanel).toContain('v-for="h in visibleTodayHabits"')
expect(mvpPanel).toContain('v-for="h in visibleHabits"')
expect(mvpPanel).toContain(':disabled="!showCompleted"')
expect(mvpPanel).toContain('if (busy.value || !props.showCompleted) return')
expect(css).toContain('.habit-toolbar{')
})
it('distinguishes hidden completed items from true and search empty states', () => {
expect(app).toContain('const hiddenCompletedTaskCount = ref(0)')
expect(app).toContain("query ? '没有匹配的任务' : hiddenCompletedTaskCount > 0 ? '已完成任务已隐藏' : '这里还很安静'")
expect(mvpPanel).toContain("!showCompleted && todayHabits.length ? '已完成的习惯已隐藏。'")
expect(mvpPanel).toContain("!showCompleted && habits.length ? '已完成的习惯已隐藏。'")
})
it('shows unfinished overdue tasks as a separate list inside Today', () => {
expect(app).toContain('const overdueTasks = ref<Task[]>([])')
expect(app).toContain("params.set('due_to', isoAtLocalDayOffset(0))")