This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(component): make a general component for profile picture
- Loading branch information
1 parent
a057c08
commit 9004126
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |