Skip to content

Commit

Permalink
Migrate example FontSizePicker test to new setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Sep 19, 2022
1 parent 6052258 commit 0383efb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
47 changes: 47 additions & 0 deletions packages/components/src/font-size-picker/stories/e2e.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import FontSizePicker from '..';

export default {
title: 'Components/FontSizePicker',
component: FontSizePicker,
};

const FontSizePickerWithState = ( { initialValue, ...props } ) => {
const [ fontSize, setFontSize ] = useState( initialValue );
return (
<FontSizePicker
{ ...props }
value={ fontSize }
onChange={ setFontSize }
/>
);
};

export const Default = FontSizePickerWithState.bind( {} );
Default.args = {
fontSizes: [
{
name: 'Small',
slug: 'small',
size: 12,
},
{
name: 'Normal',
slug: 'normal',
size: 16,
},
{
name: 'Big',
slug: 'big',
size: 26,
},
],
initialValue: 16,
};
35 changes: 4 additions & 31 deletions test/storybook-playwright/specs/font-size-picker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,15 @@ test.describe.parallel( 'FontSizePicker', () => {
await gotoStoryId( page, 'components-fontsizepicker--default' );
} );

test( 'Renders with "Normal" size by default', async ( { page } ) => {
// This isn't a meaningful test, just some example code to demonstrate a way to
// wait until a certain element has finished animating.
// We can remove it once we have real tests.
test( 'with value', async ( { page } ) => {
const button = await page.locator( 'button[aria-label="Normal"]' );

await waitUntilButtonHighlightStable( page );

expect( button ).toHaveAttribute( 'aria-checked', 'true' );
expect( await page.screenshot() ).toMatchSnapshot();
} );

test( 'Can change size to "Small"', async ( { page } ) => {
const button = await page.locator( 'button[aria-label="Small"]' );

await button.click();
await waitUntilButtonHighlightStable( page );

expect( button ).toHaveAttribute( 'aria-checked', 'true' );
expect( await page.screenshot() ).toMatchSnapshot();
} );

test( 'Can change size to "Big"', async ( { page } ) => {
const button = await page.locator( 'button[aria-label="Big"]' );

await button.click();
await waitUntilButtonHighlightStable( page );

expect( button ).toHaveAttribute( 'aria-checked', 'true' );
expect( await page.screenshot() ).toMatchSnapshot();
} );

test( 'Can change size back to "Normal"', async ( { page } ) => {
const button = await page.locator( 'button[aria-label="Normal"]' );

await button.click();
await waitUntilButtonHighlightStable( page );

expect( button ).toHaveAttribute( 'aria-checked', 'true' );
expect( await page.screenshot() ).toMatchSnapshot();
} );
} );

0 comments on commit 0383efb

Please sign in to comment.