Skip to content

Commit

Permalink
feat: first round of ratio component jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sghoweri committed Feb 21, 2019
1 parent 754dfd7 commit c17a6b2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -9,3 +9,13 @@ exports[`<bolt-ratio> Component <bolt-ratio> compiles 1`] = `
</bolt-ratio>
`;
exports[`<bolt-ratio> Component Default <bolt-ratio> w/o Shadow DOM renders 2`] = `
<bolt-ratio ratio="1200/660"
style="--aspect-ratio:1200/660;"
>
<img src="/fixtures/1200x660.jpg">
</bolt-ratio>
`;
60 changes: 59 additions & 1 deletion packages/components/bolt-ratio/__tests__/ratio.js
@@ -1,6 +1,32 @@
const { render } = require('@bolt/twig-renderer');
import {
render,
renderString,
stop as stopTwigRenderer,
} from '@bolt/twig-renderer';
import { fixture as html } from '@open-wc/testing-helpers';

async function renderTwig(template, data) {
return await render(template, data, true);
}

const timeout = 60000;

describe('<bolt-ratio> Component', async () => {
let page;

afterAll(async () => {
await stopTwigRenderer();
}, timeout);

beforeEach(async () => {
page = await global.__BROWSER__.newPage();
await page.goto('http://127.0.0.1:4444/', {
timeout: 0,
waitLoad: true,
waitNetworkIdle: true, // defaults to false
});
}, timeout);

test('<bolt-ratio> compiles', async () => {
const results = await render('@bolt-components-ratio/ratio.twig', {
children: '<img src="/fixtures/1200x660.jpg">',
Expand All @@ -9,4 +35,36 @@ describe('<bolt-ratio> Component', async () => {
expect(results.ok).toBe(true);
expect(results.html).toMatchSnapshot();
});

test('Default <bolt-ratio> w/o Shadow DOM renders', async function() {
const renderedRatioHTML = await page.evaluate(() => {
const ratio = document.createElement('bolt-ratio');
const img = document.createElement('img');
img.setAttribute('src', 'http://127.0.0.1:4444/fixtures/1200x660.jpg');

ratio.setAttribute('ratio', '1200/660');
ratio.appendChild(img);

document.body.appendChild(ratio);
ratio.useShadow = false;
ratio.updated();
return ratio.outerHTML;
});

const image = await page.screenshot();

const renderedRatioStyles = await page.evaluate(() => {
const ratio = document.querySelector('bolt-ratio');
return ratio.style.getPropertyValue('--aspect-ratio').trim();
});

expect(renderedRatioStyles).toMatch('1200/660');

expect(image).toMatchImageSnapshot({
failureThreshold: '0.01',
failureThresholdType: 'percent',
});

expect(renderedRatioHTML).toMatchSnapshot();
});
});
1 change: 0 additions & 1 deletion packages/components/bolt-ratio/src/ratio.js
Expand Up @@ -16,7 +16,6 @@ function BoltRatio() {

constructor(self) {
self = super(self);
this.useShadow = hasNativeShadowDomSupport;
this.useCssVars = supportsCSSVars;
return self;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/components/bolt-ratio/src/ratio.scss
Expand Up @@ -35,8 +35,7 @@ bolt-ratio > * {
left: 0;
width: 100%;
min-width: 100%; // workaround for content w/ hard-coded height & width
height: 100%;
min-height: 100%; // workaround for content w/ hard-coded height & width
min-height: 100%;
}

:host {
Expand All @@ -48,5 +47,4 @@ bolt-ratio > * {
top: 0;
left: 0;
width: 100%;
height: 100%;
}

0 comments on commit c17a6b2

Please sign in to comment.