Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VTag component #3870

Closed
wants to merge 8 commits into from
3 changes: 1 addition & 2 deletions frontend/src/components/VMediaInfo/VMediaTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
v-for="(tag, index) in tags"
:key="index"
:href="localizedTagPath(tag)"
:title="tag.name"
/>
>{{tag.name}}</VTag>
obulat marked this conversation as resolved.
Show resolved Hide resolved
</ul>
<ul v-else class="flex flex-wrap gap-2">
<VMediaTag v-for="(tag, index) in tags" :key="index" tag="li">{{
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/components/VTag/VTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
size="small"
variant="filled-gray"
class="label-bold"
:href="href"
>{{ title }}</VButton
v-bind ="$props"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props are automatically passed to the child component in Vue, but some attrs are not. We need to bind attrs here.

Suggested change
v-bind ="$props"
v-bind ="$attrs"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to draft this PR until the changes are addressed (linting and binding $attrs instead of $props)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
v-bind ="$props"
v-bind ="$attrs"

v-on="$listeners"
><slot /></VButton
>
</template>

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
51 changes: 51 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,51 @@
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()
})
})
Loading