Skip to content

Commit d3066cc

Browse files
committed
feat: add tests for responsive <bolt-navbar> width in a variable width grid cell
1 parent 67406c9 commit d3066cc

File tree

1 file changed

+130
-69
lines changed
  • packages/components/bolt-navbar/__tests__

1 file changed

+130
-69
lines changed

packages/components/bolt-navbar/__tests__/navbar.js

Lines changed: 130 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ async function renderTwig(template, data) {
1111
return await render(template, data, true);
1212
}
1313

14+
async function renderTwigString(template, data) {
15+
return await renderString(template, data, true);
16+
}
17+
1418
const timeout = 60000;
1519

1620
const viewportSizes = [
@@ -137,7 +141,7 @@ describe('<bolt-navbar> Component', async () => {
137141
}
138142

139143
await processViewportSizes(viewportSizes);
140-
}, 10000);
144+
}, 15000);
141145

142146
test('<bolt-navbar> with a linked title', async () => {
143147
const { html, ok } = await renderTwig(
@@ -190,15 +194,16 @@ describe('<bolt-navbar> Component', async () => {
190194
document.body.appendChild(div);
191195
}, html);
192196

197+
await page.hover('.c-bolt-navbar__title--link');
198+
193199
const image = await page.screenshot();
194200
expect(image).toMatchImageSnapshot();
195201

196202
await page.tap('.c-bolt-navbar__title--link');
197203

198204
const pageTitle = await page.title();
199205
expect(pageTitle).toMatch('Bolt Design System');
200-
201-
}, 20000);
206+
}, 15000);
202207

203208
test('<bolt-navbar> with 4 short links', async () => {
204209
const { html, ok } = await renderTwig(
@@ -291,7 +296,7 @@ describe('<bolt-navbar> Component', async () => {
291296
}
292297

293298
await processViewportSizes(viewportSizes);
294-
}, 10000);
299+
}, 15000);
295300

296301
test('<bolt-navbar> centered with 4 short links', async () => {
297302
const { html, ok } = await renderTwig(
@@ -385,7 +390,7 @@ describe('<bolt-navbar> Component', async () => {
385390
}
386391

387392
await processViewportSizes(viewportSizes);
388-
}, 10000);
393+
}, 15000);
389394

