From 4fd16bcf45cbe354cb024d4dde6937daed8c4a05 Mon Sep 17 00:00:00 2001 From: Jarlem Red de Peralta Date: Tue, 6 Dec 2022 14:48:00 +0800 Subject: [PATCH] fix(consultation): find activities of consultation fix lemredd/talakutnangan#1072 --- components/consultation/list.vue | 26 +++++++-- components/consultation/list/item.spec.ts | 68 ----------------------- 2 files changed, 20 insertions(+), 74 deletions(-) diff --git a/components/consultation/list.vue b/components/consultation/list.vue index a4e79c644..a8e50a772 100644 --- a/components/consultation/list.vue +++ b/components/consultation/list.vue @@ -35,7 +35,7 @@ v-for="consultation in consultations.data" :key="consultation.id" :consultation="consultation" - :chat-message-activities="chatMessageActivities" + :chat-message-activities="determineActivities(consultation)" :preview-messages="previewMessages"/> @@ -95,6 +95,7 @@ import type { } from "$/types/documents/chat_message_activity" import type { ConsultationRelationshipNames, + DeserializedConsultationResource, DeserializedConsultationListDocument } from "$/types/documents/consultation" @@ -114,6 +115,12 @@ import MinorDropdown from "@/helpers/minor_dropdown.vue" const pageContext = inject("pageContext") as PageContext<"deserialized"> +const props = defineProps<{ + chatMessageActivities: DeserializedChatMessageActivityListDocument<"user"|"consultation">, + consultations: DeserializedConsultationListDocument, + previewMessages: DeserializedChatMessageListDocument<"user"|"consultation"> +}>() + const { "state": isDropdownShown } = makeSwitch(false) @@ -132,9 +139,16 @@ const { "pageProps": { userProfile } } = pageContext const isUserAStudent = computed(() => userProfile.data.kind === "student") const isUserAReachableEmployee = computed(() => userProfile.data.kind === "reachable_employee") -defineProps<{ - chatMessageActivities: DeserializedChatMessageActivityListDocument<"user"|"consultation">, - consultations: DeserializedConsultationListDocument, - previewMessages: DeserializedChatMessageListDocument<"user"|"consultation"> -}>() +function determineActivities(consultation: DeserializedConsultationResource) { + const activities = props.chatMessageActivities.data.filter( + activity => activity.consultation.data.id === consultation.id + ) + + return { + "data": activities, + "meta": { + "count": activities.length + } + } +} diff --git a/components/consultation/list/item.spec.ts b/components/consultation/list/item.spec.ts index dd174dfa5..733872d1f 100644 --- a/components/consultation/list/item.spec.ts +++ b/components/consultation/list/item.spec.ts @@ -122,72 +122,4 @@ describe("Component: consultation/list/item", () => { const lengthOfUniqueUsers = wrapper.props("chatMessageActivities").data.length - 1 expect(profilePictures).toHaveLength(lengthOfUniqueUsers) }) - - it("should display profile pictures even if inactive", () => { - const wrapper = shallowMount(Component, { - "global": { - "provide": { - [BODY_CLASSES]: [], - "pageContext": { - "pageProps": { - "userProfile": { - "data": { - "kind": "student" - } - } - }, - "urlPathname": "/consultation/read/2" - } - } - }, - "props": { - "chatMessageActivities": { - "data": [ - { - "consultation": { "data": { "id": "1" } }, - "id": "1", - "user": { - "data": { - "id": "1", - "name": "participant A" - } - } - }, - { - "consultation": { "data": { "id": "1" } }, - "id": "2", - "user": { - "data": { - "id": "2", - "name": "participant B" - } - } - }, - { - "consultation": { "data": { "id": "1" } }, - "id": "3", - "user": { - "data": { - "id": "2", - "name": "participant" - } - } - } - ] - }, - "consultation": { - "id": "1", - "reason": "Reason A" - }, - "previewMessages": { - "data": [] - } - } - }) - - const profilePictures = wrapper.findAllComponents(".profile-picture-item") - const lengthOfUniqueUsers = wrapper.props("chatMessageActivities").data.length - 1 - expect(profilePictures).toHaveLength(lengthOfUniqueUsers) - profilePictures.forEach(p => console.log(p.html(), "\n\n\n")) - }) })