Skip to content

Commit 7d3fe4d

Browse files
committed
improve test coverage, update screenshots
1 parent b57c14f commit 7d3fe4d

16 files changed

+98
-24
lines changed

packages/master-detail-layout/src/styles/vaadin-master-detail-layout-base-styles.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ export const masterDetailLayoutStyles = css`
104104
}
105105
106106
:host([recalculating-detail-size]:is([has-detail], [has-detail-placeholder])) {
107-
--_master-extra: 0px;
108107
--_detail-extra: 0px;
109108
}
110109
111110
:host([keep-detail-column-offscreen]),
112-
:host([keep-detail-column-offscreen][recalculating-detail-size]),
113111
:host([has-detail-placeholder][overlay]),
114112
:host(:not([has-detail-placeholder], [has-detail])) {
115113
--_master-extra: calc(100% - var(--_master-size));

packages/master-detail-layout/test/detail-auto-size.test.js

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ window.Vaadin.featureFlags.masterDetailLayoutComponent = true;
1111
describe('detail auto size', () => {
1212
let layout;
1313

14-
beforeEach(async () => {
15-
layout = fixtureSync(`
16-
<vaadin-master-detail-layout>
17-
<div>Master</div>
18-
<div slot="detail">Detail</div>
19-
</vaadin-master-detail-layout>
20-
`);
21-
await onceResized(layout);
22-
});
14+
describe('basic', () => {
15+
beforeEach(async () => {
16+
layout = fixtureSync(`
17+
<vaadin-master-detail-layout>
18+
<div>Master</div>
19+
<div slot="detail">Detail</div>
20+
</vaadin-master-detail-layout>
21+
`);
22+
await onceResized(layout);
23+
});
2324

24-
describe('recalculateLayout', () => {
2525
it('should not be called when masterSize and detailSize are provided initially', async () => {
2626
const newLayout = fixtureSync(`
2727
<vaadin-master-detail-layout master-size="200px" detail-size="200px">
@@ -53,4 +53,73 @@ describe('detail auto size', () => {
5353
expect(() => layout.recalculateLayout()).to.not.throw();
5454
});
5555
});
56+
57+
describe('nested layouts', () => {
58+
let outer, middle, inner;
59+
60+
function getCachedSize(layout) {
61+
return layout.style.getPropertyValue('--_detail-cached-size');
62+
}
63+
64+
beforeEach(async () => {
65+
outer = fixtureSync(`
66+
<vaadin-master-detail-layout style="width: 1200px;" master-size="100px" expand="both">
67+
<div>Outer Master</div>
68+
<vaadin-master-detail-layout slot="detail" master-size="100px">
69+
<div>Middle Master</div>
70+
<vaadin-master-detail-layout slot="detail" master-size="100px">
71+
<div>Inner Master</div>
72+
<div slot="detail" style="width: 100px;">Inner Detail</div>
73+
</vaadin-master-detail-layout>
74+
</vaadin-master-detail-layout>
75+
</vaadin-master-detail-layout>
76+
`);
77+
middle = outer.querySelector('vaadin-master-detail-layout');
78+
inner = middle.querySelector('vaadin-master-detail-layout');
79+
await onceResized(outer);
80+
await onceResized(middle);
81+
await onceResized(inner);
82+
});
83+
84+
it('should cache detail intrinsic size plus border at each level', () => {
85+
// Inner: 100px detail content + 1px border = 101px
86+
expect(getCachedSize(inner)).to.equal('101px');
87+
// Middle: inner layout min-content (100px master + 101px detail) + 1px border = 202px
88+
expect(getCachedSize(middle)).to.equal('202px');
89+
// Outer: middle layout min-content (100px master + 202px detail) + 1px border = 303px
90+
expect(getCachedSize(outer)).to.equal('303px');
91+
});
92+
93+
it('should not cache detail size when detailSize is explicitly set', async () => {
94+
outer.detailSize = '300px';
95+
await onceResized(outer);
96+
expect(getCachedSize(outer)).to.equal('');
97+
});
98+
99+
describe('recalculateLayout', () => {
100+
it('should update cached sizes on ancestors after detail content changes', () => {
101+
inner.querySelector('[slot="detail"]').style.width = '200px';
102+
inner.recalculateLayout();
103+
104+
expect(getCachedSize(inner)).to.equal('201px');
105+
expect(getCachedSize(middle)).to.equal('302px');
106+
expect(getCachedSize(outer)).to.equal('403px');
107+
});
108+
109+
it('should toggle overlay on ancestors when detail content outgrows or fits available space', () => {
110+
// Outer: 100px master + 303px detail = 403px, host is 1200px → no overlay
111+
expect(outer.hasAttribute('overlay')).to.be.false;
112+
113+
// Grow inner detail so outer needs 100px + 1103px = 1203px > 1200px
114+
inner.querySelector('[slot="detail"]').style.width = '1000px';
115+
inner.recalculateLayout();
116+
expect(outer.hasAttribute('overlay')).to.be.true;
117+
118+
// Shrink back so outer needs 100px + 303px = 403px < 1200px
119+
inner.querySelector('[slot="detail"]').style.width = '100px';
120+
inner.recalculateLayout();
121+
expect(outer.hasAttribute('overlay')).to.be.false;
122+
});
123+
});
124+
});
56125
});

