Skip to content

Commit

Permalink
VTag improvements (#3975)
Browse files Browse the repository at this point in the history
* VTag improvements

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>

* Update unit tests

Signed-off-by: Olga Bulat <obulat@gmail.com>

---------

Signed-off-by: Olga Bulat <obulat@gmail.com>
Co-authored-by: Stagge <jonatan.stagge@gmail.com>
  • Loading branch information
obulat and Stagge authored Apr 1, 2024
1 parent e860f36 commit d47d1c0
Show file tree
Hide file tree
Showing 3 changed files with 36 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
31 changes: 31 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,31 @@
import { screen } from "@testing-library/vue"

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

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

describe("VTag", () => {
let options = {}

beforeEach(() => {
options = {
props: { href: "https://example.com/" },
slots: { default: "Hello" },
}
})

it("should render an anchor tag by default", () => {
const { getByRole } = render(VTag, options)
const link = getByRole("link", { name: "Hello" })
expect(link).toBeDefined()
expect(link.href).toEqual("https://example.com/")
})

it("renders slot content", () => {
const slotText = "Slot test"
options.slots = { default: `<div>${slotText}</div>` }

render(VTag, options)
expect(screen.getByText(slotText)).toBeDefined()
})
})

0 comments on commit d47d1c0

Please sign in to comment.