Skip to content

Commit

Permalink
test: ci/cd 테스트 실패 케이스 개선 (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 authored Nov 28, 2024
1 parent a9d8e16 commit 6e3eba3
Showing 1 changed file with 79 additions and 39 deletions.
118 changes: 79 additions & 39 deletions packages/react/src/hooks/useStep/useStep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,99 @@ describe('useStep', () => {
it('다음 단계로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => {
const { result } = renderHook(() => useStep({ maxStep: 2 }));

// nextStep
await waitFor(() => result.current.goToNextStep());

expect(result.current.currentStep).toBe(1);
expect(result.current.hasNextStep).toBe(true);
await waitFor(() => {
expect(result.current.currentStep).toBe(1);
expect(result.current.hasNextStep).toBe(true);
});

await waitFor(() => result.current.goToNextStep(goToNextStepActionMockFn));
// nextStep with Function
await waitFor(() => {
result.current.goToNextStep(goToNextStepActionMockFn);
});

expect(result.current.currentStep).toBe(2);
expect(result.current.hasNextStep).toBe(false);
expect(goToNextStepActionMockFn).toBeCalledTimes(1);
await waitFor(() => {
expect(result.current.currentStep).toBe(2);
expect(result.current.hasNextStep).toBe(false);
expect(goToNextStepActionMockFn).toBeCalledTimes(1);
});

await waitFor(() => result.current.goToNextStep());
// nextStep
await waitFor(() => {
result.current.goToNextStep();
});

expect(result.current.currentStep).toBe(2);
expect(result.current.hasNextStep).toBe(false);
await waitFor(() => {
expect(result.current.currentStep).toBe(2);
expect(result.current.hasNextStep).toBe(false);
});
});

it('이전 단계로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => {
const { result } = renderHook(() =>
useStep({ maxStep: 3, initialStep: 2 })
);

// prevStep
await waitFor(() => result.current.goToPrevStep());
await waitFor(() => {
expect(result.current.currentStep).toBe(1);
expect(result.current.hasPrevStep).toBe(true);
});

expect(result.current.currentStep).toBe(1);
expect(result.current.hasPrevStep).toBe(true);

// prevStep with Function
await waitFor(() => result.current.goToPrevStep(goToPrevStepActionMockFn));
await waitFor(() => {
expect(result.current.currentStep).toBe(0);
expect(result.current.hasPrevStep).toBe(false);
expect(goToPrevStepActionMockFn).toBeCalledTimes(1);
});

expect(result.current.currentStep).toBe(0);
expect(result.current.hasPrevStep).toBe(false);
expect(goToPrevStepActionMockFn).toBeCalledTimes(1);

// prevStep
await waitFor(() => result.current.goToPrevStep());

expect(result.current.currentStep).toBe(0);
expect(result.current.hasPrevStep).toBe(false);
await waitFor(() => {
expect(result.current.currentStep).toBe(0);
expect(result.current.hasPrevStep).toBe(false);
});
});

it('infinite 옵션이 true인 경우 무한 루프를 처리해야 합니다.', async () => {
const { result } = renderHook(() =>
useStep({ maxStep: 3, infinite: true })
);

// prevStep
await waitFor(() => result.current.goToPrevStep());
await waitFor(() => {
expect(result.current.currentStep).toBe(3);
});

expect(result.current.currentStep).toBe(3);

// prevStep
await waitFor(() => result.current.goToPrevStep());
await waitFor(() => {
expect(result.current.currentStep).toBe(2);
});

expect(result.current.currentStep).toBe(2);

// prevStep
await waitFor(() => result.current.goToPrevStep());
await waitFor(() => {
expect(result.current.currentStep).toBe(1);
});

expect(result.current.currentStep).toBe(1);

// prevStep
await waitFor(() => result.current.goToPrevStep());

expect(result.current.currentStep).toBe(0);
await waitFor(() => {
expect(result.current.currentStep).toBe(0);
});

// prevStep
await waitFor(() => result.current.goToPrevStep());

expect(result.current.currentStep).toBe(3);
await waitFor(() => {
expect(result.current.currentStep).toBe(3);
});
});

it('setStep 함수를 통해 특정 step로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => {
Expand All @@ -93,35 +123,45 @@ describe('useStep', () => {
await waitFor(() => {
result.current.setStep(2, setStepActionMockFn);
});

expect(result.current.currentStep).toBe(2);
expect(setStepActionMockFn).toBeCalledTimes(1);
await waitFor(() => {
expect(result.current.currentStep).toBe(2);
expect(setStepActionMockFn).toBeCalledTimes(1);
});

// setStep Function
await waitFor(() => {
result.current.setStep((currentStep) => currentStep + 1);
result.current.setStep(
(currentStep) => currentStep + 1,
setStepActionMockFn
);
});
await waitFor(() => {
expect(result.current.currentStep).toBe(3);
expect(setStepActionMockFn).toBeCalledTimes(2);
});

expect(result.current.currentStep).toBe(3);
});

it('초기 step으로 이동해야 하며, action 함수 제공 시 호출해야 합니다.', async () => {
const { result } = renderHook(() =>
useStep({ maxStep: 3, initialStep: 2 })
);

// nextStep
await waitFor(() => {
result.current.goToNextStep();
});
await waitFor(() => {
expect(result.current.currentStep).toBe(3);
});

expect(result.current.currentStep).toBe(3);

// resetStep
await waitFor(() => {
result.current.resetStep(resetStepActionMockFn);
});

expect(result.current.currentStep).toBe(2);
expect(resetStepActionMockFn).toBeCalledTimes(1);
await waitFor(() => {
expect(result.current.currentStep).toBe(2);
expect(resetStepActionMockFn).toBeCalledTimes(1);
});
});

it('유효하지 않은 step 일 시 에러를 던져야 합니다.', async () => {
Expand Down

0 comments on commit 6e3eba3

Please sign in to comment.