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

UI: Keep failing stories in the sidebar, disregarding filters #30086

Merged
merged 2 commits into from
Dec 17, 2024
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
59 changes: 59 additions & 0 deletions code/core/src/manager-api/lib/stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { describe, expect, it } from 'vitest';

import type { API_PreparedStoryIndex, StoryIndexV2, StoryIndexV3 } from '@storybook/core/types';

import type { State } from '../root';
import { mockEntries } from '../tests/mockStoriesEntries';
import {
transformStoryIndexToStoriesHash,
transformStoryIndexV2toV3,
transformStoryIndexV3toV4,
transformStoryIndexV4toV5,
Expand Down Expand Up @@ -216,3 +218,60 @@ describe('transformStoryIndexV4toV5', () => {
`);
});
});

describe('transformStoryIndexToStoriesHash', () => {
it('does not apply filters to failing stories', () => {
// Arrange - set up an index with two stories, one of which has a failing status
const indexV5: API_PreparedStoryIndex = {
v: 5,
entries: {
'1': {
id: '1',
type: 'story',
title: 'Story 1',
name: 'Story 1',
importPath: './path/to/story-1.ts',
parameters: {},
tags: [],
},
'2': {
id: '2',
type: 'story',
title: 'Story 2',
name: 'Story 2',
importPath: './path/to/story-2.ts',
parameters: {},
tags: [],
},
},
};

const filters: State['filters'] = {
someFilter: () => false,
};

const status: State['status'] = {
'1': { someStatus: { status: 'error', title: 'broken', description: 'very bad' } },
'2': { someStatus: { status: 'success', title: 'perfect', description: 'nice' } },
};

const options = {
provider: {
getConfig: () => ({ sidebar: {} }),
} as any,
docsOptions: { docsMode: false },
filters,
status,
};

// Act - transform the index to hashes
const result = transformStoryIndexToStoriesHash(indexV5, options);

// Assert - the failing story is still present in the result, even though the filters remove all stories
expect(Object.keys(result)).toHaveLength(2);
expect(result['story-1']).toBeTruthy();
expect(result['1']).toBeTruthy();
Comment on lines +271 to +273
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Test is asserting both 'story-1' and '1' keys exist, but this seems incorrect - should only be checking for one ID format based on the transformation logic

expect(result['story-2']).toBeUndefined();
expect(result['2']).toBeUndefined();
});
});
8 changes: 7 additions & 1 deletion code/core/src/manager-api/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,17 @@ export const transformStoryIndexToStoriesHash = (
const entryValues = Object.values(index.entries).filter((entry: any) => {
let result = true;

// All stories with a failing status should always show up, regardless of the applied filters
const storyStatus = status[entry.id];
if (Object.values(storyStatus ?? {}).some(({ status: s }) => s === 'error')) {
return result;
}

Object.values(filters).forEach((filter: any) => {
if (result === false) {
return;
}
result = filter({ ...entry, status: status[entry.id] });
result = filter({ ...entry, status: storyStatus });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Passing storyStatus directly instead of spreading entry and adding status separately would be more efficient

});

return result;
Expand Down
Loading