From 9f4af5628b36f18311b26a90ca00d2e2a3cf2885 Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Thu, 2 Jul 2020 14:30:04 +0200 Subject: [PATCH 1/6] Allow empty `alt` --- src/components/card/card-img.js | 3 ++- src/components/image/img.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/card/card-img.js b/src/components/card/card-img.js index 53592e441af..86f238dcddf 100644 --- a/src/components/card/card-img.js +++ b/src/components/card/card-img.js @@ -1,4 +1,5 @@ import Vue from '../../utils/vue' +import { isString } from '../../utils/inspect' import { mergeData } from 'vue-functional-data-merge' export const props = { @@ -69,7 +70,7 @@ export const BCardImg = /*#__PURE__*/ Vue.extend({ class: [baseClass], attrs: { src: props.src || null, - alt: props.alt || null, + alt: isString(props.alt) ? props.alt : null, height: props.height || null, width: props.width || null } diff --git a/src/components/image/img.js b/src/components/image/img.js index 3f69d25467d..19c0d3574dd 100644 --- a/src/components/image/img.js +++ b/src/components/image/img.js @@ -153,7 +153,7 @@ export const BImg = /*#__PURE__*/ Vue.extend({ mergeData(data, { attrs: { src: src, - alt: props.alt || null, + alt: isString(props.alt) ? props.alt : null, width: width ? toString(width) : null, height: height ? toString(height) : null, srcset: srcset || null, From a5408bbeebef6fd8903a67e9c2b1629f0f1c3d23 Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Mon, 6 Jul 2020 09:11:15 +0200 Subject: [PATCH 2/6] default to null to avoid check --- src/components/card/card-img.js | 6 +++--- src/components/image/img.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/card/card-img.js b/src/components/card/card-img.js index 86f238dcddf..3bf726ba3dd 100644 --- a/src/components/card/card-img.js +++ b/src/components/card/card-img.js @@ -8,8 +8,8 @@ export const props = { required: true }, alt: { - type: String - // default: null + type: String, + default: null }, top: { type: Boolean, @@ -70,7 +70,7 @@ export const BCardImg = /*#__PURE__*/ Vue.extend({ class: [baseClass], attrs: { src: props.src || null, - alt: isString(props.alt) ? props.alt : null, + alt: props.alt, height: props.height || null, width: props.width || null } diff --git a/src/components/image/img.js b/src/components/image/img.js index 19c0d3574dd..3d938947033 100644 --- a/src/components/image/img.js +++ b/src/components/image/img.js @@ -33,8 +33,8 @@ export const props = { // default: null }, alt: { - type: String - // default: null + type: String, + default: null }, width: { type: [Number, String] @@ -153,7 +153,7 @@ export const BImg = /*#__PURE__*/ Vue.extend({ mergeData(data, { attrs: { src: src, - alt: isString(props.alt) ? props.alt : null, + alt: props.alt, width: width ? toString(width) : null, height: height ? toString(height) : null, srcset: srcset || null, From 4ee7a53e65673b9c649391faeb45abdb9867b791 Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Mon, 6 Jul 2020 09:12:23 +0200 Subject: [PATCH 3/6] remove unused import --- src/components/card/card-img.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/card/card-img.js b/src/components/card/card-img.js index 3bf726ba3dd..8d38397b2b7 100644 --- a/src/components/card/card-img.js +++ b/src/components/card/card-img.js @@ -1,5 +1,4 @@ import Vue from '../../utils/vue' -import { isString } from '../../utils/inspect' import { mergeData } from 'vue-functional-data-merge' export const props = { From 5bb60542c490bfeef4e3b254903ac770f430ec7e Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Mon, 6 Jul 2020 10:58:27 +0200 Subject: [PATCH 4/6] add avatar support --- src/components/avatar/avatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/avatar/avatar.js b/src/components/avatar/avatar.js index 6af4e2b6e20..c62985e5efe 100644 --- a/src/components/avatar/avatar.js +++ b/src/components/avatar/avatar.js @@ -202,7 +202,7 @@ export const BAvatar = /*#__PURE__*/ Vue.extend({ } = this const link = !button && isLink(this) const tag = button ? BButton : link ? BLink : 'span' - const alt = this.alt || null + const alt = this.alt const ariaLabel = this.ariaLabel || null let $content = null From c6e98743fa10e7ad5f20385f79b0e68c3a374ba3 Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Mon, 6 Jul 2020 13:52:41 +0200 Subject: [PATCH 5/6] add test cases --- src/components/avatar/avatar.spec.js | 30 +++++++++++++++++++++++ src/components/card/card-img-lazy.spec.js | 16 ++++++++++++ src/components/card/card-img.spec.js | 16 ++++++++++++ src/components/image/img.spec.js | 29 ++++++++++++++++++++++ 4 files changed, 91 insertions(+) diff --git a/src/components/avatar/avatar.spec.js b/src/components/avatar/avatar.spec.js index 8f96e71156e..0123f5574bb 100644 --- a/src/components/avatar/avatar.spec.js +++ b/src/components/avatar/avatar.spec.js @@ -317,4 +317,34 @@ describe('avatar', () => { wrapper2.destroy() }) + + it('should render `alt` attribute if `alt` prop is empty string', async () => { + const wrapper = mount(BAvatar, { + propsData: { + src: '/foo/bar', + alt: '' + } + }) + expect(wrapper.vm).toBeDefined() + expect(wrapper.find('img').exists()).toBe(true) + expect(wrapper.find('img').attributes('src')).toEqual('/foo/bar') + expect(wrapper.find('img').attributes('alt')).toEqual('') + + wrapper.destroy() + }) + + it('should not render `alt` attribute if `alt` prop is null', async () => { + const wrapper = mount(BAvatar, { + propsData: { + src: '/foo/bar', + alt: null + } + }) + expect(wrapper.vm).toBeDefined() + expect(wrapper.find('img').exists()).toBe(true) + expect(wrapper.find('img').attributes('src')).toEqual('/foo/bar') + expect(wrapper.find('img').attributes('alt')).not.toBeDefined() + + wrapper.destroy() + }) }) diff --git a/src/components/card/card-img-lazy.spec.js b/src/components/card/card-img-lazy.spec.js index b41290ec320..6513247e0a1 100644 --- a/src/components/card/card-img-lazy.spec.js +++ b/src/components/card/card-img-lazy.spec.js @@ -154,6 +154,22 @@ describe('card-image', () => { wrapper.destroy() }) + it('has attribute alt when prop `alt` empty', async () => { + const wrapper = mount(BCardImgLazy, { + context: { + props: { + src: 'https://picsum.photos/600/300/?image=25', + alt: '' + } + } + }) + + expect(wrapper.attributes('alt')).toBeDefined() + expect(wrapper.attributes('alt')).toBe('') + + wrapper.destroy() + }) + it('has attribute width when prop width set', async () => { const wrapper = mount(BCardImgLazy, { context: { diff --git a/src/components/card/card-img.spec.js b/src/components/card/card-img.spec.js index ee1a51a5847..d0f68758348 100644 --- a/src/components/card/card-img.spec.js +++ b/src/components/card/card-img.spec.js @@ -158,6 +158,22 @@ describe('card-image', () => { wrapper.destroy() }) + it('has attribute alt when prop `alt` empty', async () => { + const wrapper = mount(BCardImg, { + context: { + props: { + src: 'https://picsum.photos/600/300/?image=25', + alt: '' + } + } + }) + + expect(wrapper.attributes('alt')).toBeDefined() + expect(wrapper.attributes('alt')).toBe('') + + wrapper.destroy() + }) + it('has attribute width when prop width set', async () => { const wrapper = mount(BCardImg, { context: { diff --git a/src/components/image/img.spec.js b/src/components/image/img.spec.js index 9b075f6dc4c..5399fda3818 100644 --- a/src/components/image/img.spec.js +++ b/src/components/image/img.spec.js @@ -30,6 +30,22 @@ describe('img', () => { wrapper.destroy() }) + it('default does not have attributes alt, width, or height', async () => { + const wrapper = mount(BImg, { + context: { + props: { + src: 'https://picsum.photos/600/300/?image=25' + } + } + }) + + expect(wrapper.attributes('alt')).not.toBeDefined() + expect(wrapper.attributes('width')).not.toBeDefined() + expect(wrapper.attributes('height')).not.toBeDefined() + + wrapper.destroy() + }) + it('should have class "img-fluid" when prop fluid set', async () => { const wrapper = mount(BImg, { propsData: { @@ -223,4 +239,17 @@ describe('img', () => { wrapper.destroy() }) + + it('should have alt attribute when `alt` prop is empty', async () => { + const wrapper = mount(BImg, { + propsData: { + alt: '' + } + }) + + expect(wrapper.attributes('alt')).toBeDefined() + expect(wrapper.attributes('alt')).toEqual('') + + wrapper.destroy() + }) }) From 8aff8b7c707a20cc7e5c8d5ad4a0260e6b93296d Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen - Nova Consult ApS Date: Mon, 6 Jul 2020 13:54:48 +0200 Subject: [PATCH 6/6] spelling --- src/components/card/card-img-lazy.spec.js | 2 +- src/components/card/card-img.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/card/card-img-lazy.spec.js b/src/components/card/card-img-lazy.spec.js index 6513247e0a1..c5344e631da 100644 --- a/src/components/card/card-img-lazy.spec.js +++ b/src/components/card/card-img-lazy.spec.js @@ -154,7 +154,7 @@ describe('card-image', () => { wrapper.destroy() }) - it('has attribute alt when prop `alt` empty', async () => { + it('has attribute alt when prop `alt` is empty', async () => { const wrapper = mount(BCardImgLazy, { context: { props: { diff --git a/src/components/card/card-img.spec.js b/src/components/card/card-img.spec.js index d0f68758348..89b41e63634 100644 --- a/src/components/card/card-img.spec.js +++ b/src/components/card/card-img.spec.js @@ -158,7 +158,7 @@ describe('card-image', () => { wrapper.destroy() }) - it('has attribute alt when prop `alt` empty', async () => { + it('has attribute alt when prop `alt` is empty', async () => { const wrapper = mount(BCardImg, { context: { props: {