Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Favoriting room through rooms page #31554

Merged
merged 13 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-cows-compete.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 6 additions & 5 deletions apps/meteor/client/views/admin/rooms/EditRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions apps/meteor/tests/e2e/administration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
16 changes: 16 additions & 0 deletions apps/meteor/tests/e2e/page-objects/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]');
}
Expand Down
Loading