Files
monorepo/LCU.WebApps.Operations.IncentiveManager/src/components/activity-detail/ActivityTransferToOwnDepartmentRequest.test.tsx
T
2026-03-23 11:21:52 -05:00

373 lines
12 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 ActivityTransferToOwnDepartmentRequest from "./ActivityTransferToOwnDepartmentRequest";
import { IDepartmentAssignment } from "../../shared/models/DepartmentAssignment";
import { UserType } from "../../shared/models/Auditable";
describe("ActivityTransferToOwnDepartmentRequest", () => {
it("should call props onFormSubmit with selected department and current activity employeeId", () => {
const mockFormSubmit = jest.fn();
const mockOwnedDepartments: IDepartmentAssignment[] = [
{
id: 3,
employeeId: "C0000",
departmentId: 12,
startDate: moment(),
endDate: undefined,
note: "Test",
isHome: true,
slidingPayout: 1,
created: moment(),
createdBy: "George Frick",
createdByType: UserType.Associate,
lastUpdatedBy: "Incentive Manager",
lastUpdated: moment(),
lastUpdatedByType: UserType.System,
role: {
name: "test role",
rank: 1,
description: "test test",
hasCommissions: false,
permissions: [
{
code: "Secret",
description: "Secret Test Code"
}
]
}
},
{
id: 4,
employeeId: "C0000",
departmentId: 14,
startDate: moment(),
endDate: undefined,
note: "Test",
isHome: true,
slidingPayout: 1,
created: moment(),
createdBy: "George Frick",
createdByType: UserType.Associate,
lastUpdatedBy: "Incentive Manager",
lastUpdated: moment(),
lastUpdatedByType: UserType.System,
role: {
name: "test role",
rank: 1,
description: "test test",
hasCommissions: false,
permissions: [
{
code: "Secret",
description: "Secret Test Code"
}
]
}
}
];
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(
<ActivityTransferToOwnDepartmentRequest
allDepartments={[]}
ownedDepartments={mockOwnedDepartments}
currentEmployeeId="C0000"
activity={mockActivity}
onFormSubmit={mockFormSubmit}
/>
);
expect(
wrapper
.find(
"[data-test='activity-transfer-request-own-department-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-own-department-button']"
)
.prop("disabled")
).toBe(false);
wrapper
.find(
"[data-test='activity-transfer-request-own-department-button']"
)
.simulate("click");
expect(mockFormSubmit).toHaveBeenCalledTimes(1);
expect(mockFormSubmit).toHaveBeenLastCalledWith("25", "C0000");
});
it("it should not display if the activity is not owned by the current appUser", () => {
const mockFormSubmit = jest.fn();
const mockOwnedDepartments: IDepartmentAssignment[] = [
{
id: 3,
employeeId: "C0000",
departmentId: 12,
startDate: moment(),
endDate: undefined,
note: "Test",
isHome: true,
slidingPayout: 1,
created: moment(),
createdBy: "George Frick",
createdByType: UserType.Associate,
lastUpdatedBy: "Incentive Manager",
lastUpdated: moment(),
lastUpdatedByType: UserType.System,
role: {
name: "test role",
rank: 1,
description: "test test",
hasCommissions: false,
permissions: [
{
code: "Secret",
description: "Secret Test Code"
}
]
}
},
{
id: 4,
employeeId: "C0000",
departmentId: 14,
startDate: moment(),
endDate: undefined,
note: "Test",
isHome: true,
slidingPayout: 1,
created: moment(),
createdBy: "George Frick",
createdByType: UserType.Associate,
lastUpdatedBy: "Incentive Manager",
lastUpdated: moment(),
lastUpdatedByType: UserType.System,
role: {
name: "test role",
rank: 1,
description: "test test",
hasCommissions: false,
permissions: [
{
code: "Secret",
description: "Secret Test Code"
}
]
}
}
];
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(
<ActivityTransferToOwnDepartmentRequest
allDepartments={[]}
ownedDepartments={mockOwnedDepartments}
currentEmployeeId="C0001"
activity={mockActivity}
onFormSubmit={mockFormSubmit}
/>
);
expect(
wrapper.find("[data-test='transfer-request-own-department-form']")
.length
).toBe(0);
});
it("it should not display if the appUser only has one current department", () => {
const mockFormSubmit = jest.fn();
const mockOwnedDepartments: IDepartmentAssignment[] = [
{
id: 3,
employeeId: "C0000",
departmentId: 12,
startDate: moment(),
endDate: undefined,
note: "Test",
isHome: true,
slidingPayout: 1,
created: moment(),
createdBy: "George Frick",
createdByType: UserType.Associate,
lastUpdatedBy: "Incentive Manager",
lastUpdated: moment(),
lastUpdatedByType: UserType.System,
role: {
name: "test role",
rank: 1,
description: "test test",
hasCommissions: false,
permissions: [
{
code: "Secret",
description: "Secret Test Code"
}
]
}
}
];
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(
<ActivityTransferToOwnDepartmentRequest
allDepartments={[]}
ownedDepartments={mockOwnedDepartments}
currentEmployeeId="C0000"
activity={mockActivity}
onFormSubmit={mockFormSubmit}
/>
);
expect(
wrapper.find("[data-test='transfer-request-own-department-form']")
.length
).toBe(0);
});
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(
<ActivityTransferToOwnDepartmentRequest
allDepartments={[]}
ownedDepartments={[]}
currentEmployeeId="C0000"
activity={mockActivity}
onFormSubmit={mockFormSubmit}
/>
);
expect(
wrapper.find("[data-test='transfer-request-own-department-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(
<ActivityTransferToOwnDepartmentRequest
allDepartments={[]}
ownedDepartments={[]}
currentEmployeeId="C0000"
activity={mockActivity}
onFormSubmit={mockFormSubmit}
/>
);
expect(
wrapper.find("[data-test='transfer-request-own-department-form']")
.length
).toBe(0);
});
});