mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
FIX test
This commit is contained in:
parent
ad8a245c85
commit
d3dbcc4629
@ -66,11 +66,14 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('sets versions in the init function', async () => {
|
it('sets versions in the init function', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { state: initialState, init, api } = initVersions({ store });
|
const { state: initialState, init } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
store.setState.mockReset();
|
store.setState.mockReset();
|
||||||
|
|
||||||
await init({ api: { addNotification: jest.fn(), ...api } });
|
await init();
|
||||||
|
|
||||||
expect(store.setState).toHaveBeenCalledWith({
|
expect(store.setState).toHaveBeenCalledWith({
|
||||||
versions: {
|
versions: {
|
||||||
@ -84,58 +87,74 @@ describe('versions API', () => {
|
|||||||
describe('notifications', () => {
|
describe('notifications', () => {
|
||||||
it('sets an update notification right away in the init function', async () => {
|
it('sets an update notification right away in the init function', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { init, api, state: initialState } = initVersions({ store });
|
const addNotification = jest.fn();
|
||||||
|
const { init, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
|
|
||||||
const addNotification = jest.fn();
|
await init();
|
||||||
await init({ api: { addNotification, ...api } });
|
|
||||||
expect(addNotification).toHaveBeenCalled();
|
expect(addNotification).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set an update notification if it has been dismissed', async () => {
|
it('does not set an update notification if it has been dismissed', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
store.setState({ dismissedVersionNotification: '5.2.3' });
|
store.setState({ dismissedVersionNotification: '5.2.3' });
|
||||||
const { init, api, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
|
|
||||||
const addNotification = jest.fn();
|
const addNotification = jest.fn();
|
||||||
await init({ api: { addNotification, ...api } });
|
await init();
|
||||||
expect(addNotification).not.toHaveBeenCalled();
|
expect(addNotification).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set an update notification if the latest version is a patch', async () => {
|
it('does not set an update notification if the latest version is a patch', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { init, api, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
versions: { ...initialState.versions, current: { version: '5.2.1' } },
|
versions: { ...initialState.versions, current: { version: '5.2.1' } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const addNotification = jest.fn();
|
const addNotification = jest.fn();
|
||||||
await init({ api: { addNotification, ...api } });
|
await init();
|
||||||
expect(addNotification).not.toHaveBeenCalled();
|
expect(addNotification).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set an update notification in production mode', async () => {
|
it('does not set an update notification in production mode', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { init, api, state: initialState } = initVersions({ store, mode: 'production' });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
|
|
||||||
const addNotification = jest.fn();
|
const addNotification = jest.fn();
|
||||||
await init({ api: { addNotification, ...api } });
|
await init();
|
||||||
expect(addNotification).not.toHaveBeenCalled();
|
expect(addNotification).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('persists a dismissed notification', async () => {
|
it('persists a dismissed notification', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { init, api, state: initialState } = initVersions({ store });
|
|
||||||
store.setState(initialState);
|
|
||||||
|
|
||||||
let notification;
|
let notification;
|
||||||
const addNotification = jest.fn().mockImplementation(n => {
|
const addNotification = jest.fn().mockImplementation(n => {
|
||||||
notification = n;
|
notification = n;
|
||||||
});
|
});
|
||||||
await init({ api: { addNotification, ...api } });
|
|
||||||
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification },
|
||||||
|
});
|
||||||
|
store.setState(initialState);
|
||||||
|
|
||||||
|
await init();
|
||||||
|
|
||||||
notification.onClear();
|
notification.onClear();
|
||||||
expect(store.setState).toHaveBeenCalledWith(
|
expect(store.setState).toHaveBeenCalledWith(
|
||||||
@ -147,10 +166,13 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('getCurrentVersion works', async () => {
|
it('getCurrentVersion works', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
expect(api.getCurrentVersion()).toEqual({
|
expect(api.getCurrentVersion()).toEqual({
|
||||||
version: '3.0.0',
|
version: '3.0.0',
|
||||||
@ -159,10 +181,13 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('getLatestVersion works', async () => {
|
it('getLatestVersion works', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState(initialState);
|
store.setState(initialState);
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
expect(api.getLatestVersion()).toMatchObject({
|
expect(api.getLatestVersion()).toMatchObject({
|
||||||
version: '5.2.3',
|
version: '5.2.3',
|
||||||
@ -172,7 +197,10 @@ describe('versions API', () => {
|
|||||||
describe('versionUpdateAvailable', () => {
|
describe('versionUpdateAvailable', () => {
|
||||||
it('matching version', async () => {
|
it('matching version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
versions: {
|
versions: {
|
||||||
@ -182,14 +210,17 @@ describe('versions API', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
expect(api.versionUpdateAvailable()).toEqual(false);
|
expect(api.versionUpdateAvailable()).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('new patch version', async () => {
|
it('new patch version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
versions: {
|
versions: {
|
||||||
@ -199,16 +230,19 @@ describe('versions API', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
expect(api.versionUpdateAvailable()).toEqual(false);
|
expect(api.versionUpdateAvailable()).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('new minor version', async () => {
|
it('new minor version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
@ -224,9 +258,12 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('new major version', async () => {
|
it('new major version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
@ -242,9 +279,12 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('new prerelease version', async () => {
|
it('new prerelease version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
@ -260,9 +300,12 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('from older prerelease version', async () => {
|
it('from older prerelease version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
@ -278,9 +321,12 @@ describe('versions API', () => {
|
|||||||
|
|
||||||
it('from newer prerelease version', async () => {
|
it('from newer prerelease version', async () => {
|
||||||
const store = createMockStore();
|
const store = createMockStore();
|
||||||
const { api, init, state: initialState } = initVersions({ store });
|
const { init, api, state: initialState } = initVersions({
|
||||||
|
store,
|
||||||
|
fullAPI: { addNotification: jest.fn() },
|
||||||
|
});
|
||||||
|
|
||||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
await init();
|
||||||
|
|
||||||
store.setState({
|
store.setState({
|
||||||
...initialState,
|
...initialState,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user