From 789462b236a2514ed2fdeba9b2bd63b81f2a418e Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Fri, 17 May 2024 16:09:16 -0600 Subject: [PATCH] fix: Monitors dissapearing from Unit upon edit (#32393) --- .changeset/angry-rocks-try.md | 5 +++ .../ee/client/omnichannel/units/UnitEdit.tsx | 4 +-- .../e2e/omnichannel/omnichannel-units.spec.ts | 35 +++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .changeset/angry-rocks-try.md diff --git a/.changeset/angry-rocks-try.md b/.changeset/angry-rocks-try.md new file mode 100644 index 0000000000000..8072b9db48fb8 --- /dev/null +++ b/.changeset/angry-rocks-try.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixed an issue causing monitors to dissapear from a saved unit every time a user saved the item. This was caused by the UI not sending the correct _id of the monitors that were already saved, and this caused the Backend to ignore them and remove from the list. diff --git a/apps/meteor/ee/client/omnichannel/units/UnitEdit.tsx b/apps/meteor/ee/client/omnichannel/units/UnitEdit.tsx index adb0a2a5c0890..b618d2eac89e3 100644 --- a/apps/meteor/ee/client/omnichannel/units/UnitEdit.tsx +++ b/apps/meteor/ee/client/omnichannel/units/UnitEdit.tsx @@ -85,8 +85,8 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments }: UnitEditProps) => const currUnitMonitors = useMemo( () => - unitMonitors?.map(({ _id, username }) => ({ - value: _id, + unitMonitors?.map(({ monitorId, username }) => ({ + value: monitorId, label: username, })) || [], [unitMonitors], diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-units.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-units.spec.ts index 146885aef55ea..7b4b5d2611cca 100644 --- a/apps/meteor/tests/e2e/omnichannel/omnichannel-units.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-units.spec.ts @@ -24,6 +24,8 @@ test.describe('OC - Manage Units', () => { let monitor: Awaited>; + let monitor2: Awaited>; + test.beforeAll(async ({ api }) => { department = await createDepartment(api); department2 = await createDepartment(api); @@ -35,12 +37,14 @@ test.describe('OC - Manage Units', () => { test.beforeAll(async ({ api }) => { monitor = await createMonitor(api, 'user2'); + monitor2 = await createMonitor(api, 'user3'); }); test.afterAll(async () => { await department.delete(); await department2.delete(); await monitor.delete(); + await monitor2.delete(); await agent.delete(); }); @@ -101,8 +105,9 @@ test.describe('OC - Manage Units', () => { return newUnit; }); - await page.reload(); - + await page.goto('/omnichannel'); + await poOmnichannelUnits.sidenav.linkUnits.click(); + await test.step('expect to edit unit', async () => { await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.findRowByName(unit.name).click(); @@ -117,6 +122,32 @@ test.describe('OC - Manage Units', () => { await expect(poOmnichannelUnits.findRowByName(editedUnitName)).toBeVisible(); }); + await test.step('expect to add another monitor to list', async () => { + await poOmnichannelUnits.findRowByName(editedUnitName).click(); + await poOmnichannelUnits.selectMonitor('user3'); + await poOmnichannelUnits.btnSave.click(); + }); + + await test.step('expect unit to have been edited with 2 monitors', async () => { + await poOmnichannelUnits.search(editedUnitName); + await poOmnichannelUnits.findRowByName(editedUnitName).click(); + + await expect(poOmnichannelUnits.inputMonitors).toHaveText(/user2/); + await expect(poOmnichannelUnits.inputMonitors).toHaveText(/user3/); + }); + + await test.step('expect unit to remove one of the two monitors', async () => { + await poOmnichannelUnits.search(editedUnitName); + await poOmnichannelUnits.findRowByName(editedUnitName).click(); + await poOmnichannelUnits.selectMonitor('user2'); + await poOmnichannelUnits.btnSave.click(); + + await poOmnichannelUnits.search(editedUnitName); + await poOmnichannelUnits.findRowByName(editedUnitName).click(); + await expect(poOmnichannelUnits.inputMonitors).toHaveText(/user3/); + await expect(poOmnichannelUnits.inputMonitors).not.toHaveText(/user2/); + }); + await test.step('expect to delete unit', async () => { await poOmnichannelUnits.findRowByName(editedUnitName).click(); await expect(poOmnichannelUnits.contextualBar).toBeVisible();