packages/master-detail-layout/test/visual/base/master-detail-layout.test.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,17 @@ describe('master-detail-layout', () => {
152152
let layouts;
153153

154154
function openDetail(layout) {
155-
layout._setDetail(layout.querySelector(':scope > [slot="detail-hidden"]'));
155+
return layout._setDetail(layout.querySelector(':scope > [slot="detail-hidden"]'));
156156
}
157157

158158
beforeEach(async () => {
159159
mdl = fixtureSync(
160160
`
161-
<vaadin-master-detail-layout master-size="300px" no-animation style="height: 400px; border: 1px solid lightgray;">
161+
<vaadin-master-detail-layout expand="detail" master-size="300px" no-animation style="max-width: calc(300px + 250px + 200px + 100px + 1px * 3); height: 400px; border: 1px solid lightgray;">
162162
<div>Master 0</div>
163-
<vaadin-master-detail-layout master-size="250px" no-animation slot="detail-hidden">
163+
<vaadin-master-detail-layout expand="detail" master-size="250px" no-animation slot="detail-hidden">
164164
<div>Master 1</div>
165-
<vaadin-master-detail-layout master-size="200px" no-animation slot="detail-hidden">
165+
<vaadin-master-detail-layout expand="detail" master-size="200px" no-animation slot="detail-hidden">
166166
<div>Master 2</div>
167167
<div slot="detail-hidden" style="min-width: 100px">Detail 2</div>
168168
</vaadin-master-detail-layout>
@@ -173,27 +173,34 @@ describe('master-detail-layout', () => {
173173
);
174174

175175
layouts = [...div.querySelectorAll('vaadin-master-detail-layout')];
176-
await onceResized(mdl);
176+
await onceResized(div);
177177
});
178178

179179
it('default', async () => {
180-
await visualDiff(div, 'detail-auto-size-default');
180+
await visualDiff(div, `detail-auto-size`);
181181
});
182182

183183
[0, 1, 2].forEach((depth) => {
184184
it(`opened (depth ${depth})`, async () => {
185-
layouts.slice(0, depth + 1).forEach(openDetail);
186-
await onceResized(mdl);
187-
await visualDiff(div, `detail-auto-size-opened-depth-${depth}`);
185+
for (const layout of layouts.slice(0, depth + 1)) {
186+
await openDetail(layout);
187+
}
188+
await onceResized(div);
189+
await visualDiff(div, `detail-auto-size-opened-${depth}`);
188190
});
189191
});
190192

191193
['600px', '400px', '200px'].forEach((width, depth) => {
192194
it(`overflow (depth ${depth})`, async () => {
193-
layouts.forEach(openDetail);
194195
div.style.width = width;
195-
await onceResized(mdl);
196-
await visualDiff(div, `detail-auto-size-overflow-depth-${depth}`);
196+
await onceResized(div);
197+
198+
for (const layout of layouts) {
199+
await openDetail(layout);
200+
}
201+
202+
await onceResized(div);
203+
await visualDiff(div, `detail-auto-size-overflow-${depth}`);
197204
});
198205
});
199206
});
3.64 KB
Loading

0 commit comments

Comments
 (0)