Skip to content

Commit

Permalink
VTag improvements
Browse files Browse the repository at this point in the history
Co-authored-by: FelixSjogren <felixarvidsjogren@gmail.com>

FEAT - Add lot for the content instead of a prop (#2)

Closes #2

Co-authored-by: Stagge <jonatan.stagge@gmail.com>

TEST - Add tests for VTag (#7)

Added tests for Vtag,
tests include:
All props are sent to VButton
VTag renders slot content
Renders anchor tag.

Co-authored-by: Stagge <jonatan.stagge@gmail.com>

FEAT - Ensure inner VButton emits and handles events in VTag #4

Closes #4

Added accessibility label (#10)

- Added aria-label to indicate that that the link is a tag

Improvements from review

lint

Signed-off-by: Olga Bulat <obulat@gmail.com>
  • Loading branch information
Stagge authored and obulat committed Mar 27, 2024
1 parent 83f21d7 commit dda343b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/VMediaInfo/VMediaTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:class="heightClass"
>
<li v-for="tag in visibleTags" :key="tag">
<VTag :href="localizedTagPath(tag)" :title="tag" />
<VTag :href="localizedTagPath(tag)">{{ tag }}</VTag>
</li>
</ul>
<VButton
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/VTag/VTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
size="small"
variant="filled-gray"
class="label-bold"
:href="href"
>{{ title }}</VButton
>
v-bind="$props"
v-on="$listeners"
><slot
/></VButton>
</template>

<script lang="ts">
Expand All @@ -18,10 +19,6 @@ export default defineComponent({
name: "VTag",
components: { VButton },
props: {
title: {
type: String,
required: true,
},
href: {
type: String,
required: true,
Expand Down
50 changes: 50 additions & 0 deletions frontend/test/unit/specs/components/VTag/v-tag.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { screen } from "@testing-library/vue"

import { render } from "~~/test/unit/test-utils/render"

import VTag from "~/components/VTag/VTag.vue"

describe("VTag", () => {
let props = null
let options = null

beforeEach(() => {
props = {}
options = { propsData: props }
})

it("should render an anchor tag by default", () => {
options.propsData = {
...options.propsData,
title: "exTitle",
href: "https://example.com/",
}
const { container } = render(VTag, options)
expect(container.firstChild.tagName).toEqual("A")
})

it("should pass all props to VButton", () => {
options.propsData = {
...options.propsData,
title: "exTitle",
href: "https://example.com/",
}
const { container } = render(VTag, options)
expect(container.firstChild.title).toEqual("exTitle")
expect(container.firstChild.href).toEqual("https://example.com/")
})

it("renders slot content", () => {
const label = "I'm a label"
options.propsData = {
href: "https://example.com/",
title: "Slot test",
}
options.slots = {
default: `<div aria-label="${label}">Hello</div>`,
}

render(VTag, options)
expect(screen.queryByLabelText(label)).toBeDefined()
})
})

0 comments on commit dda343b

Please sign in to comment.