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

Docs: E2E tests for Source block update fix #22835

Merged
merged 30 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0a0cd6f
change the comparaison to update the source
chakAs3 May 25, 2023
8901ff1
downgrade typescript version on main project
chakAs3 May 26, 2023
067301e
Merge branch 'clean-migrate-nx' into next-rollback-tree
chakAs3 May 26, 2023
8018f24
7.1.0-alpha.24 changelog
shilman May 26, 2023
30c1c13
Update root, peer deps, version.ts/json to 7.1.0-alpha.24 [ci skip]
shilman May 26, 2023
539e812
v7.1.0-alpha.24
shilman May 26, 2023
e70caeb
Update git head to 7.1.0-alpha.24, update yarn.lock [ci skip]
shilman May 26, 2023
557edc1
merge next to buil/fix-chromatic-tests
chakAs3 May 26, 2023
bd56ed2
Merge branch 'build/fix-next-chromatic-tests' into chaks/fix-update-s…
chakAs3 May 26, 2023
2201fb8
remove unused loadash import
chakAs3 May 26, 2023
abace6f
downgrade typescript version on main project
chakAs3 May 26, 2023
38eb54f
Merge branch 'build/fix-next-chromatic-tests' of https://github.com/s…
chakAs3 May 26, 2023
e176ca2
Merge branch 'next' into chaks/fix-update-source-snippet
chakAs3 May 26, 2023
60b541f
fix null exception conditional decorator story
chakAs3 May 26, 2023
c104a0b
Merge branch 'build/fix-next-chromatic-tests' into chaks/fix-update-s…
chakAs3 May 26, 2023
c9ee17b
Merge branch 'next' into chaks/fix-update-source-snippet
chakAs3 May 29, 2023
3623501
add test check if value changes back to previous
chakAs3 May 30, 2023
f18031e
Merge branch 'next' into chaks/fix-update-source-snippet
chakAs3 May 30, 2023
6c83e2e
revert back typescript version
chakAs3 May 30, 2023
bcb9741
fix lockfile
chakAs3 May 30, 2023
30a91c1
Merge branch 'next' into chaks/add-e2e-test-to-addon-docs
chakAs3 May 30, 2023
edee82a
Merge remote-tracking branch 'origin/chaks/add-e2e-test-to-addon-docs…
shilman May 31, 2023
1bd982e
added lit to Skipped renderer not supporting dynamic
chakAs3 May 31, 2023
f6e27b5
remove deep test. always return new source
chakAs3 Jun 1, 2023
ec6cdf5
skip angular for test
chakAs3 Jun 2, 2023
b89f3c3
Merge branch 'next' into chaks/fix-update-source-snippet
chakAs3 Jun 2, 2023
a0cd9c5
skip angular for dynamic source test
chakAs3 Jun 2, 2023
d028cde
skip internal and ca for test
chakAs3 Jun 2, 2023
26f5d22
Merge pull request #22807 from storybookjs/chaks/fix-update-source-sn…
chakAs3 Jun 2, 2023
9be6013
Add note about restoring optimization in 8.0
shilman Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 37 additions & 2 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test.describe('addon-docs', () => {
test('should provide source snippet', async ({ page }) => {
// templateName is e.g. 'Vue-CLI (Default JS)'
test.skip(
/^(vue3|vue-cli|preact)/i.test(`${templateName}`),
/^(vue-cli|preact)/i.test(`${templateName}`),
`Skipping ${templateName}, which does not support dynamic source snippets`
);

Expand All @@ -111,7 +111,6 @@ test.describe('addon-docs', () => {

test('source snippet should not change in stories block', async ({ page }) => {
const skipped = [
'vue3',
'vue-cli',
'preact',
// SSv6 does not render stories in the correct order in our sandboxes
Expand Down Expand Up @@ -157,6 +156,42 @@ test.describe('addon-docs', () => {
await expect(storiesCode).toContainText('Basic');
});

test('source snippet should change back to previous value in stories block', async ({ page }) => {
test.skip(
/^(lit|vue-cli|preact|angular|internal\/ssv6|ca)/i.test(`${templateName}`),
`Skipping ${templateName}, which does not support dynamic source snippets`
);

const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/basic', 'docs');
const root = sbPage.previewRoot();
const toggles = root.locator('.docblock-code-toggle');

const toggle = await toggles.nth(0);
await toggle.click({ force: true });

const codes = root.locator('pre.prismjs');

const code = await codes.nth(0);
const text = await code.innerText();

await expect(text).toContain('Basic');

const labelControl = root.locator('textarea[name=label]');
labelControl.fill('Changed');
labelControl.blur();

// Check the Primary one has changed
await expect(code).toContainText('Changed');

// Change the value back
labelControl.fill('Basic');
labelControl.blur();

// Check the Primary one has changed back
await expect(code).toContainText('Basic');
});

test('should not run autoplay stories without parameter', async ({ page }) => {
const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/autoplay', 'docs');
Expand Down
19 changes: 9 additions & 10 deletions code/ui/blocks/src/blocks/SourceContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FC, Context, PropsWithChildren } from 'react';
import React, { createContext, useEffect, useState } from 'react';

import { dequal as deepEqual } from 'dequal';
import type { Channel } from '@storybook/channels';

import { SNIPPET_RENDERED } from '@storybook/docs-tools';
Expand Down Expand Up @@ -64,11 +63,14 @@ export const SourceContainer: FC<PropsWithChildren<{ channel: Channel }>> = ({
: idOrEvent;

const hash = args ? argsHash(args) : UNKNOWN_ARGS_HASH;

// optimization: if the source is the same, ignore the incoming event
if (sources[id] && sources[id][hash] && sources[id][hash].code === source) {
return;
}
// FIXME: In SB8.0 when we remove the Source block deprecations,
// we should restore this optimizationand make the Source block
// smarter about understanding when its args change.
//
// See https://github.com/storybookjs/storybook/pull/22807
//
// optimization: don't update if the source is the same
// if (deepEqual(currentSource, { code: source, format })) return;

setSources((current) => {
const newSources = {
Expand All @@ -79,10 +81,7 @@ export const SourceContainer: FC<PropsWithChildren<{ channel: Channel }>> = ({
},
};

if (!deepEqual(current, newSources)) {
return newSources;
}
return current;
return newSources;
});
};

Expand Down