diff --git a/docs/src/api/_baseline.json b/docs/src/api/_baseline.json index 251d6b05..4b2c191b 100644 --- a/docs/src/api/_baseline.json +++ b/docs/src/api/_baseline.json @@ -976,14 +976,16 @@ "componentName": "FdShellBarGroup" }, "FdShellBarLogo": { - "slots": {}, + "slots": { + "default": "Allows you to provide a custom shell bar logo. If used, this will replace the img-element which is rendered per default." + }, "events": {}, "mixins": [], "props": { "src": { "name": "src", "description": "image source", - "required": true, + "required": false, "types": ["String"] }, "srcset": { @@ -1156,7 +1158,9 @@ "componentName": "FdShellBarProductSwitcherItem" }, "FdShellBarProductSwitcherItemImg": { - "slots": {}, + "slots": { + "default": "Allows you to provide a custom product logo. If used, this will replace the img-element which is rendered per default." + }, "events": {}, "mixins": [], "props": { @@ -1165,7 +1169,7 @@ "description": "image source", "required": false, "types": ["String"], - "defaultValue": "" + "defaultValue": null } }, "componentName": "FdShellBarProductSwitcherItemImg" diff --git a/docs/src/layouts/DefaultLayout.vue b/docs/src/layouts/DefaultLayout.vue index ed9251d4..38c69767 100644 --- a/docs/src/layouts/DefaultLayout.vue +++ b/docs/src/layouts/DefaultLayout.vue @@ -7,7 +7,9 @@ src="/images/logo.png" srcset="/images/logo.png 1x, /images/logo@2x.png 2x" /> - Fundamental Vue + + Fundamental Vue + diff --git a/ui/src/components/Layout/ShellBar/ShellBarLogo.vue b/ui/src/components/Layout/ShellBar/ShellBarLogo.vue index 0dff3ade..087b9054 100644 --- a/ui/src/components/Layout/ShellBar/ShellBarLogo.vue +++ b/ui/src/components/Layout/ShellBar/ShellBarLogo.vue @@ -1,6 +1,8 @@ @@ -9,15 +11,10 @@ import { withTargetLocation, mixins } from "@/mixins"; export default mixins(withTargetLocation("/")).extend({ name: "FdShellBarLogo", + inheritAttrs: false, props: { - src: { - type: String, - required: true - }, - srcset: { - type: String, - default: null - } + src: String, + srcset: String } }); diff --git a/ui/src/components/Layout/ShellBar/ShellBarProductSwitcherItemImg.vue b/ui/src/components/Layout/ShellBar/ShellBarProductSwitcherItemImg.vue index 429eed16..4ec4b713 100644 --- a/ui/src/components/Layout/ShellBar/ShellBarProductSwitcherItemImg.vue +++ b/ui/src/components/Layout/ShellBar/ShellBarProductSwitcherItemImg.vue @@ -1,6 +1,8 @@ @@ -8,8 +10,9 @@ import Vue from "vue"; export default Vue.extend({ name: "FdShellBarProductSwitcherItemImg", + inheritAttrs: false, props: { - src: { type: String, default: "" } + src: String } }); diff --git a/ui/src/components/Layout/ShellBar/__tests__/ShellBarLogo.test.ts b/ui/src/components/Layout/ShellBar/__tests__/ShellBarLogo.test.ts new file mode 100644 index 00000000..1b1356f2 --- /dev/null +++ b/ui/src/components/Layout/ShellBar/__tests__/ShellBarLogo.test.ts @@ -0,0 +1,17 @@ +import FdShellBarLogo from "./../ShellBarLogo.vue"; +import { mount, createLocalVue } from "@vue/test-utils"; + +describe("ShellBarLogo", () => { + // Test for https://github.com/SAP/fundamental-vue/issues/154 + it("puts alt on logo", async () => { + const localVue = createLocalVue(); + const wrapper = mount({ + components: { FdShellBarLogo }, + template: `` + }, { localVue }); + await localVue.nextTick(); + const img = wrapper.find("img"); + expect(img.exists()).toBe(true); + expect(img.attributes("alt")).toBe("helloWorld"); + }) +}); diff --git a/ui/src/components/Layout/ShellBar/__tests__/ShellBarProductSwitcherItemImg.test.ts b/ui/src/components/Layout/ShellBar/__tests__/ShellBarProductSwitcherItemImg.test.ts new file mode 100644 index 00000000..cb02853d --- /dev/null +++ b/ui/src/components/Layout/ShellBar/__tests__/ShellBarProductSwitcherItemImg.test.ts @@ -0,0 +1,17 @@ +import FdShellBarProductSwitcherItemImg from "./../ShellBarProductSwitcherItemImg.vue"; +import { mount, createLocalVue } from "@vue/test-utils"; + +describe("ShellBarProductSwitcherItemImg", () => { + // Test for https://github.com/SAP/fundamental-vue/issues/139 + it("puts alt on logo", async () => { + const localVue = createLocalVue(); + const wrapper = mount({ + components: { FdShellBarProductSwitcherItemImg }, + template: `` + }, { localVue }); + await localVue.nextTick(); + const img = wrapper.find("img"); + expect(img.exists()).toBe(true); + expect(img.attributes("alt")).toBe("helloWorld"); + }) +}); diff --git a/ui/src/mixins/withTargetLocation.ts b/ui/src/mixins/withTargetLocation.ts index 0052e44d..8852fa4b 100644 --- a/ui/src/mixins/withTargetLocation.ts +++ b/ui/src/mixins/withTargetLocation.ts @@ -11,13 +11,13 @@ export default (defaultTo: string | object | null = null) => > }, methods: { - pushLocationIfPossible(event?: Event, onComplete?: typeof noop) { + pushLocationIfPossible(event?: Event, onComplete = noop) { if (this.to == null || this.$router == null) { return; } this.pushLocation(event, onComplete); }, - pushLocation(event?: Event, onComplete?: typeof noop) { + pushLocation(event?: Event, onComplete = noop) { if (event) { event.preventDefault(); event.stopPropagation(); @@ -33,7 +33,7 @@ export default (defaultTo: string | object | null = null) => warn(`Tried to navigate to ${to} but $router not found.`); return; } - $router.push(to, onComplete || noop); + $router.push(to, onComplete); this.$emit("click", event); } }