Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Storybook 7 viewport menu not working #22829

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion code/addons/viewport/src/Tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ const getStyles = (
styles: Styles,
isRotated: boolean
): ViewportStyles | undefined => {
if (!styles || !prevStyles) {
if (styles === null) {
return undefined;
}

const result = typeof styles === 'function' ? styles(prevStyles) : styles;
return isRotated ? flip(result) : result;
};
Expand Down
2 changes: 1 addition & 1 deletion code/addons/viewport/src/models/Viewport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Styles = ViewportStyles | ((s: ViewportStyles) => ViewportStyles) | null;
export type Styles = ViewportStyles | ((s: ViewportStyles | undefined) => ViewportStyles) | null;

export interface Viewport {
name: string;
Expand Down
20 changes: 20 additions & 0 deletions code/e2e-tests/addon-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,24 @@ test.describe('addon-viewport', () => {
// Check that Button story is still displayed
await expect(sbPage.previewRoot()).toContainText('Button');
});

test('iframe width should be changed when a mobile viewport is selected', async ({ page }) => {
const sbPage = new SbPage(page);

// Click on viewport button and select small mobile
await sbPage.navigateToStory('example/button', 'primary');

// Measure the original dimensions of previewRoot
const originalDimensions = await sbPage.previewRoot().boundingBox();
await expect(originalDimensions?.width).toBeDefined();

await sbPage.selectToolbar('[title="Change the size of the preview"]', '#list-item-mobile1');

// Measure the adjusted dimensions of previewRoot after clicking the mobile item.
const adjustedDimensions = await sbPage.previewRoot().boundingBox();
await expect(adjustedDimensions?.width).toBeDefined();

// Compare the two widths
await expect(adjustedDimensions?.width).not.toBe(originalDimensions?.width);
});
});