Move usePluginApiClientContext & useProjectContext into hooks where applicable
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
@@ -18,7 +18,6 @@ import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import {
|
||||
mockApiClient,
|
||||
mockCalverProject,
|
||||
mockNextGitHubInfoSemver,
|
||||
mockReleaseBranch,
|
||||
@@ -29,11 +28,6 @@ import {
|
||||
import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
import { useCreateRc } from './hooks/useCreateRc';
|
||||
|
||||
jest.mock('../../contexts/PluginApiClientContext', () => ({
|
||||
usePluginApiClientContext: () => ({
|
||||
pluginApiClient: mockApiClient,
|
||||
}),
|
||||
}));
|
||||
jest.mock('../../contexts/ProjectContext', () => ({
|
||||
useProjectContext: jest.fn(() => ({
|
||||
project: mockCalverProject,
|
||||
|
||||
@@ -38,7 +38,6 @@ import { ResponseStepDialog } from '../../components/ResponseStepDialog/Response
|
||||
import { SEMVER_PARTS } from '../../constants/constants';
|
||||
import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
import { useCreateRc } from './hooks/useCreateRc';
|
||||
import { usePluginApiClientContext } from '../../contexts/PluginApiClientContext';
|
||||
import { useProjectContext } from '../../contexts/ProjectContext';
|
||||
import { useStyles } from '../../styles/styles';
|
||||
|
||||
@@ -67,7 +66,6 @@ export const CreateRc = ({
|
||||
releaseBranch,
|
||||
successCb,
|
||||
}: CreateRcProps) => {
|
||||
const { pluginApiClient } = usePluginApiClientContext();
|
||||
const { project } = useProjectContext();
|
||||
const classes = useStyles();
|
||||
|
||||
@@ -88,7 +86,6 @@ export const CreateRc = ({
|
||||
defaultBranch,
|
||||
latestRelease,
|
||||
nextGitHubInfo,
|
||||
pluginApiClient,
|
||||
project,
|
||||
successCb,
|
||||
});
|
||||
|
||||
@@ -26,6 +26,12 @@ import {
|
||||
} from '../../../test-helpers/test-helpers';
|
||||
import { useCreateRc } from './useCreateRc';
|
||||
|
||||
jest.mock('../../../contexts/PluginApiClientContext', () => ({
|
||||
usePluginApiClientContext: () => ({
|
||||
pluginApiClient: mockApiClient,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('useCreateRc', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
@@ -35,7 +41,6 @@ describe('useCreateRc', () => {
|
||||
defaultBranch: mockDefaultBranch,
|
||||
latestRelease: mockReleaseVersionCalver,
|
||||
nextGitHubInfo: mockNextGitHubInfoCalver,
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockCalverProject,
|
||||
}),
|
||||
);
|
||||
@@ -54,7 +59,6 @@ describe('useCreateRc', () => {
|
||||
defaultBranch: mockDefaultBranch,
|
||||
latestRelease: mockReleaseVersionCalver,
|
||||
nextGitHubInfo: mockNextGitHubInfoCalver,
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockCalverProject,
|
||||
successCb: jest.fn(),
|
||||
}),
|
||||
|
||||
@@ -20,19 +20,18 @@ import { useAsync, useAsyncFn } from 'react-use';
|
||||
import {
|
||||
GetLatestReleaseResult,
|
||||
GetRepositoryResult,
|
||||
IPluginApiClient,
|
||||
} from '../../../api/PluginApiClient';
|
||||
import { CardHook, ComponentConfigCreateRc } from '../../../types/types';
|
||||
import { getRcGitHubInfo } from '../../../helpers/getRcGitHubInfo';
|
||||
import { GitHubReleaseManagerError } from '../../../errors/GitHubReleaseManagerError';
|
||||
import { Project } from '../../../contexts/ProjectContext';
|
||||
import { useResponseSteps } from '../../../hooks/useResponseSteps';
|
||||
import { usePluginApiClientContext } from '../../../contexts/PluginApiClientContext';
|
||||
|
||||
interface CreateRC {
|
||||
defaultBranch: GetRepositoryResult['defaultBranch'];
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
nextGitHubInfo: ReturnType<typeof getRcGitHubInfo>;
|
||||
pluginApiClient: IPluginApiClient;
|
||||
project: Project;
|
||||
successCb?: ComponentConfigCreateRc['successCb'];
|
||||
}
|
||||
@@ -41,10 +40,11 @@ export function useCreateRc({
|
||||
defaultBranch,
|
||||
latestRelease,
|
||||
nextGitHubInfo,
|
||||
pluginApiClient,
|
||||
project,
|
||||
successCb,
|
||||
}: CreateRC): CardHook<void> {
|
||||
const { pluginApiClient } = usePluginApiClientContext();
|
||||
|
||||
if (nextGitHubInfo.error) {
|
||||
throw new GitHubReleaseManagerError(
|
||||
`Unexpected error: ${
|
||||
|
||||
@@ -94,7 +94,6 @@ export const PatchBody = ({
|
||||
const { progress, responseSteps, run, runInvoked } = usePatch({
|
||||
bumpedTag,
|
||||
latestRelease,
|
||||
pluginApiClient,
|
||||
project,
|
||||
tagParts,
|
||||
successCb,
|
||||
|
||||
@@ -27,6 +27,12 @@ import {
|
||||
} from '../../../test-helpers/test-helpers';
|
||||
import { usePatch } from './usePatch';
|
||||
|
||||
jest.mock('../../../contexts/PluginApiClientContext', () => ({
|
||||
usePluginApiClientContext: () => ({
|
||||
pluginApiClient: mockApiClient,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('patch', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
@@ -35,7 +41,6 @@ describe('patch', () => {
|
||||
usePatch({
|
||||
bumpedTag: mockBumpedTag,
|
||||
latestRelease: mockReleaseVersionCalver,
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockCalverProject,
|
||||
tagParts: mockTagParts,
|
||||
}),
|
||||
@@ -54,7 +59,6 @@ describe('patch', () => {
|
||||
usePatch({
|
||||
bumpedTag: mockBumpedTag,
|
||||
latestRelease: mockReleaseVersionCalver,
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockCalverProject,
|
||||
tagParts: mockTagParts,
|
||||
successCb: jest.fn(),
|
||||
|
||||
@@ -20,18 +20,17 @@ import { useAsync, useAsyncFn } from 'react-use';
|
||||
import {
|
||||
GetLatestReleaseResult,
|
||||
GetRecentCommitsResultSingle,
|
||||
IPluginApiClient,
|
||||
} from '../../../api/PluginApiClient';
|
||||
import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts';
|
||||
import { ComponentConfigPatch, CardHook } from '../../../types/types';
|
||||
import { Project } from '../../../contexts/ProjectContext';
|
||||
import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts';
|
||||
import { usePluginApiClientContext } from '../../../contexts/PluginApiClientContext';
|
||||
import { useResponseSteps } from '../../../hooks/useResponseSteps';
|
||||
|
||||
interface Patch {
|
||||
bumpedTag: string;
|
||||
latestRelease: NonNullable<GetLatestReleaseResult>;
|
||||
pluginApiClient: IPluginApiClient;
|
||||
project: Project;
|
||||
tagParts: NonNullable<CalverTagParts | SemverTagParts>;
|
||||
successCb?: ComponentConfigPatch['successCb'];
|
||||
@@ -41,11 +40,11 @@ interface Patch {
|
||||
export function usePatch({
|
||||
bumpedTag,
|
||||
latestRelease,
|
||||
pluginApiClient,
|
||||
project,
|
||||
tagParts,
|
||||
successCb,
|
||||
}: Patch): CardHook<GetRecentCommitsResultSingle> {
|
||||
const { pluginApiClient } = usePluginApiClientContext();
|
||||
const {
|
||||
responseSteps,
|
||||
addStepToResponseSteps,
|
||||
|
||||
@@ -17,23 +17,9 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import {
|
||||
mockApiClient,
|
||||
mockCalverProject,
|
||||
mockReleaseCandidateCalver,
|
||||
} from '../../test-helpers/test-helpers';
|
||||
import { mockReleaseCandidateCalver } from '../../test-helpers/test-helpers';
|
||||
import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
|
||||
jest.mock('../../contexts/PluginApiClientContext', () => ({
|
||||
usePluginApiClientContext: () => ({
|
||||
pluginApiClient: mockApiClient,
|
||||
}),
|
||||
}));
|
||||
jest.mock('../../contexts/ProjectContext', () => ({
|
||||
useProjectContext: () => ({
|
||||
project: mockCalverProject,
|
||||
}),
|
||||
}));
|
||||
jest.mock('./hooks/usePromoteRc', () => ({
|
||||
usePromoteRc: () => ({
|
||||
run: jest.fn(),
|
||||
|
||||
@@ -22,8 +22,6 @@ import { Differ } from '../../components/Differ';
|
||||
import { GetLatestReleaseResult } from '../../api/PluginApiClient';
|
||||
import { ResponseStepDialog } from '../../components/ResponseStepDialog/ResponseStepDialog';
|
||||
import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
import { usePluginApiClientContext } from '../../contexts/PluginApiClientContext';
|
||||
import { useProjectContext } from '../../contexts/ProjectContext';
|
||||
import { usePromoteRc } from './hooks/usePromoteRc';
|
||||
import { useStyles } from '../../styles/styles';
|
||||
|
||||
@@ -33,14 +31,10 @@ interface PromoteRcBodyProps {
|
||||
}
|
||||
|
||||
export const PromoteRcBody = ({ rcRelease, successCb }: PromoteRcBodyProps) => {
|
||||
const { pluginApiClient } = usePluginApiClientContext();
|
||||
const { project } = useProjectContext();
|
||||
const classes = useStyles();
|
||||
const releaseVersion = rcRelease.tagName.replace('rc-', 'version-');
|
||||
|
||||
const { progress, responseSteps, run, runInvoked } = usePromoteRc({
|
||||
pluginApiClient,
|
||||
project,
|
||||
rcRelease,
|
||||
releaseVersion,
|
||||
successCb,
|
||||
|
||||
@@ -19,19 +19,28 @@ import { waitFor } from '@testing-library/react';
|
||||
|
||||
import {
|
||||
mockApiClient,
|
||||
mockCalverProject,
|
||||
mockReleaseCandidateCalver,
|
||||
mockSemverProject,
|
||||
} from '../../../test-helpers/test-helpers';
|
||||
import { usePromoteRc } from './usePromoteRc';
|
||||
|
||||
jest.mock('../../../contexts/PluginApiClientContext', () => ({
|
||||
usePluginApiClientContext: () => ({
|
||||
pluginApiClient: mockApiClient,
|
||||
}),
|
||||
}));
|
||||
jest.mock('../../../contexts/ProjectContext', () => ({
|
||||
useProjectContext: () => ({
|
||||
project: mockCalverProject,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('usePromoteRc', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
it('should return the expected responseSteps and progress', async () => {
|
||||
const { result } = renderHook(() =>
|
||||
usePromoteRc({
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockSemverProject,
|
||||
rcRelease: mockReleaseCandidateCalver,
|
||||
releaseVersion: 'version-1.2.3',
|
||||
}),
|
||||
@@ -48,8 +57,6 @@ describe('usePromoteRc', () => {
|
||||
it('should return the expected responseSteps and progress (with successCb)', async () => {
|
||||
const { result } = renderHook(() =>
|
||||
usePromoteRc({
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockSemverProject,
|
||||
rcRelease: mockReleaseCandidateCalver,
|
||||
releaseVersion: 'version-1.2.3',
|
||||
successCb: jest.fn(),
|
||||
|
||||
@@ -17,29 +17,25 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useAsync, useAsyncFn } from 'react-use';
|
||||
|
||||
import {
|
||||
GetLatestReleaseResult,
|
||||
IPluginApiClient,
|
||||
} from '../../../api/PluginApiClient';
|
||||
import { GetLatestReleaseResult } from '../../../api/PluginApiClient';
|
||||
import { CardHook, ComponentConfigPromoteRc } from '../../../types/types';
|
||||
import { Project } from '../../../contexts/ProjectContext';
|
||||
import { useProjectContext } from '../../../contexts/ProjectContext';
|
||||
import { usePluginApiClientContext } from '../../../contexts/PluginApiClientContext';
|
||||
import { useResponseSteps } from '../../../hooks/useResponseSteps';
|
||||
|
||||
interface PromoteRc {
|
||||
pluginApiClient: IPluginApiClient;
|
||||
project: Project;
|
||||
rcRelease: NonNullable<GetLatestReleaseResult>;
|
||||
releaseVersion: string;
|
||||
successCb?: ComponentConfigPromoteRc['successCb'];
|
||||
}
|
||||
|
||||
export function usePromoteRc({
|
||||
pluginApiClient,
|
||||
project,
|
||||
rcRelease,
|
||||
releaseVersion,
|
||||
successCb,
|
||||
}: PromoteRc): CardHook<void> {
|
||||
const { pluginApiClient } = usePluginApiClientContext();
|
||||
const { project } = useProjectContext();
|
||||
const {
|
||||
responseSteps,
|
||||
addStepToResponseSteps,
|
||||
|
||||
Reference in New Issue
Block a user