Skip to content

Commit

Permalink
feat(e2e): change Responsive to custom iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
kiesha-telus committed Feb 23, 2021
1 parent ce22db2 commit 54ad650
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions e2e/visual/components/CartesianResponsiveImage.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
/* eslint-disable react/no-children-prop */
import React from 'react'

import { Cartesian, Responsive } from '@compositor/kit'
import { renderToString } from 'react-dom/server'
import { Cartesian } from '@compositor/kit'

import ResponsiveImage from '../../../packages/ResponsiveImage'

const ResponsiveImageContainer = props => (
<Responsive
viewports={[
{ width: 320, height: 568 },
{ width: 640, height: 360 },
{ width: 768, height: 1024 },
{ width: 1024, height: 543 },
{ width: 1440, height: 880 },
]}
>
const viewports = [
{ width: 320, height: 568 },
{ width: 640, height: 360 },
{ width: 768, height: 1024 },
{ width: 1024, height: 543 },
{ width: 1440, height: 880 },
]

const ResponsiveImageContainer = props => {
// "Responsive" component from "@compositor/kit" does not take in a title attribute for
// iframe, failing the accessibility scan. iframe used to test different window sizes
const html = innerHtml => `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Document</title>
</head>
<body>
${innerHtml}
</body>
</html>
`

const CartesianResponsiveImage = renderToString(
<Cartesian
{...props}
component={ResponsiveImage}
Expand All @@ -25,7 +42,23 @@ const ResponsiveImageContainer = props => (
fallbackSrc="https://tds.telus.com/components/responsive-image/mountains_desktop.jpg"
alt="mountains background"
/>
</Responsive>
)
)

return (
<>
{viewports.map((viewport, i) => (
<iframe
key={JSON.stringify(viewport[i])}
title={`test-width: ${viewport.width}`}
style={{
width: viewport.width,
height: viewport.height,
}}
srcDoc={html(CartesianResponsiveImage)}
/>
))}
</>
)
}

export default { name: 'ResponsiveImage', Component: ResponsiveImageContainer }

0 comments on commit 54ad650

Please sign in to comment.