mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
refactor: update unit tests for setRunningState to use new state management
- Replaced direct access to state variables with calls to the new getSpecRegenerationStatus function in unit tests for setRunningState. - This change improves encapsulation and ensures that tests reflect the updated state management logic.
This commit is contained in:
@@ -2,8 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest";
|
|||||||
import {
|
import {
|
||||||
setRunningState,
|
setRunningState,
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
isRunning,
|
getSpecRegenerationStatus,
|
||||||
currentAbortController,
|
|
||||||
} from "@/routes/app-spec/common.js";
|
} from "@/routes/app-spec/common.js";
|
||||||
|
|
||||||
describe("app-spec/common.ts", () => {
|
describe("app-spec/common.ts", () => {
|
||||||
@@ -15,33 +14,35 @@ describe("app-spec/common.ts", () => {
|
|||||||
describe("setRunningState", () => {
|
describe("setRunningState", () => {
|
||||||
it("should set isRunning to true when running is true", () => {
|
it("should set isRunning to true when running is true", () => {
|
||||||
setRunningState(true);
|
setRunningState(true);
|
||||||
expect(isRunning).toBe(true);
|
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set isRunning to false when running is false", () => {
|
it("should set isRunning to false when running is false", () => {
|
||||||
setRunningState(true);
|
setRunningState(true);
|
||||||
setRunningState(false);
|
setRunningState(false);
|
||||||
expect(isRunning).toBe(false);
|
expect(getSpecRegenerationStatus().isRunning).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set currentAbortController when provided", () => {
|
it("should set currentAbortController when provided", () => {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
setRunningState(true, controller);
|
setRunningState(true, controller);
|
||||||
expect(currentAbortController).toBe(controller);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||||
|
controller
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set currentAbortController to null when not provided", () => {
|
it("should set currentAbortController to null when not provided", () => {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
setRunningState(true, controller);
|
setRunningState(true, controller);
|
||||||
setRunningState(false);
|
setRunningState(false);
|
||||||
expect(currentAbortController).toBe(null);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set currentAbortController to null when explicitly passed null", () => {
|
it("should set currentAbortController to null when explicitly passed null", () => {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
setRunningState(true, controller);
|
setRunningState(true, controller);
|
||||||
setRunningState(true, null);
|
setRunningState(true, null);
|
||||||
expect(currentAbortController).toBe(null);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update state multiple times correctly", () => {
|
it("should update state multiple times correctly", () => {
|
||||||
@@ -49,16 +50,20 @@ describe("app-spec/common.ts", () => {
|
|||||||
const controller2 = new AbortController();
|
const controller2 = new AbortController();
|
||||||
|
|
||||||
setRunningState(true, controller1);
|
setRunningState(true, controller1);
|
||||||
expect(isRunning).toBe(true);
|
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||||
expect(currentAbortController).toBe(controller1);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||||
|
controller1
|
||||||
|
);
|
||||||
|
|
||||||
setRunningState(true, controller2);
|
setRunningState(true, controller2);
|
||||||
expect(isRunning).toBe(true);
|
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||||
expect(currentAbortController).toBe(controller2);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||||
|
controller2
|
||||||
|
);
|
||||||
|
|
||||||
setRunningState(false, null);
|
setRunningState(false, null);
|
||||||
expect(isRunning).toBe(false);
|
expect(getSpecRegenerationStatus().isRunning).toBe(false);
|
||||||
expect(currentAbortController).toBe(null);
|
expect(getSpecRegenerationStatus().currentAbortController).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user