390395
test('<bolt-navbar> without links', async () => {
391396
const { html, ok } = await renderTwig(
@@ -423,68 +428,124 @@ describe('<bolt-navbar> Component', async () => {
423428
failureThreshold: '0.01',
424429
failureThresholdType: 'percent',
425430
});
426-
});
427-
428-
// test('Default <bolt-ratio> w/o Shadow DOM renders', async function() {
429-
// const renderedRatioHTML = await page.evaluate(() => {
430-
// const ratio = document.createElement('bolt-ratio');
431-
// const img = document.createElement('img');
432-
// img.setAttribute('src', '/fixtures/1200x660.jpg');
433-
434-
// ratio.setAttribute('no-shadow', '');
435-
// ratio.setAttribute('ratio', '1200/660');
436-
// ratio.appendChild(img);
437-
438-
// document.body.appendChild(ratio);
439-
// return ratio.outerHTML;
440-
// });
441-
// expect(renderedRatioHTML).toMatchSnapshot();
442-
443-
// const image = await page.screenshot();
444-
// expect(image).toMatchImageSnapshot({
445-
// failureThreshold: '0.01',
446-
// failureThresholdType: 'percent',
447-
// });
448-
449-
// const renderedRatioStyles = await page.evaluate(() => {
450-
// const ratio = document.querySelector('bolt-ratio');
451-
// const innerRatio = ratio.renderRoot.querySelector('.c-bolt-ratio');
452-
// return innerRatio.style.getPropertyValue('--aspect-ratio').trim();
453-
// });
454-
455-
// expect(renderedRatioStyles).toMatch(parseFloat(1200 / 660).toFixed(5));
456-
// });
457-
458-
// test('<bolt-ratio> with HTML5 video renders', async function() {
459-
// const renderedRatioHTML = await page.evaluate(() => {
460-
// const ratio = document.createElement('bolt-ratio');
461-
462-
// ratio.innerHTML = `<video controls poster="/fixtures/poster.png">
463-
// <source src="/fixtures/devstories.webm" type="video/webm;codecs=&quot;vp8, vorbis&quot;">
464-
// <source src="/fixtures/devstories.mp4" type="video/mp4;codecs=&quot;avc1.42E01E, mp4a.40.2&quot;">
465-
// <track src="/fixtures/devstories-en.vtt" label="English subtitles" kind="subtitles" srclang="en" default="">
466-
// </video>`;
467-
// ratio.setAttribute('ratio', '640/360');
468-
// ratio.style.width = '640px';
469-
// document.body.appendChild(ratio);
470-
// return ratio.outerHTML;
471-
// });
472-
473-
// const renderedRatioSize = await page.evaluate(() => {
474-
// const ratioSize = {
475-
// width: document.querySelector('bolt-ratio').clientWidth,
476-
// height: document.querySelector('bolt-ratio').clientHeight,
477-
// };
478-
// return ratioSize;
479-
// });
480-
481-
// const image = await page.screenshot();
482-
483-
// expect(image).toMatchImageSnapshot({
484-
// failureThreshold: '0.01',
485-
// failureThresholdType: 'percent',
486-
// });
487-
488-
// expect(renderedRatioHTML).toMatchSnapshot();
489-
// });
431+
}, 15000);
432+
433+
test('<bolt-navbar> without a title', async () => {
434+
const { html, ok } = await renderTwig(
435+
'@bolt-components-navbar/navbar.twig',
436+
{
437+
links: [
438+
{
439+
text: 'Components',
440+
url: '/pattern-lab/index.html',
441+
},
442+
{
443+
text: 'Docs',
444+
url: '/docs/getting-started/index.html',
445+
},
446+
{
447+
text: 'Releases',
448+
url: 'https://github.com/bolt-design-system/bolt/releases',
449+
attributes: {
450+
target: '_blank',
451+
},
452+
},
453+
{
454+
text: 'Github',
455+
url: 'https://github.com/bolt-design-system/bolt',
456+
attributes: {
457+
target: '_blank',
458+
},
459+
icon: {
460+
name: 'github',
461+
position: 'after',
462+
},
463+
},
464+
],
465+
},
466+
);
467+
expect(ok).toBe(true);
468+
expect(html).toMatchSnapshot();
469+
470+
await page.evaluate(html => {
471+
const div = document.createElement('div');
472+
div.innerHTML = `${html}`;
473+
document.body.appendChild(div);
474+
}, html);
475+
const largeViewport = await page.screenshot();
476+
477+
expect(largeViewport).toMatchImageSnapshot({
478+
failureThreshold: '0.01',
479+
failureThresholdType: 'percent',
480+
});
481+
482+
await page.setViewport({ height: 568, width: 320 });
483+
const smallViewport = await page.screenshot();
484+
485+
expect(smallViewport).toMatchImageSnapshot({
486+
failureThreshold: '0.01',
487+
failureThresholdType: 'percent',
488+
});
489+
}, 15000);
490+
491+
test('<bolt-navbar> variable width', async () => {
492+
const { html, ok } = await renderTwigString(`
493+
{% grid "o-bolt-grid--center" %}
494+
{% cell "u-bolt-width-2/3 u-bolt-width-1/2@small" %}
495+
{% include "@bolt-components-navbar/navbar.twig" with {
496+
width: 'auto',
497+
links: [
498+
{
499+
text: 'Components',
500+
url: '/pattern-lab/index.html',
501+
},
502+
{
503+
text: 'Docs',
504+
url: '/docs/getting-started/index.html',
505+
},
506+
{
507+
text: 'Releases',
508+
url: 'https://github.com/bolt-design-system/bolt/releases',
509+
attributes: {
510+
target: '_blank',
511+
},
512+
},
513+
{
514+
text: 'Github',
515+
url: 'https://github.com/bolt-design-system/bolt',
516+
attributes: {
517+
target: '_blank',
518+
},
519+
icon: {
520+
name: 'github',
521+
position: 'after',
522+
},
523+
},
524+
],
525+
} only %}
526+
{% endcell %}
527+
{% endgrid %}
528+
`);
529+
expect(ok).toBe(true);
530+
expect(html).toMatchSnapshot();
531+
532+
await page.evaluate(html => {
533+
const div = document.createElement('div');
534+
div.innerHTML = `${html}`;
535+
document.body.appendChild(div);
536+
}, html);
537+
538+
async function processViewportSizes(viewportSizes) {
539+
for (const item of viewportSizes) {
540+
const { height, width, size } = item;
541+
screenshots[size] = [];
542+
543+
await page.setViewport({ height, width });
544+
screenshots[size].default = await page.screenshot();
545+
expect(screenshots[size].default).toMatchImageSnapshot();
546+
}
547+
}
548+
549+
await processViewportSizes(viewportSizes);
550+
}, 15000);
490551
});

0 commit comments

Comments
 (0)