refactor: extract display name into component
I could imagine that we will refactor this into even smaller components in the future but for now, I bundle the pronoun with the display name like this. Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
parent
508105681b
commit
fecd15f862
3 changed files with 39 additions and 5 deletions
17
src/lib/components/atoms/DisplayName.svelte
Normal file
17
src/lib/components/atoms/DisplayName.svelte
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<script lang="ts">
|
||||||
|
/**
|
||||||
|
* Under which name shall the person be known?
|
||||||
|
*/
|
||||||
|
export let displayName: string = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How to correctly address this person.
|
||||||
|
*/
|
||||||
|
export let pronoun: string = '';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1 class="h1 font-semibold text-4xl leading-tight">
|
||||||
|
<span class="sr-only">Profile for </span>
|
||||||
|
{@html displayName}
|
||||||
|
</h1>
|
||||||
|
<p class="leading-normal my-1">({@html pronoun})</p>
|
|
@ -2,6 +2,7 @@
|
||||||
import Avatar from '$lib/components/atoms/Avatar.svelte';
|
import Avatar from '$lib/components/atoms/Avatar.svelte';
|
||||||
import BlockOrReport from '$lib/components/atoms/BlockOrReport.svelte';
|
import BlockOrReport from '$lib/components/atoms/BlockOrReport.svelte';
|
||||||
import Created from '$lib/components/atoms/Created.svelte';
|
import Created from '$lib/components/atoms/Created.svelte';
|
||||||
|
import DisplayName from '$lib/components/atoms/DisplayName.svelte';
|
||||||
|
|
||||||
/** @type {import('./$types').PageData} */
|
/** @type {import('./$types').PageData} */
|
||||||
export let data;
|
export let data;
|
||||||
|
@ -26,11 +27,7 @@
|
||||||
<!-- Board -->
|
<!-- Board -->
|
||||||
<div class="flex flex-col flex-1 gap-2">
|
<div class="flex flex-col flex-1 gap-2">
|
||||||
<div class="flex items-end">
|
<div class="flex items-end">
|
||||||
<h1 class="h1 font-semibold text-4xl leading-tight">
|
<DisplayName displayName={data.user.display_name} pronoun={data.user.pronoun} />
|
||||||
<span class="sr-only">Profile for </span>
|
|
||||||
{@html data.user.display_name}
|
|
||||||
</h1>
|
|
||||||
<p class="leading-normal my-1">(she/her)</p>
|
|
||||||
</div>
|
</div>
|
||||||
<span class="leading-tight">
|
<span class="leading-tight">
|
||||||
{@html data.user.username}@{@html data.user.instance}
|
{@html data.user.username}@{@html data.user.instance}
|
||||||
|
|
20
tests/components/atoms/DisplayName.test.ts
Normal file
20
tests/components/atoms/DisplayName.test.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
|
||||||
|
import DisplayName from '../../../src/lib/components/atoms/DisplayName.svelte';
|
||||||
|
|
||||||
|
describe('DisplayName.svelte', () => {
|
||||||
|
it('should mount', () => {
|
||||||
|
// Arrange
|
||||||
|
const displayName = 'Jane Doe';
|
||||||
|
const pronoun = 'she/her';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
render(DisplayName, { displayName, pronoun });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(screen.getByText(displayName)).toBeInTheDocument();
|
||||||
|
// Turn into regular expression to respect round brackets
|
||||||
|
expect(screen.getByText(new RegExp(pronoun))).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue