155 lines
4.8 KiB
TypeScript
155 lines
4.8 KiB
TypeScript
import { shallow } from "enzyme";
|
|
import moment from "moment";
|
|
import React from "react";
|
|
import Product2 from "../../shared/enumerations/Product";
|
|
import {
|
|
ActivityState,
|
|
ActivityType,
|
|
IActivity,
|
|
SystemType
|
|
} from "../../shared/models/Activity";
|
|
import ActivityTransferRequest from "./ActivityTransferRequest";
|
|
|
|
describe("ActivityTransferRequest", () => {
|
|
it("should call props onFormSubmit with selected department and employee", () => {
|
|
const mockFormSubmit = jest.fn();
|
|
const mockActivity: IActivity = {
|
|
id: 1,
|
|
product: Product2.ATMCard,
|
|
sourceSystem: SystemType.Dna,
|
|
activityPayouts: [],
|
|
departmentId: "1",
|
|
detail: {},
|
|
employeeEmail: "[email protected]",
|
|
employeeId: "C0000",
|
|
type: ActivityType.Sale,
|
|
state: ActivityState.Accepted
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<ActivityTransferRequest
|
|
departments={[]}
|
|
activity={mockActivity}
|
|
onFormSubmit={mockFormSubmit}
|
|
/>
|
|
);
|
|
|
|
expect(
|
|
wrapper
|
|
.find("[data-test='activity-transfer-request-button']")
|
|
.prop("disabled")
|
|
).toBe(true);
|
|
|
|
wrapper
|
|
.find("UserSearchSelect")
|
|
.prop<(field: string, newValue: any) => void>("onUserSelected")(
|
|
"25",
|
|
"C002"
|
|
);
|
|
|
|
expect(
|
|
wrapper
|
|
.find("[data-test='activity-transfer-request-button']")
|
|
.prop("disabled")
|
|
).toBe(true);
|
|
|
|
wrapper.find("[data-test='dept-input']").prop<any>("onChange")({
|
|
target: { value: "25" }
|
|
});
|
|
expect(
|
|
wrapper
|
|
.find("[data-test='activity-transfer-request-button']")
|
|
.prop("disabled")
|
|
).toBe(false);
|
|
|
|
wrapper
|
|
.find("[data-test='activity-transfer-request-button']")
|
|
.simulate("click");
|
|
|
|
expect(mockFormSubmit).toHaveBeenCalledTimes(1);
|
|
expect(mockFormSubmit).toHaveBeenLastCalledWith("25", "C002");
|
|
});
|
|
|
|
it("should not display if the activity has payouts", () => {
|
|
const mockFormSubmit = jest.fn();
|
|
const mockActivity: IActivity = {
|
|
id: 1,
|
|
product: Product2.ATMCard,
|
|
sourceSystem: SystemType.Dna,
|
|
activityPayouts: [
|
|
{
|
|
payoutLineItem: {
|
|
id: 1,
|
|
activityPeriod: moment.utc(),
|
|
departmentId: 25,
|
|
role: {
|
|
description: "Teller",
|
|
name: "Teller Doe",
|
|
permissions: [],
|
|
hasCommissions: true,
|
|
rank: 1
|
|
},
|
|
product: "ATMCard",
|
|
goalId: 2,
|
|
goalValue: 3,
|
|
commissionId: 4,
|
|
commissionValue: 5,
|
|
employeeId: "123",
|
|
activityTotal: 100,
|
|
payoutTotal: 200,
|
|
slidingPayout: 12,
|
|
activityPayouts: undefined,
|
|
payoutProfileId: undefined
|
|
}
|
|
}
|
|
],
|
|
departmentId: "1",
|
|
detail: {},
|
|
employeeEmail: "[email protected]",
|
|
employeeId: "C0000",
|
|
type: ActivityType.Sale,
|
|
state: ActivityState.Accepted
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<ActivityTransferRequest
|
|
departments={[]}
|
|
activity={mockActivity}
|
|
onFormSubmit={mockFormSubmit}
|
|
/>
|
|
);
|
|
|
|
expect(wrapper.find("[data-test='transfer-request-form']").length).toBe(
|
|
0
|
|
);
|
|
});
|
|
|
|
it("should not display if the activity is in PendingTransfer state", () => {
|
|
const mockFormSubmit = jest.fn();
|
|
const mockActivity: IActivity = {
|
|
id: 1,
|
|
product: Product2.ATMCard,
|
|
sourceSystem: SystemType.Dna,
|
|
activityPayouts: [],
|
|
departmentId: "1",
|
|
detail: {},
|
|
employeeEmail: "[email protected]",
|
|
employeeId: "C0000",
|
|
type: ActivityType.Sale,
|
|
state: ActivityState.PendingTransfer
|
|
};
|
|
|
|
const wrapper = shallow(
|
|
<ActivityTransferRequest
|
|
departments={[]}
|
|
activity={mockActivity}
|
|
onFormSubmit={mockFormSubmit}
|
|
/>
|
|
);
|
|
|
|
expect(wrapper.find("[data-test='transfer-request-form']").length).toBe(
|
|
0
|
|
);
|
|
});
|
|
});
|