Skip to content

Commit 25514e1

Browse files
cursoragentterryyin
andcommitted
fix: make note reactive in AnsweredQuestionComponent
The note under MCQ questions was not updating when navigating to previous questions because the note variable was a static assignment instead of a computed property. Changed to use computed() so the note updates reactively when the answeredQuestion prop changes. Added test to verify the note display updates correctly when the prop changes. Co-authored-by: terry <terry@odd-e.com>
1 parent 9e4acd4 commit 25514e1

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

frontend/src/components/recall/AnsweredQuestionComponent.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
<script setup lang="ts">
2424
import type { AnsweredQuestion } from "@generated/backend"
2525
import type { PropType } from "vue"
26+
import { computed } from "vue"
2627
import QuestionDisplay from "./QuestionDisplay.vue"
2728
import ConversationButton from "./ConversationButton.vue"
2829
import NoteUnderQuestion from "./NoteUnderQuestion.vue"
2930
import ViewMemoryTrackerLink from "./ViewMemoryTrackerLink.vue"
3031
31-
const { answeredQuestion, conversationButton } = defineProps({
32+
const props = defineProps({
3233
answeredQuestion: {
3334
type: Object as PropType<AnsweredQuestion>,
3435
required: true,
@@ -39,5 +40,5 @@ const { answeredQuestion, conversationButton } = defineProps({
3940
},
4041
})
4142
42-
const note = answeredQuestion?.note
43+
const note = computed(() => props.answeredQuestion?.note)
4344
</script>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import AnsweredQuestionComponent from "@/components/recall/AnsweredQuestionComponent.vue"
2+
import { flushPromises } from "@vue/test-utils"
3+
import helper from "@tests/helpers"
4+
import makeMe from "@tests/fixtures/makeMe"
5+
import { describe, it, expect } from "vitest"
6+
7+
describe("AnsweredQuestionComponent", () => {
8+
describe("note under question", () => {
9+
it("renders note under question when note is present", async () => {
10+
const note = makeMe.aNote.title("Test Note Title").please()
11+
const answeredQuestion = makeMe.anAnsweredQuestion.withNote(note).please()
12+
13+
const wrapper = helper
14+
.component(AnsweredQuestionComponent)
15+
.withProps({ answeredQuestion, conversationButton: false })
16+
.mount()
17+
18+
await flushPromises()
19+
20+
expect(wrapper.text()).toContain("Test Note Title")
21+
})
22+
23+
it("updates note display when answeredQuestion prop changes", async () => {
24+
const note1 = makeMe.aNote.title("First Note").please()
25+
const note2 = makeMe.aNote.title("Second Note").please()
26+
const answeredQuestion1 = makeMe.anAnsweredQuestion
27+
.withNote(note1)
28+
.please()
29+
const answeredQuestion2 = makeMe.anAnsweredQuestion
30+
.withNote(note2)
31+
.please()
32+
33+
const wrapper = helper
34+
.component(AnsweredQuestionComponent)
35+
.withProps({ answeredQuestion: answeredQuestion1, conversationButton: false })
36+
.mount()
37+
38+
await flushPromises()
39+
40+
// Verify first note is displayed
41+
expect(wrapper.text()).toContain("First Note")
42+
expect(wrapper.text()).not.toContain("Second Note")
43+
44+
// Update prop to second answered question
45+
await wrapper.setProps({ answeredQuestion: answeredQuestion2 })
46+
await flushPromises()
47+
48+
// Verify second note is now displayed
49+
expect(wrapper.text()).toContain("Second Note")
50+
expect(wrapper.text()).not.toContain("First Note")
51+
})
52+
})
53+
})

0 commit comments

Comments
 (0)