Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit 3415ccb

Browse files
feat: Adds title-prop & tests to Link-component
1 parent 0f3fa78 commit 3415ccb

File tree

6 files changed

+95
-26
lines changed

6 files changed

+95
-26
lines changed

docs/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: [["@vue/app", {useBuiltIns: "usage"}]]
2+
presets: [["@vue/app", { useBuiltIns: "usage" }]]
33
};

docs/src/api/_baseline.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
"slots": {
201201
"": {
202202
"name": "",
203-
"description": "Link Title"
203+
"description": "Link Title. If not set the title-prop is used as a fallback."
204204
}
205205
},
206206
"events": {
@@ -211,6 +211,13 @@
211211
},
212212
"mixins": [],
213213
"props": {
214+
"title": {
215+
"name": "title",
216+
"description": "Is used for two things: (1) title-attribute of the rendered anchor and (2) as fallback content when no default slot is provided.",
217+
"required": false,
218+
"types": ["String"],
219+
"defaultValue": null
220+
},
214221
"selected": {
215222
"name": "selected",
216223
"description": "whether link is selected",

docs/src/pages/Link/default.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<title>Link</title>
2+
<tip>
3+
You can provide the visible title of the link by using a default slot or by using the `title`-prop.
4+
If both are provided the `title`-prop is only used for the `title` attribute of the anchor. This means that
25

6+
```html
7+
<FdLink href="#" title="foo bar" />
8+
```
9+
10+
is **equivialent** to
11+
12+
```html
13+
<FdLink href="#" title="foo bar">foo bar</FdLink>
14+
```
15+
16+
</tip>
317
<template>
418
<div>
519
<h3>Normal</h3>
@@ -31,6 +45,9 @@
3145
<script>
3246
export default {
3347
methods: {
48+
handleFocus() {
49+
console.log("focus");
50+
},
3451
handleClick() {
3552
console.log("clicked");
3653
}

ui/jest.config.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
module.exports = {
2-
moduleFileExtensions: [
3-
'js',
4-
'jsx',
5-
'json',
6-
'vue',
7-
'ts',
8-
'tsx'
9-
],
2+
moduleFileExtensions: ["js", "jsx", "json", "vue", "ts", "tsx"],
103
transform: {
11-
'^.+\\.vue$': 'vue-jest',
12-
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
13-
'^.+\\.tsx?$': 'ts-jest'
4+
"^.+\\.vue$": "vue-jest",
5+
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
6+
"jest-transform-stub",
7+
"^.+\\.tsx?$": "ts-jest"
148
},
159
moduleNameMapper: {
16-
'^@/(.*)$': '<rootDir>/src/$1'
10+
"^@/(.*)$": "<rootDir>/src/$1"
1711
},
18-
snapshotSerializers: [
19-
'jest-serializer-vue'
20-
],
12+
snapshotSerializers: ["jest-serializer-vue"],
2113
testMatch: [
22-
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
14+
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
2315
],
24-
testURL: 'http://localhost/',
16+
testURL: "http://localhost/",
2517
globals: {
26-
'ts-jest': {
18+
"ts-jest": {
2719
babelConfig: true
2820
}
2921
}
30-
}
22+
};

ui/src/components/Link/Link.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
<template>
2-
<a v-on="listeners" @click="click" :class="classes" href="#">
3-
<slot />
2+
<a v-on="listeners" @click="click" :class="classes" href="#" :title="title">
3+
<slot>{{ title }}</slot>
44
</a>
55
</template>
66

77
<script lang="ts">
88
import Vue from "vue";
9-
import { PropValidator } from "vue/types/options";
109
1110
export default Vue.extend({
1211
name: "FdLink",
1312
props: {
14-
selected: { type: Boolean, default: false } as PropValidator<boolean>,
15-
disabled: { type: Boolean, default: false } as PropValidator<boolean>
13+
title: String,
14+
selected: { type: Boolean, default: false },
15+
disabled: { type: Boolean, default: false }
1616
},
1717
methods: {
1818
click(event: Event): void {
19+
if (event.defaultPrevented) {
20+
return;
21+
}
1922
if (this.disabled) {
2023
event.preventDefault();
2124
event.stopPropagation();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import FdLink from "./../Link.vue";
2+
import { mount, createLocalVue } from "@vue/test-utils";
3+
import FundamentalVue from "@/index";
4+
5+
describe("Link", () => {
6+
it("can be disabled", async () => {
7+
const localVue = createLocalVue();
8+
localVue.use(FundamentalVue);
9+
const wrapper = await mount(FdLink, { propsData: { disabled: true } });
10+
expect(wrapper.classes("is-disabled")).toBe(true);
11+
const anchor = wrapper.find("a");
12+
expect(anchor.exists()).toBe(true);
13+
// @click events are not emitted
14+
anchor.trigger("click");
15+
expect(wrapper.emitted("click")).toBeUndefined();
16+
});
17+
18+
it("can have custom href", async () => {
19+
const localVue = createLocalVue();
20+
localVue.use(FundamentalVue);
21+
const wrapper = await mount(FdLink, {
22+
propsData: { href: "https://localhost:10000" }
23+
});
24+
expect(wrapper.attributes("href")).toBe("https://localhost:10000");
25+
});
26+
27+
it("renders default slot", async () => {
28+
const localVue = createLocalVue();
29+
localVue.use(FundamentalVue);
30+
const wrapper = await mount(FdLink, {
31+
slots: {
32+
default: "foo bar"
33+
}
34+
});
35+
expect(wrapper.find("a").text()).toBe("foo bar");
36+
});
37+
38+
it("renders title as both: title-attr and content", async () => {
39+
const localVue = createLocalVue();
40+
localVue.use(FundamentalVue);
41+
const wrapper = await mount(FdLink, {
42+
propsData: {
43+
title: "foo bar"
44+
}
45+
});
46+
const anchor = wrapper.find("a");
47+
expect(anchor.text()).toBe("foo bar");
48+
expect(anchor.attributes("title")).toBe("foo bar");
49+
});
50+
});

0 commit comments

Comments
 (0)