Drag and drop working
This commit is contained in:
@@ -174,5 +174,130 @@ describe("circuit write service rules", () => {
|
||||
assert.deepEqual(updatedIds, ["c1", "c2"]);
|
||||
assert.equal(result.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
it("moving a device row to another circuit preserves row and toggles reserve flags", async () => {
|
||||
const updatedReserve: Array<{ id: string; isReserve: boolean }> = [];
|
||||
const movedCalls: Array<{ rowId: string; targetCircuitId: string; sortOrder: number }> = [];
|
||||
const service = new CircuitWriteService({
|
||||
deviceRowRepository: {
|
||||
async findById() {
|
||||
return { id: "r1", circuitId: "c1" } as never;
|
||||
},
|
||||
async countByCircuit(circuitId: string) {
|
||||
if (circuitId === "c2") {
|
||||
return 2;
|
||||
}
|
||||
if (circuitId === "c1") {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
async moveToCircuit(rowId: string, targetCircuitId: string, sortOrder: number) {
|
||||
movedCalls.push({ rowId, targetCircuitId, sortOrder });
|
||||
},
|
||||
} as never,
|
||||
circuitRepository: {
|
||||
async findById(circuitId: string) {
|
||||
if (circuitId === "c1") {
|
||||
return {
|
||||
id: "c1",
|
||||
sectionId: "s1",
|
||||
circuitListId: "l1",
|
||||
equipmentIdentifier: "-1F1",
|
||||
sortOrder: 10,
|
||||
isReserve: 0,
|
||||
} as never;
|
||||
}
|
||||
return {
|
||||
id: "c2",
|
||||
sectionId: "s1",
|
||||
circuitListId: "l1",
|
||||
equipmentIdentifier: "-1F2",
|
||||
sortOrder: 20,
|
||||
isReserve: 1,
|
||||
} as never;
|
||||
},
|
||||
async update(id: string, payload: { isReserve: boolean }) {
|
||||
updatedReserve.push({ id, isReserve: payload.isReserve });
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await service.moveDeviceRow("r1", { targetCircuitId: "c2" });
|
||||
assert.deepEqual(movedCalls, [{ rowId: "r1", targetCircuitId: "c2", sortOrder: 30 }]);
|
||||
assert.deepEqual(updatedReserve, [
|
||||
{ id: "c1", isReserve: true },
|
||||
{ id: "c2", isReserve: false },
|
||||
]);
|
||||
});
|
||||
|
||||
it("moving a device row to placeholder creates a new circuit in target section", async () => {
|
||||
let createdCircuitPayload: { sectionId: string; equipmentIdentifier: string; isReserve?: boolean } | null = null;
|
||||
const service = new CircuitWriteService({
|
||||
deviceRowRepository: {
|
||||
async findById() {
|
||||
return { id: "r1", circuitId: "c1" } as never;
|
||||
},
|
||||
async countByCircuit(circuitId: string) {
|
||||
if (circuitId === "c-new") {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
},
|
||||
async moveToCircuit() {
|
||||
return;
|
||||
},
|
||||
} as never,
|
||||
circuitRepository: {
|
||||
async findById(circuitId: string) {
|
||||
if (circuitId === "c1") {
|
||||
return {
|
||||
id: "c1",
|
||||
sectionId: "s1",
|
||||
circuitListId: "l1",
|
||||
equipmentIdentifier: "-1F1",
|
||||
sortOrder: 10,
|
||||
isReserve: 0,
|
||||
} as never;
|
||||
}
|
||||
if (circuitId === "c-new") {
|
||||
return {
|
||||
id: "c-new",
|
||||
sectionId: "s2",
|
||||
circuitListId: "l1",
|
||||
equipmentIdentifier: "-2F8",
|
||||
sortOrder: 50,
|
||||
isReserve: 0,
|
||||
} as never;
|
||||
}
|
||||
return null as never;
|
||||
},
|
||||
async listBySection() {
|
||||
return [{ sortOrder: 40 }] as never[];
|
||||
},
|
||||
async create(payload: { sectionId: string; equipmentIdentifier: string; isReserve?: boolean }) {
|
||||
createdCircuitPayload = payload;
|
||||
return "c-new";
|
||||
},
|
||||
async update() {
|
||||
return;
|
||||
},
|
||||
} as never,
|
||||
circuitSectionRepository: {
|
||||
async findById() {
|
||||
return { id: "s2", circuitListId: "l1", prefix: "-2F" } as never;
|
||||
},
|
||||
} as never,
|
||||
numberingService: {
|
||||
async getNextIdentifier() {
|
||||
return "-2F8";
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await service.moveDeviceRow("r1", { targetSectionId: "s2", createNewCircuit: true });
|
||||
assert.equal(createdCircuitPayload?.sectionId, "s2");
|
||||
assert.equal(createdCircuitPayload?.equipmentIdentifier, "-2F8");
|
||||
assert.equal(createdCircuitPayload?.isReserve, false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user