Skip to content

Commit

Permalink
Merge branch 'next' into jeppe/composed-play-default-canvaselement
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Mar 8, 2024
2 parents 93b7ed4 + d135d12 commit 0dbe3e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
25 changes: 14 additions & 11 deletions code/lib/manager-api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface SubAPI {
* @param {string} id - The ID of the composed ref.
* @param {API_ComposedRefUpdate} ref - The update object for the composed ref.
*/
updateRef: (id: string, ref: API_ComposedRefUpdate) => void;
updateRef: (id: string, ref: API_ComposedRefUpdate) => Promise<void>;
/**
* Gets all composed refs.
* @returns {API_Refs} - The composed refs object.
Expand All @@ -60,7 +60,7 @@ export interface SubAPI {
* @param {string} id - The ID of the composed ref.
* @param {string} url - The new URL for the composed ref.
*/
changeRefVersion: (id: string, url: string) => void;
changeRefVersion: (id: string, url: string) => Promise<void>;
/**
* Changes the state of a composed ref by its ID and previewInitialized flag.
* @param {string} id - The ID of the composed ref.
Expand Down Expand Up @@ -168,12 +168,12 @@ export const init: ModuleFn<SubAPI, SubState> = (

return Object.values(refs).find(({ url }: any) => url.match(source));
},
changeRefVersion: (id, url) => {
changeRefVersion: async (id, url) => {
const { versions, title } = api.getRefs()[id];
const ref: API_SetRefData = { id, url, versions, title, index: {}, expanded: true };

api.setRef(id, { ...ref, type: 'unknown' }, false);
api.checkRef(ref);
await api.setRef(id, { ...ref, type: 'unknown' }, false);
await api.checkRef(ref);
},
changeRefState: (id, previewInitialized) => {
const { [id]: ref, ...updated } = api.getRefs();
Expand Down Expand Up @@ -276,7 +276,7 @@ export const init: ModuleFn<SubAPI, SubState> = (
return refs;
},

setRef: (id, { storyIndex, setStoriesData, ...rest }, ready = false) => {
setRef: async (id, { storyIndex, setStoriesData, ...rest }, ready = false) => {
if (singleStory) {
return;
}
Expand Down Expand Up @@ -307,10 +307,10 @@ export const init: ModuleFn<SubAPI, SubState> = (
index = addRefIds(index, ref);
}

api.updateRef(id, { ...ref, ...rest, index, internal_index });
await api.updateRef(id, { ...ref, ...rest, index, internal_index });
},

updateRef: (id, data) => {
updateRef: async (id, data) => {
const { [id]: ref, ...updated } = api.getRefs();

updated[id] = { ...ref, ...data };
Expand All @@ -320,7 +320,7 @@ export const init: ModuleFn<SubAPI, SubState> = (
return obj;
}, {});

store.setState({
await store.setState({
refs: ordered,
});
},
Expand All @@ -331,8 +331,11 @@ export const init: ModuleFn<SubAPI, SubState> = (
const initialState: SubState['refs'] = refs;

if (runCheck) {
Object.entries(refs).forEach(([id, ref]) => {
api.checkRef({ ...ref!, stories: {} } as API_SetRefData);
new Promise(async (resolve) => {
for (const ref of Object.values(refs)) {
await api.checkRef({ ...ref!, stories: {} } as API_SetRefData);
}
resolve(undefined);
});
}

Expand Down
6 changes: 6 additions & 0 deletions code/lib/manager-api/src/tests/refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ describe('Refs API', () => {
// given
initRefs({ provider, store } as any);

// the `runCheck` is async, so we need to wait for it to finish
await vi.waitFor(() => fetchMock.mock.calls.length > 0);

expect(fetchMock.mock.calls).toMatchInlineSnapshot(`
[
[
Expand Down Expand Up @@ -207,6 +210,9 @@ describe('Refs API', () => {
};
initRefs({ provider, store } as any);

// the `runCheck` is async, so we need to wait for it to finish
await vi.waitFor(() => fetchMock.mock.calls.length > 0);

expect(fetchMock.mock.calls).toMatchInlineSnapshot(`
[
[
Expand Down
1 change: 1 addition & 0 deletions code/renderers/preact/template/cli/Header.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fn } from '@storybook/test';
import { Header } from './Header';

export default {
Expand Down

0 comments on commit 0dbe3e4

Please sign in to comment.