-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DLT-1110] Update tests, add fixtures, update setup, lock in packages
- Loading branch information
Showing
6 changed files
with
446 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 43 additions & 33 deletions
76
web/test/components/transfer/transfer-dialog-controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,80 @@ | ||
import { expect, sinon } from "../../setup.js"; | ||
import { createMockServices, setupJQueryMocks } from "../../fixtures/transfer-fixtures.js"; | ||
import { TransferDialogController } from "../../../static/components/transfer/transfer-dialog-controller.js"; | ||
import { TransferEndpointManager } from "../../../static/components/transfer/transfer-endpoint-manager.js"; | ||
import { TransferModel } from "../../../static/models/transfer-model.js"; | ||
import { TransferMode } from "../../../static/models/transfer-model.js"; | ||
import { TransferUIManager } from "../../../static/components/transfer/transfer-ui-manager.js"; | ||
|
||
describe("TransferDialogController", () => { | ||
let controller; | ||
let mockCallback; | ||
let mockServices; | ||
let sandbox; | ||
let uiManagerStub; | ||
let endpointManagerStub; | ||
let modelStub; | ||
|
||
const TEST_MODE = 1; | ||
const TEST_MODE = TransferMode.TT_DATA_PUT; | ||
const TEST_IDS = [{ id: 1 }, { id: 2 }]; | ||
const TEST_DIALOG_LABELS = { title: "Test Title", button: "Test Button" }; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
mockCallback = sandbox.stub(); | ||
mockServices = createMockServices(); | ||
setupJQueryMocks(sandbox); | ||
|
||
modelStub = new TransferModel(TEST_MODE, TEST_IDS); | ||
endpointManagerStub = new TransferEndpointManager(); | ||
uiManagerStub = new TransferUIManager(); | ||
|
||
sandbox.stub(modelStub); | ||
|
||
uiManagerStub.createDialog = sandbox.stub(); | ||
uiManagerStub.initializeComponents = sandbox.stub(); | ||
uiManagerStub.attachMatchesHandler = sandbox.stub(); | ||
uiManagerStub.showDialog = sandbox.stub(); | ||
uiManagerStub.getDialogLabels = sandbox.stub().returns(TEST_DIALOG_LABELS); | ||
|
||
endpointManagerStub.initialized = false; | ||
controller = new TransferDialogController(TEST_MODE, TEST_IDS, mockCallback); | ||
|
||
controller.uiManager = uiManagerStub; | ||
controller.endpointManager = endpointManagerStub; | ||
controller.model = modelStub; | ||
controller = new TransferDialogController(TEST_MODE, TEST_IDS, mockCallback, mockServices); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("constructor", () => { | ||
it("should initialize with correct parameters", () => { | ||
const newController = new TransferDialogController(TEST_MODE, TEST_IDS, mockCallback); | ||
it("should initialize with correct parameters and components", () => { | ||
expect(controller.endpointManager).to.be.instanceOf(TransferEndpointManager); | ||
expect(controller.uiManager).to.be.instanceOf(TransferUIManager); | ||
expect(controller.ids).to.deep.equal(TEST_IDS); | ||
expect(controller.callback).to.equal(mockCallback); | ||
|
||
expect(newController.model).to.be.instanceOf(TransferModel); | ||
expect(newController.endpointManager).to.be.instanceOf(TransferEndpointManager); | ||
expect(newController.uiManager).to.be.instanceOf(TransferUIManager); | ||
expect(newController.ids).to.deep.equal(TEST_IDS); | ||
expect(newController.callback).to.equal(mockCallback); | ||
expect(controller.endpointManager.api).to.equal(mockServices.api); | ||
expect(controller.uiManager.api).to.equal(mockServices.api); | ||
expect(controller.endpointManager.dialogs).to.equal(mockServices.dialogs); | ||
expect(controller.uiManager.dialogs).to.equal(mockServices.dialogs); | ||
}); | ||
|
||
it("should initialize with default services if none provided", () => { | ||
const defaultController = new TransferDialogController( | ||
TEST_MODE, | ||
TEST_IDS, | ||
mockCallback, | ||
); | ||
expect(defaultController.services).to.have.property("dialogs"); | ||
expect(defaultController.services).to.have.property("api"); | ||
}); | ||
}); | ||
|
||
describe("show", () => { | ||
it("should successfully show the transfer dialog", async () => { | ||
sandbox.stub(controller.uiManager, "initializeComponents"); | ||
sandbox.stub(controller.uiManager, "attachMatchesHandler"); | ||
sandbox.stub(controller.uiManager, "showDialog"); | ||
|
||
await controller.show(); | ||
|
||
expect(controller.uiManager.createDialog.called).to.be.true; | ||
expect(controller.uiManager.initializeComponents.called).to.be.true; | ||
expect(controller.uiManager.attachMatchesHandler.called).to.be.true; | ||
expect(controller.uiManager.showDialog.called).to.be.true; | ||
expect(controller.endpointManager.initialized).to.be.true; | ||
expect(controller.uiManager.showDialog.called).to.be.true; | ||
}); | ||
|
||
it("should handle errors gracefully", async () => { | ||
sandbox | ||
.stub(controller.uiManager, "initializeComponents") | ||
.throws(new Error("Test error")); | ||
|
||
await controller.show(); | ||
|
||
expect( | ||
mockServices.dialogs.dlgAlert.calledWith("Error", "Failed to open transfer dialog"), | ||
).to.be.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.