From 97cb50aec5417e3325e58c239c0feca2dca815fe Mon Sep 17 00:00:00 2001 From: Matthew White Date: Fri, 13 Dec 2024 14:51:41 -0500 Subject: [PATCH 1/2] Resize hover cards only based on
, not .hover-card-title --- src/components/hover-card.vue | 66 +++++++++++--------- test/components/hover-card.spec.js | 97 ++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 28 deletions(-) diff --git a/src/components/hover-card.vue b/src/components/hover-card.vue index 33cc844dd..6e110329c 100644 --- a/src/components/hover-card.vue +++ b/src/components/hover-card.vue @@ -28,7 +28,7 @@ except according to the terms contained in the LICENSE file. diff --git a/test/components/hover-card.spec.js b/test/components/hover-card.spec.js index 172db4f41..f2bfe80e5 100644 --- a/test/components/hover-card.spec.js +++ b/test/components/hover-card.spec.js @@ -1,4 +1,9 @@ +import { nextTick } from 'vue'; + import HoverCard from '../../src/components/hover-card.vue'; +import Popover from '../../src/components/popover.vue'; + +import { truncatesText } from '../../src/util/dom'; import { mount } from '../util/lifecycle'; @@ -10,4 +15,96 @@ describe('HoverCard', () => { const icon = component.get('.hover-card-heading span'); icon.classes('icon-file').should.be.true; }); + + describe('truncateDt prop', () => { + const Parent = { + template: ` + + + + + + `, + components: { HoverCard, Popover }, + props: { + title: { + type: String, + default: 'x' + }, + dt: { + type: String, + required: true + }, + dd: { + type: String, + default: 'x' + }, + truncateDt: { + type: Boolean, + // This is the opposite of the default in HoverCard. + default: false + } + } + }; + const setupResize = async (props) => { + const component = mount(Parent, { props, attachTo: document.body }); + // Wait a tick for the resize to happen. + await nextTick(); + + const { width: hoverCardWidth } = component.get('.hover-card').element + .getBoundingClientRect(); + const { width: dtWidth } = component.get('dt').element + .getBoundingClientRect(); + const { width: ddWidth } = component.get('dd').element + .getBoundingClientRect(); + // 2 for the border. + hoverCardWidth.should.equal(dtWidth + ddWidth + 2); + + return { component, dtWidth, ddWidth }; + }; + + const xs = (count) => 'x'.repeat(count); + + it('truncates the
if truncateDt is true', async () => { + const { component, dtWidth, ddWidth } = await setupResize({ + dt: xs(50), + truncateDt: true + }); + dtWidth.should.equal(144); + // There aren't any tooltips, so we'll assert text truncation this way. + truncatesText(component.get('dt').element).should.be.true; + ddWidth.should.equal(144); + }); + + it('allows the
to grow if truncateDt is false', async () => { + const { component, dtWidth, ddWidth } = await setupResize({ + dt: xs(50) + }); + dtWidth.should.be.above(300); + truncatesText(component.get('dt').element).should.be.false; + ddWidth.should.be.below(50); + }); + + it('allows the
to grow up to the width of the
', async () => { + const { component, dtWidth, ddWidth } = await setupResize({ + dt: xs(50), + dd: xs(100) + }); + dtWidth.should.be.above(300); + ddWidth.should.equal(dtWidth); + truncatesText(component.get('dd').element).should.be.true; + }); + + it('does not allow the title to grow arbitrarily wide', async () => { + const { component, ddWidth } = await setupResize({ + dt: xs(50), + title: xs(100) + }); + truncatesText(component.get('.hover-card-title').element).should.be.true; + // The long title should not cause the
to grow. + ddWidth.should.be.below(50); + }); + }); }); From 680fe73662d7920ea92fc368f33c529cf63ddd95 Mon Sep 17 00:00:00 2001 From: Matthew White Date: Mon, 16 Dec 2024 01:04:39 -0500 Subject: [PATCH 2/2] Make changes after code review --- src/components/hover-card.vue | 56 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/components/hover-card.vue b/src/components/hover-card.vue index 6e110329c..076081d2f 100644 --- a/src/components/hover-card.vue +++ b/src/components/hover-card.vue @@ -28,7 +28,7 @@ except according to the terms contained in the LICENSE file.