Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
chore(component): make a general component for profile picture
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 13, 2022
1 parent a057c08 commit 9004126
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
42 changes: 42 additions & 0 deletions components/helpers/profile_picture.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { shallowMount } from "@vue/test-utils"

import Component from "./profile_picture.vue"

describe("Component: helpers/profile_picture_item", () => {
it("should show if user has profile picture", () => {
const sampleURL = "/images/profile.png"
const wrapper = shallowMount<any>(Component, {
"props": {
"user": {
"data": {
"profilePicture": {
"data": {
"fileContents": sampleURL
}
}
}
}
}
})

const image = wrapper.find("img")
const source = image.attributes("src")

expect(source).toBe(sampleURL)
})

it("should show if user has profile picture", () => {
const wrapper = shallowMount<any>(Component, {
"props": {
"user": {
"data": {}
}
}
})

const image = wrapper.find("img")
const source = image.attributes("src")

expect(source).toBe("stub")
})
})
31 changes: 31 additions & 0 deletions components/helpers/profile_picture.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<img :src="profilePictureURL"/>
</template>
<script setup lang="ts">
import { computed } from "vue"
import type { DeserializedUserDocument } from "$/types/documents/user"
import type { DeserializedProfilePictureDocument } from "$/types/documents/profile_picture"
import Icon from "@assets/icon.png"
const {
user
} = defineProps<{
user: DeserializedUserDocument<"profilePicture">
}>()
function isDeserializedProfilePictureDocument(value: any)
: value is DeserializedProfilePictureDocument {
return typeof value === "object"
}
const profilePictureURL = computed(() => {
const { profilePicture } = user.data
if (isDeserializedProfilePictureDocument(profilePicture)) {
return profilePicture.data.fileContents
}
return Icon
})
</script>

0 comments on commit 9004126

Please sign in to comment.