Files
calendar/apps/web/test/lib/CheckForEmptyAssignment.test.ts
T
8508a6f1a0 fix: #15697 Assignment warning modal poping up ,even when hosts are added . (#15699)
* removed reduntand check on assignedusers

* update for managed eventtype

* formatted

* comments

* Updated comments

* extracted checkForEmptyAssignment and added tests

* updated comments

* updated to show dialog also when not yet saved

* update translations

* updated comments

* updated translation

* updated types

* chore: update naming and comments

* Delete apps/web/lib/checkForEmptyAssignment.ts

deleted since file was renamed

* Delete apps/web/test/lib/checkForEmptyAssignment.test.ts

deleted as the file is renamed to be more descriptive

* update to do teamcheck before

* chore: revert name to CheckForEmptyAssignment

* updated check conditions

* updated useEffect dependencies

---------

Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
2024-07-29 07:02:59 +03:00

103 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { checkForEmptyAssignment } from "../../lib/checkForEmptyAssignment";
describe("Tests to Check if Event Types have empty Assignment", () => {
it("should return true if managed event type has no assigned users", () => {
expect(
checkForEmptyAssignment({
assignedUsers: [],
assignAllTeamMembers: false,
hosts: [{ userId: 101, isFixed: false, priority: 2 }],
isManagedEventType: true,
})
).toBe(true);
});
it("should return true if non-managed event type has no hosts assigned", () => {
expect(
checkForEmptyAssignment({
assignedUsers: [
{
created: true,
owner: {
id: 101,
avatar: "avatar.svg",
email: "firstuser@cal.com",
membership: "OWNER",
name: "First user",
username: "firstuser",
profile: {
username: "firstuser",
upId: "usr-101",
id: null,
organization: null,
organizationId: null,
},
avatarUrl: null,
nonProfileUsername: null,
},
slug: "managedevent",
hidden: false,
},
],
assignAllTeamMembers: false,
hosts: [],
isManagedEventType: false,
})
).toBe(true);
});
it("should return false if assignAllTeamMembers is selected", () => {
expect(
checkForEmptyAssignment({
assignedUsers: [],
assignAllTeamMembers: true,
hosts: [],
isManagedEventType: false,
})
).toBe(false);
});
it("should return false if non-managed event type has hosts assigned", () => {
expect(
checkForEmptyAssignment({
assignedUsers: [],
assignAllTeamMembers: false,
hosts: [{ userId: 101, isFixed: false, priority: 2 }],
isManagedEventType: false,
})
).toBe(false);
});
it("should return false if managed event type has assigned users", () => {
expect(
checkForEmptyAssignment({
assignedUsers: [
{
created: true,
owner: {
id: 101,
avatar: "avatar.svg",
email: "firstuser@cal.com",
membership: "OWNER",
name: "First user",
username: "firstuser",
profile: {
username: "firstuser",
upId: "usr-101",
id: null,
organization: null,
organizationId: null,
},
avatarUrl: null,
nonProfileUsername: null,
},
slug: "managedevent",
hidden: false,
},
],
assignAllTeamMembers: false,
hosts: [],
isManagedEventType: true,
})
).toBe(false);
});
});