-
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.
Merge pull request #141 from JHWelch/styled-titles
Styled titles
- Loading branch information
Showing
16 changed files
with
524 additions
and
56 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,66 @@ | ||
import { RichText, TextStyle } from '@shared/dtos' | ||
import Factory from '@tests/utils/factories/factory' | ||
|
||
export default class RichTextFactory extends Factory<RichText> { | ||
protected state: RichText = { | ||
type: 'text', | ||
text: { | ||
content: 'The', | ||
link: null, | ||
}, | ||
annotations: { | ||
bold: false, | ||
italic: false, | ||
strikethrough: false, | ||
underline: false, | ||
code: false, | ||
color: 'default', | ||
}, | ||
plain_text: 'The', | ||
href: null, | ||
} | ||
|
||
public text (text: string): RichTextFactory { | ||
this.state.text.content = text | ||
this.state.plain_text = text | ||
|
||
return this | ||
} | ||
|
||
public bold (): RichTextFactory { | ||
this.state.annotations.bold = true | ||
|
||
return this | ||
} | ||
|
||
|
||
public italic (): RichTextFactory { | ||
this.state.annotations.italic = true | ||
|
||
return this | ||
} | ||
|
||
public strikethrough (): RichTextFactory { | ||
this.state.annotations.strikethrough = true | ||
|
||
return this | ||
} | ||
|
||
public underline (): RichTextFactory { | ||
this.state.annotations.underline = true | ||
|
||
return this | ||
} | ||
|
||
public code (): RichTextFactory { | ||
this.state.annotations.code = true | ||
|
||
return this | ||
} | ||
|
||
public color (color: TextStyle['color']): RichTextFactory { | ||
this.state.annotations.color = color | ||
|
||
return this | ||
} | ||
} |
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
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
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,37 @@ | ||
<script lang="ts" setup> | ||
import { WeekDto } from '@shared/dtos' | ||
defineProps<{ | ||
week: WeekDto | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<span | ||
v-if="week.styledTheme.length > 0" | ||
class="text-3xl font-semibold" | ||
data-testid="theme" | ||
> | ||
<span | ||
v-for="(theme, index) in week.styledTheme" | ||
:key="index" | ||
:class="{ | ||
'font-bold': theme.annotations.bold, | ||
'italic': theme.annotations.italic, | ||
'underline': theme.annotations.underline, | ||
'line-through': theme.annotations.strikethrough, | ||
}" | ||
> | ||
{{ theme.text.content }} | ||
</span> | ||
</span> | ||
|
||
<span | ||
v-else | ||
class="text-3xl font-semibold" | ||
data-testid="theme" | ||
> | ||
{{ week.isSkipped ? 'No movies this week!' : week.theme }} | ||
</span> | ||
</template> |
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,94 @@ | ||
/** @vitest-environment jsdom */ | ||
|
||
import { beforeEach, describe, expect, it } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import Theme from '@components/week/Theme.vue' | ||
import { WeekDto } from '@shared/dtos' | ||
import RichTextFactory from '@tests/utils/factories/richTextFactory' | ||
import WeekFactory from '@tests/utils/factories/weekFactory' | ||
|
||
let week: WeekDto | ||
|
||
describe('Just a theme, no styled theme', () => { | ||
beforeEach(() => { | ||
week = new WeekFactory().build({ | ||
theme: 'The Matrix', | ||
}) | ||
}) | ||
|
||
it('shows the theme', () => { | ||
const wrapper = mount(Theme, { | ||
props: { week: week }, | ||
}) | ||
expect(wrapper.text()).toContain(week.theme) | ||
}) | ||
}) | ||
|
||
describe('Styled theme', () => { | ||
beforeEach(() => { | ||
week = new WeekFactory().build({ | ||
theme: 'The Matrix', | ||
styledTheme: [ | ||
new RichTextFactory().text('The').bold().build(), | ||
new RichTextFactory().text('Matrix').italic().build(), | ||
new RichTextFactory().text('is').underline().build(), | ||
new RichTextFactory().text('the best').strikethrough().build(), | ||
], | ||
}) | ||
}) | ||
|
||
it('shows the styled theme', () => { | ||
const wrapper = mount(Theme, { | ||
props: { week }, | ||
}) | ||
|
||
const component = wrapper.find('[data-testid="theme"]') | ||
expect(component.exists()).toBe(true) | ||
expect(component.element.children[0].innerHTML).toBe('The') | ||
expect(component.element.children[0].classList).toContain('font-bold') | ||
expect(component.element.children[1].innerHTML).toBe('Matrix') | ||
expect(component.element.children[1].classList).toContain('italic') | ||
expect(component.element.children[2].innerHTML).toBe('is') | ||
expect(component.element.children[2].classList).toContain('underline') | ||
expect(component.element.children[3].innerHTML).toBe('the best') | ||
expect(component.element.children[3].classList).toContain('line-through') | ||
}) | ||
}) | ||
|
||
describe('Week skipped', () => { | ||
beforeEach(() => { | ||
week = new WeekFactory().build({ | ||
theme: 'The Matrix', | ||
isSkipped: true, | ||
}) | ||
}) | ||
|
||
it('shows the theme', () => { | ||
const wrapper = mount(Theme, { | ||
props: { week: week }, | ||
}) | ||
expect(wrapper.text()).toContain('No movies this week!') | ||
}) | ||
|
||
describe('with styled Theme', () => { | ||
beforeEach(() => { | ||
week.styledTheme = [ | ||
new RichTextFactory().text('The').bold().build(), | ||
new RichTextFactory().text('Matrix').italic().build(), | ||
] | ||
}) | ||
|
||
it('shows the styled theme', () => { | ||
const wrapper = mount(Theme, { | ||
props: { week }, | ||
}) | ||
|
||
const component = wrapper.find('[data-testid="theme"]') | ||
expect(component.exists()).toBe(true) | ||
expect(component.element.children[0].innerHTML).toBe('The') | ||
expect(component.element.children[0].classList).toContain('font-bold') | ||
expect(component.element.children[1].innerHTML).toBe('Matrix') | ||
expect(component.element.children[1].classList).toContain('italic') | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.