-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(documentation): adds visual regression tests for the text input (#…
- Loading branch information
Showing
4 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/documentation/cypress/snapshots/components/input.snapshot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const BASEURL = '/iframe.html?id=snapshots--input'; | ||
const types = [ | ||
'text', | ||
'number', | ||
'email', | ||
'tel', | ||
'url', | ||
'password', | ||
'date', | ||
'datetime-local', | ||
'month', | ||
'week', | ||
'time', | ||
'color', | ||
]; | ||
|
||
describe('Input', () => { | ||
describe('types', () => { | ||
types.forEach(type => { | ||
it(type, () => { | ||
cy.visit(`${BASEURL}${type}`); | ||
cy.percySnapshot(`Inputs-${type}`, { widths: [320, 1024] }); | ||
}); | ||
}); | ||
}); | ||
}); |
116 changes: 116 additions & 0 deletions
116
packages/documentation/src/stories/components/input/input.snapshot.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import type { Args, StoryContext, StoryObj } from '@storybook/web-components'; | ||
import meta from './input.stories'; | ||
import { html } from 'lit'; | ||
import { getCombinations, COMBINATIONS } from '../../../utils/inputComponentsGetCombinations'; | ||
|
||
export default { | ||
...meta, | ||
title: 'Snapshots', | ||
render: renderInputSnapshot, | ||
}; | ||
|
||
function renderInputSnapshot(_args: Args, context: StoryContext) { | ||
const combinations = [ | ||
...COMBINATIONS, | ||
{ | ||
label: `Label - no Placeholder`, | ||
placeholder: null, | ||
}, | ||
{ | ||
label: `Label - with Value`, | ||
value: 'Lorem Ipsum', | ||
}, | ||
]; | ||
return html` | ||
<div class="d-flex flex-wrap align-items-start gap-regular"> | ||
${['bg-white', 'bg-dark'].map( | ||
bg => html` | ||
<div class="${bg} d-flex gap-3 flex-column p-3"> | ||
<h3>Sizes</h3> | ||
${getCombinations('size', context.argTypes.size.options, combinations) | ||
.filter( | ||
(args: Args) => | ||
!args.value || | ||
(args.value && | ||
(context.args.type === 'text' || context.args.type === 'password')), | ||
) | ||
.map( | ||
(args: Args) => | ||
html` | ||
<div> | ||
${args.title !== undefined && args.title | ||
? html` | ||
<h4> | ||
${Object.entries(context.argTypes.size.control.labels) | ||
.filter(([key, value]) => key === args.size) | ||
.map(s => s[1])} | ||
</h4> | ||
` | ||
: ''} | ||
<div>${meta.render?.({ ...context.args, ...args }, context)}</div> | ||
</div> | ||
`, | ||
)} | ||
<h3>Floating Label</h3> | ||
${getCombinations('floatingLabel', [true], combinations) | ||
.filter( | ||
(args: Args) => | ||
!args.value || | ||
(args.value && | ||
(context.args.type === 'text' || context.args.type === 'password')), | ||
) | ||
.map( | ||
(args: Args) => | ||
html` | ||
<div>${meta.render?.({ ...context.args, ...args }, context)}</div> | ||
`, | ||
)} | ||
</div> | ||
`, | ||
)} | ||
</div> | ||
`; | ||
} | ||
|
||
type Story = StoryObj; | ||
|
||
export const Inputtext: Story = { | ||
args: { | ||
type: 'text', | ||
}, | ||
}; | ||
export const Inputpassword: Story = { | ||
args: { | ||
type: 'password', | ||
}, | ||
}; | ||
export const Inputdate: Story = { | ||
args: { | ||
type: 'date', | ||
}, | ||
}; | ||
export const Inputdatetimelocal: Story = { | ||
args: { | ||
type: 'datetime-local', | ||
}, | ||
}; | ||
export const Inputmonth: Story = { | ||
args: { | ||
type: 'month', | ||
}, | ||
}; | ||
export const Inputweek: Story = { | ||
args: { | ||
type: 'week', | ||
}, | ||
}; | ||
export const Inputtime: Story = { | ||
args: { | ||
type: 'time', | ||
}, | ||
}; | ||
export const Inputcolor: Story = { | ||
args: { | ||
type: 'color', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/documentation/src/utils/inputComponentsGetCombinations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const SHORT_HINT = | ||
'Hintus ipsum dolor sit amet consectetur adipisicing elit. Vero mollitia magnam quo quam saepe. Aliquam tempore non deleniti culpa reprehenderit.'; | ||
const LONG_HINT = | ||
'Hintus ipsum dolor sit amet consectetur adipisicing elit. Voluptatem maxime eius aut quae ducimus dignissimos pariatur suscipit distinctio, accusamus laudantium, sint quibusdam nisi optio? Ut quae obcaecati, harum ullam quos beatae, ipsam enim, placeat eligendi dolores excepturi. Quia quod eligendi ab voluptas modi id distinctio iure vel possimus deserunt, amet, dolores laboriosam quas qui aut laborum? Et numquam esse laboriosam totam quod sapiente recusandae consectetur optio, quaerat quia.'; | ||
const SHORT_LABEL = 'Label'; | ||
const LONG_TEXT = | ||
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem maxime eius aut quae ducimus dignissimos pariatur suscipit distinctio, accusamus laudantium, sint quibusdam nisi optio? Ut quae obcaecati, harum ullam quos beatae, ipsam enim, placeat eligendi dolores excepturi'; | ||
|
||
export const COMBINATIONS = [ | ||
{ | ||
title: true, // This property is true when a heading should be rendered above the story | ||
label: `${SHORT_LABEL} - no Hint`, | ||
hint: null, | ||
}, | ||
{ | ||
label: `${SHORT_LABEL} - short Hint`, | ||
hint: SHORT_HINT, | ||
}, | ||
{ | ||
label: `${SHORT_LABEL} - long - ${LONG_TEXT}`, | ||
hint: LONG_HINT, | ||
}, | ||
{ | ||
label: `${SHORT_LABEL} - Disabled`, | ||
disabled: true, | ||
}, | ||
{ | ||
label: `${SHORT_LABEL} - Valid`, | ||
validation: 'is-valid', | ||
}, | ||
{ | ||
label: `${SHORT_LABEL} - Invalid`, | ||
validation: 'is-invalid', | ||
}, | ||
]; | ||
|
||
export function getCombinations( | ||
argumentName: string, | ||
argumentValues: Array<unknown>, | ||
combinations: Array<{ label: string; [propName: string]: any }>, | ||
) { | ||
let result: Array<Object> = []; | ||
for (const argumentValue of argumentValues) { | ||
result = [ | ||
...result, | ||
...combinations.map(c => ({ | ||
...c, | ||
[argumentName]: argumentValue, | ||
})), | ||
]; | ||
} | ||
return result; | ||
} |