fix: Favoriting room through rooms page (#31554)

Co-authored-by: Henrique Guimarães Ribeiro <43561537+rique223@users.noreply.github.com>
pull/31585/head^2
Shivang Yadav 2 years ago committed by GitHub
parent ef683599be
commit 5c29cec75e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/serious-cows-compete.md
  2. 11
      apps/meteor/client/views/admin/rooms/EditRoom.tsx
  3. 10
      apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx
  4. 22
      apps/meteor/tests/e2e/administration.spec.ts
  5. 16
      apps/meteor/tests/e2e/page-objects/admin.ts

@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---
Fixed a bug on the rooms page's "Favorite" setting, which previously failed to designate selected rooms as favorites by default.

@ -13,7 +13,7 @@ import {
TextAreaInput,
FieldError,
} from '@rocket.chat/fuselage';
import { useMutableCallback, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useEffectEvent, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useRouter, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import { useForm, Controller } from 'react-hook-form';
@ -96,9 +96,10 @@ const EditRoom = ({ room, onChange, onDelete }: EditRoomProps) => {
const handleArchive = useArchiveRoom(room);
const handleUpdateRoomData = useMutableCallback(async ({ isDefault, roomName, favorite, ...formData }) => {
const handleUpdateRoomData = useEffectEvent(async ({ isDefault, roomName, favorite, ...formData }) => {
const data = getDirtyFields(formData, dirtyFields);
delete data.archived;
delete data.favorite;
try {
await saveAction({
@ -117,9 +118,9 @@ const EditRoom = ({ room, onChange, onDelete }: EditRoomProps) => {
}
});
const handleSave = useMutableCallback(async (data) => {
await Promise.all([isDirty && handleUpdateRoomData(data), changeArchiving && handleArchive()].filter(Boolean));
});
const handleSave = useEffectEvent((data) =>
Promise.all([isDirty && handleUpdateRoomData(data), changeArchiving && handleArchive()].filter(Boolean)),
);
const formId = useUniqueId();
const roomNameField = useUniqueId();

@ -20,7 +20,7 @@ import {
Box,
TextAreaInput,
} from '@rocket.chat/fuselage';
import { useMutableCallback, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useEffectEvent, useUniqueId } from '@rocket.chat/fuselage-hooks';
import type { TranslationKey } from '@rocket.chat/ui-contexts';
import { useSetting, useTranslation, useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts';
import React, { useMemo } from 'react';
@ -98,7 +98,7 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
const handleArchive = useArchiveRoom(room);
const handleUpdateRoomData = useMutableCallback(async ({ hideSysMes, joinCodeRequired, ...formData }) => {
const handleUpdateRoomData = useEffectEvent(async ({ hideSysMes, joinCodeRequired, ...formData }) => {
const data = getDirtyFields(formData, dirtyFields);
delete data.archived;
@ -119,9 +119,9 @@ const EditRoomInfo = ({ room, onClickClose, onClickBack }: EditRoomInfoProps) =>
}
});
const handleSave = useMutableCallback(async (data) => {
await Promise.all([isDirty && handleUpdateRoomData(data), changeArchiving && handleArchive()].filter(Boolean));
});
const handleSave = useEffectEvent((data) =>
Promise.all([isDirty && handleUpdateRoomData(data), changeArchiving && handleArchive()].filter(Boolean)),
);
const formId = useUniqueId();
const roomNameField = useUniqueId();

@ -87,6 +87,28 @@ test.describe.parallel('administration', () => {
await poAdmin.getRoomRow(targetChannel).click();
await expect(poAdmin.archivedInput).toBeChecked();
});
test.describe.serial('Default rooms', () => {
test('expect target channell to be default', async () => {
await poAdmin.inputSearchRooms.type(targetChannel);
await poAdmin.getRoomRow(targetChannel).click();
await poAdmin.defaultLabel.click();
await poAdmin.btnSave.click();
await poAdmin.getRoomRow(targetChannel).click();
await expect(poAdmin.defaultInput).toBeChecked();
});
test('should mark target default channel as "favorite by default"', async () => {
await poAdmin.inputSearchRooms.type(targetChannel);
await poAdmin.getRoomRow(targetChannel).click();
await poAdmin.favoriteLabel.click();
await poAdmin.btnSave.click();
await poAdmin.getRoomRow(targetChannel).click();
await expect(poAdmin.favoriteInput).toBeChecked();
});
});
});
test.describe('Permissions', () => {

@ -36,6 +36,22 @@ export class Admin {
return this.page.locator('input[name="archived"]');
}
get favoriteLabel(): Locator {
return this.page.locator('label >> text=Favorite');
}
get favoriteInput(): Locator {
return this.page.locator('input[name="favorite"]');
}
get defaultLabel(): Locator {
return this.page.locator('label >> text=Default');
}
get defaultInput(): Locator {
return this.page.locator('input[name="isDefault"]');
}
get inputSearchUsers(): Locator {
return this.page.locator('input[placeholder="Search Users"]');
}

Loading…
Cancel
Save