-
Notifications
You must be signed in to change notification settings - Fork 373
test(desktop): expand Storybook smoke theme coverage #4042
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
Open
Yx01-me
wants to merge
2
commits into
apache:main
Choose a base branch
from
Yx01-me:feat/story_book_palette_scheme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−13
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,122 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import test from 'node:test'; | ||
| import { catalogJobs, storyUrl } from './storybook-visual-smoke.mjs'; | ||
|
|
||
| const REFERENCE_STORY_ID = 'product-shell-official-appshell--native-conversation'; | ||
| const THEME_PALETTES = [ | ||
| 'default', | ||
| ...Array.from({ length: 10 }, (_, index) => `test-palette-${index + 1}`), | ||
| ]; | ||
|
|
||
| function storyIndex(...storyIds) { | ||
| return { | ||
| entries: Object.fromEntries( | ||
| storyIds.map((storyId) => [storyId, { id: storyId, type: 'story' }]), | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| test('ordinary catalog stories render the default palette in both colour schemes', () => { | ||
| assert.deepEqual( | ||
| catalogJobs(storyIndex('product-settings--memory'), { themePalettes: THEME_PALETTES }), | ||
| [ | ||
| { | ||
| storyId: 'product-settings--memory', | ||
| colorScheme: 'light', | ||
| palette: 'default', | ||
| }, | ||
| { | ||
| storyId: 'product-settings--memory', | ||
| colorScheme: 'dark', | ||
| palette: 'default', | ||
| }, | ||
| ], | ||
| ); | ||
| }); | ||
|
|
||
| test('the reference story renders every palette in both colour schemes', () => { | ||
| const jobs = catalogJobs(storyIndex(REFERENCE_STORY_ID), { | ||
| themePalettes: THEME_PALETTES, | ||
| }); | ||
|
|
||
| assert.equal(jobs.length, 22); | ||
| assert.equal(new Set(jobs.map((job) => `${job.colorScheme}/${job.palette}`)).size, 22); | ||
| assert.deepEqual(jobs.slice(0, 4), [ | ||
| { storyId: REFERENCE_STORY_ID, colorScheme: 'light', palette: 'default' }, | ||
| { storyId: REFERENCE_STORY_ID, colorScheme: 'dark', palette: 'default' }, | ||
| { | ||
| storyId: REFERENCE_STORY_ID, | ||
| colorScheme: 'light', | ||
| palette: 'test-palette-1', | ||
| }, | ||
| { | ||
| storyId: REFERENCE_STORY_ID, | ||
| colorScheme: 'dark', | ||
| palette: 'test-palette-1', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| test('a mixed catalog adds only twenty renders for full palette coverage', () => { | ||
| const storyIds = ['product-settings--memory', REFERENCE_STORY_ID, 'design-system--button']; | ||
| const jobs = catalogJobs(storyIndex(...storyIds), { themePalettes: THEME_PALETTES }); | ||
|
|
||
| assert.equal(jobs.length, 2 * storyIds.length + 20); | ||
| assert.deepEqual(new Set(jobs.map((job) => job.storyId)), new Set(storyIds)); | ||
| }); | ||
|
|
||
| test('duplicate palette ids do not duplicate render jobs', () => { | ||
| const jobs = catalogJobs(storyIndex(REFERENCE_STORY_ID), { | ||
| themePalettes: ['default', 'onedark', 'default', 'onedark'], | ||
| }); | ||
|
|
||
| assert.equal(jobs.length, 4); | ||
| }); | ||
|
|
||
| test('catalog jobs require a non-empty palette inventory containing default', () => { | ||
| assert.throws( | ||
| () => catalogJobs(storyIndex('product-settings--memory'), { themePalettes: [] }), | ||
| /at least one theme palette/, | ||
| ); | ||
| assert.throws( | ||
| () => | ||
| catalogJobs(storyIndex('product-settings--memory'), { | ||
| themePalettes: ['onedark'], | ||
| }), | ||
| /must include default/, | ||
| ); | ||
| }); | ||
|
|
||
| test('story URLs encode the selected colour scheme and palette', () => { | ||
| const url = new URL( | ||
| storyUrl('http://127.0.0.1:6006', { | ||
| storyId: REFERENCE_STORY_ID, | ||
| colorScheme: 'dark', | ||
| palette: 'tokyo-night', | ||
| }), | ||
| ); | ||
|
|
||
| assert.equal(url.pathname, '/iframe.html'); | ||
| assert.equal(url.searchParams.get('id'), REFERENCE_STORY_ID); | ||
| assert.equal(url.searchParams.get('viewMode'), 'story'); | ||
| assert.equal(url.searchParams.get('globals'), 'colorScheme:dark;palette:tokyo-night'); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for expanding theme coverage without multiplying every story by every palette. [P2] This import adds an undeclared build prerequisite to the smoke entrypoint:
@maka/core/settingsresolves todist/settings.js, butnpm --workspace @maka/desktop run smoke:storybookdoes not build@maka/corefirst. In a clean worktree, building Storybook and then running the smoke command fails withERR_MODULE_NOT_FOUND; CI hides this because the root build happens earlier. Please make the smoke command establish that prerequisite, or consume the shared palette authority through a path that does not depend on pre-existing Core build output.简体中文
谢谢在没有让每个 story 都乘上全部 palette 的前提下扩展主题覆盖。[P2] 这个 import 给 smoke 入口增加了一个未声明的构建前置条件:
@maka/core/settings会解析到dist/settings.js,但npm --workspace @maka/desktop run smoke:storybook不会先构建@maka/core。在干净 worktree 中,先构建 Storybook 再运行 smoke 会得到ERR_MODULE_NOT_FOUND;CI 因为更早执行了根目录 build,恰好掩盖了这个问题。请让 smoke 命令显式满足该前置条件,或者从不依赖 Core 预构建产物的路径读取共享 palette authority。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll solve it soon