Skip to content

Commit

Permalink
[DLT-1110] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AronPerez committed Jan 3, 2025
1 parent d0215b7 commit 3ed0070
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/package.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"homepage": "https://github.com/ORNL/DataFed#readme",
"devDependencies": {
"chai": "^4",
"sinon": "^15.2.0",
"esm": "^3.2.25",
"mocha": "^10.8.2",
"pug": "^3.0.3"
Expand Down
73 changes: 73 additions & 0 deletions web/test/components/transfer/transfer-dialog-controller.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect } from "chai";
import sinon from "sinon";
import { TransferDialogController } from "../../../static/components/transfer/transfer-dialog-controller.js";
import { TransferModel } from "../../../static/models/transfer-model.js";
import { TransferEndpointManager } from "../../../static/components/transfer/transfer-endpoint-manager.js";
import { TransferUIManager } from "../../../static/components/transfer/transfer-ui-manager.js";
import * as dialogs from "../../../static/dialogs.js";

describe("TransferDialogController", () => {
let controller;
let mockCallback;
const TEST_MODE = 1;
const TEST_IDS = [{ id: 1 }, { id: 2 }];

beforeEach(() => {
mockCallback = sinon.spy();
sinon.stub(TransferModel.prototype);
sinon.stub(TransferEndpointManager.prototype);
sinon.stub(TransferUIManager.prototype, "createDialog");
sinon.stub(TransferUIManager.prototype, "initializeComponents");
sinon.stub(TransferUIManager.prototype, "attachMatchesHandler");
sinon.stub(TransferUIManager.prototype, "showDialog");
sinon.stub(dialogs, "dlgAlert");

controller = new TransferDialogController(TEST_MODE, TEST_IDS, mockCallback);
});

afterEach(() => {
sinon.restore();
});

describe("constructor", () => {
it("should initialize with correct parameters", () => {
expect(controller.model).to.be.instanceOf(TransferModel);
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);
});
});

describe("show", () => {
it("should successfully show the transfer dialog", () => {
controller.show();

expect(controller.uiManager.createDialog.calledOnce).to.be.true;
expect(controller.uiManager.initializeComponents.calledOnce).to.be.true;
expect(controller.uiManager.attachMatchesHandler.calledOnce).to.be.true;
expect(controller.uiManager.showDialog.calledOnce).to.be.true;
expect(controller.endpointManager.initialized).to.be.true;
});

it("should handle errors and show alert dialog", () => {
controller.uiManager.createDialog.throws(new Error("Test error"));
controller.show();

expect(dialogs.dlgAlert.calledOnce).to.be.true;
expect(dialogs.dlgAlert.calledWith("Error", "Failed to open transfer dialog")).to.be
.true;
});

it("should call UI methods in correct order", () => {
controller.show();

sinon.assert.callOrder(
controller.uiManager.createDialog,
controller.uiManager.initializeComponents,
controller.uiManager.attachMatchesHandler,
controller.uiManager.showDialog,
);
});
});
});

0 comments on commit 3ed0070

Please sign in to comment.