diff --git a/.changeset/rotten-candles-train.md b/.changeset/rotten-candles-train.md new file mode 100644 index 00000000000..8837d7009a2 --- /dev/null +++ b/.changeset/rotten-candles-train.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes the "Enabled" toggle always being displayed as active when editing a business hour. diff --git a/apps/meteor/client/views/omnichannel/businessHours/EditBusinessHours.tsx b/apps/meteor/client/views/omnichannel/businessHours/EditBusinessHours.tsx index 7d459cfe5a9..63f7ece3d60 100644 --- a/apps/meteor/client/views/omnichannel/businessHours/EditBusinessHours.tsx +++ b/apps/meteor/client/views/omnichannel/businessHours/EditBusinessHours.tsx @@ -25,7 +25,7 @@ const getInitialData = (businessHourData: Serialized | un open, })), departmentsToApplyBusinessHour: '', - active: businessHourData?.active || true, + active: businessHourData?.active ?? true, departments: businessHourData?.departments?.map(({ _id, name }) => ({ value: _id, label: name })) || [], }); diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-business-hours.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-business-hours.spec.ts index 2c5dc162e50..ed179249d7c 100644 --- a/apps/meteor/tests/e2e/omnichannel/omnichannel-business-hours.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-business-hours.spec.ts @@ -19,6 +19,9 @@ test.describe('OC - Business Hours', () => { let department2: Awaited>; let agent: Awaited>; + const BHid = faker.string.uuid(); + const BHName = 'TEST Business Hours'; + test.beforeAll(async ({ api }) => { department = await createDepartment(api); department2 = await createDepartment(api); @@ -40,8 +43,6 @@ test.describe('OC - Business Hours', () => { }); test('OC - Manage Business Hours - Create Business Hours', async ({ page }) => { - const BHName = faker.string.uuid(); - await page.goto('/omnichannel'); await poOmnichannelBusinessHours.sidenav.linkBusinessHours.click(); @@ -86,11 +87,9 @@ test.describe('OC - Business Hours', () => { }); test('OC - Business hours - Edit BH departments', async ({ api, page }) => { - const BHName = faker.string.uuid(); - await test.step('expect to create new businessHours', async () => { const createBH = await createBusinessHour(api, { - id: '33', + id: BHid, name: BHName, departments: [department.data._id], }); @@ -136,4 +135,49 @@ test.describe('OC - Business Hours', () => { await expect(poOmnichannelBusinessHours.confirmDeleteModal).not.toBeVisible(); }); }); + + test('OC - Business hours - Toggle BH active status', async ({ api, page }) => { + await test.step('expect to create new businessHours', async () => { + const createBH = await createBusinessHour(api, { + id: BHid, + name: BHName, + departments: [department.data._id], + }); + + expect(createBH.status()).toBe(200); + }); + + await page.goto('/omnichannel'); + await poOmnichannelBusinessHours.sidenav.linkBusinessHours.click(); + + await test.step('expect to disable business hours', async () => { + await poOmnichannelBusinessHours.sidenav.linkBusinessHours.click(); + + await poOmnichannelBusinessHours.search(BHName); + await poOmnichannelBusinessHours.findRowByName(BHName).click(); + + await poOmnichannelBusinessHours.getCheckboxByLabel('Enabled').click(); + await expect(poOmnichannelBusinessHours.getCheckboxByLabel('Enabled')).not.toBeChecked(); + + await poOmnichannelBusinessHours.btnSave.click(); + }); + + await test.step('expect to enable business hours', async () => { + await poOmnichannelBusinessHours.sidenav.linkBusinessHours.click(); + + await poOmnichannelBusinessHours.search(BHName); + await poOmnichannelBusinessHours.findRowByName(BHName).click(); + + await poOmnichannelBusinessHours.getCheckboxByLabel('Enabled').click(); + await expect(poOmnichannelBusinessHours.getCheckboxByLabel('Enabled')).toBeChecked(); + + await poOmnichannelBusinessHours.btnSave.click(); + }); + + await test.step('expect delete business hours', async () => { + await poOmnichannelBusinessHours.btnDeleteByName(BHName).click(); + await expect(poOmnichannelBusinessHours.confirmDeleteModal).toBeVisible(); + await poOmnichannelBusinessHours.btnConfirmDeleteModal.click(); + }); + }); }); diff --git a/apps/meteor/tests/e2e/page-objects/omnichannel-business-hours.ts b/apps/meteor/tests/e2e/page-objects/omnichannel-business-hours.ts index a77784c4538..b411c9a2108 100644 --- a/apps/meteor/tests/e2e/page-objects/omnichannel-business-hours.ts +++ b/apps/meteor/tests/e2e/page-objects/omnichannel-business-hours.ts @@ -51,6 +51,10 @@ export class OmnichannelBusinessHours extends OmnichannelAdministration { return this.confirmDeleteModal.locator('role=button[name="Delete"]'); } + getCheckboxByLabel(name: string): Locator { + return this.page.locator('label', { has: this.page.getByRole('checkbox', { name }) }); + } + private selectOption(name: string): Locator { return this.page.locator(`[role=option][value="${name}"]`); }