Skip to content
55 changes: 16 additions & 39 deletions frontend/__tests__/controllers/preset-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as ConfigUtils from "../../src/ts/config/utils";
import * as Persistence from "../../src/ts/config/persistence";
import * as Notifications from "../../src/ts/states/notifications";
import * as TestLogic from "../../src/ts/test/test-logic";
import * as TagController from "../../src/ts/controllers/tag-controller";
import * as Tags from "../../src/ts/collections/tags";

describe("PresetController", () => {
describe("apply", () => {
Expand All @@ -34,12 +34,9 @@ describe("PresetController", () => {
"showSuccessNotification",
);
const testRestartMock = vi.spyOn(TestLogic, "restart");
const tagControllerClearMock = vi.spyOn(TagController, "clear");
const tagControllerSetMock = vi.spyOn(TagController, "set");
const tagControllerSaveActiveMock = vi.spyOn(
TagController,
"saveActiveToLocalStorage",
);
const tagsClearMock = vi.spyOn(Tags, "clearActiveTags");
const tagsSetMock = vi.spyOn(Tags, "setTagActive");
const tagsSaveActiveMock = vi.spyOn(Tags, "saveActiveToLocalStorage");

beforeEach(() => {
[
Expand All @@ -49,9 +46,9 @@ describe("PresetController", () => {
configGetConfigChangesMock,
notificationAddMock,
testRestartMock,
tagControllerClearMock,
tagControllerSetMock,
tagControllerSaveActiveMock,
tagsClearMock,
tagsSetMock,
tagsSaveActiveMock,
].forEach((it) => it.mockClear());

configApplyMock.mockResolvedValue();
Expand All @@ -66,7 +63,7 @@ describe("PresetController", () => {

//THEN
expect(configApplyMock).toHaveBeenCalledWith(preset.config);
expect(tagControllerClearMock).toHaveBeenCalled();
expect(tagsClearMock).toHaveBeenCalled();
expect(testRestartMock).toHaveBeenCalled();
expect(notificationAddMock).toHaveBeenCalledWith("Preset applied", {
durationMs: 2000,
Expand All @@ -84,20 +81,10 @@ describe("PresetController", () => {
await PresetController.apply(preset._id);

//THEN
expect(tagControllerClearMock).toHaveBeenCalled();
expect(tagControllerSetMock).toHaveBeenNthCalledWith(
1,
"tagOne",
true,
false,
);
expect(tagControllerSetMock).toHaveBeenNthCalledWith(
2,
"tagTwo",
true,
false,
);
expect(tagControllerSaveActiveMock).toHaveBeenCalled();
expect(tagsClearMock).toHaveBeenCalled();
expect(tagsSetMock).toHaveBeenNthCalledWith(1, "tagOne", true, false);
expect(tagsSetMock).toHaveBeenNthCalledWith(2, "tagTwo", true, false);
expect(tagsSaveActiveMock).toHaveBeenCalled();
});

it("should ignore unknown preset", async () => {
Expand Down Expand Up @@ -145,20 +132,10 @@ describe("PresetController", () => {
await PresetController.apply(preset._id);

//THEN
expect(tagControllerClearMock).toHaveBeenCalled();
expect(tagControllerSetMock).toHaveBeenNthCalledWith(
1,
"tagOne",
true,
false,
);
expect(tagControllerSetMock).toHaveBeenNthCalledWith(
2,
"tagTwo",
true,
false,
);
expect(tagControllerSaveActiveMock).toHaveBeenCalled();
expect(tagsClearMock).toHaveBeenCalled();
expect(tagsSetMock).toHaveBeenNthCalledWith(1, "tagOne", true, false);
expect(tagsSetMock).toHaveBeenNthCalledWith(2, "tagTwo", true, false);
expect(tagsSaveActiveMock).toHaveBeenCalled();
});

const givenPreset = (partialPreset: Partial<Preset>): Preset => {
Expand Down
Loading
Loading