mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* Fix updating organization name not updating configuration subtitle * PR feedback: Remove unnecessary square brackets * Refactor code to update redux state in a safer way, add org action test * Refactor updateConfigurationSubtitle test, remove jest.mock usage * Consolidate dependency type
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { updateOrganization } from './actions';
|
|
import { updateConfigurationSubtitle } from 'app/core/actions';
|
|
import { thunkTester } from 'test/core/thunk/thunkTester';
|
|
|
|
const setup = () => {
|
|
const initialState = {
|
|
organization: {
|
|
organization: {
|
|
id: 1,
|
|
name: 'New Org Name',
|
|
},
|
|
},
|
|
};
|
|
|
|
return {
|
|
initialState,
|
|
};
|
|
};
|
|
|
|
describe('updateOrganization', () => {
|
|
describe('when updateOrganization thunk is dispatched', () => {
|
|
const getMock = jest.fn().mockResolvedValue({ id: 1, name: 'New Org Name' });
|
|
const putMock = jest.fn().mockResolvedValue({ id: 1, name: 'New Org Name' });
|
|
const backendSrvMock: any = {
|
|
get: getMock,
|
|
put: putMock,
|
|
};
|
|
|
|
it('then it should dispatch updateConfigurationSubtitle', async () => {
|
|
const { initialState } = setup();
|
|
|
|
const dispatchedActions = await thunkTester(initialState)
|
|
.givenThunk(updateOrganization)
|
|
.whenThunkIsDispatched({ getBackendSrv: () => backendSrvMock });
|
|
|
|
expect(dispatchedActions[0].type).toEqual(updateConfigurationSubtitle.type);
|
|
expect(dispatchedActions[0].payload).toEqual(initialState.organization.organization.name);
|
|
});
|
|
});
|
|
});
|