Skip to content

Commit

Permalink
Merge branch 'develop' into test/decouple-channels
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Feb 5, 2024
2 parents 4a1c1e3 + 4442737 commit 5207959
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 187 deletions.
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
17 changes: 17 additions & 0 deletions apps/meteor/tests/data/teams.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ITeam, TEAM_TYPE } from "@rocket.chat/core-typings"
import { api, request } from "./api-data"

export const createTeam = async (credentials: Record<string, any>, teamName: string, type: TEAM_TYPE): Promise<ITeam> => {
const response = await request.post(api('teams.create')).set(credentials).send({
name: teamName,
type,
});

return response.body.team;
};

export const deleteTeam = async (credentials: Record<string, any>, teamName: string): Promise<void> => {
await request.post(api('teams.delete')).set(credentials).send({
teamName,
});
};
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

0 comments on commit 5207959

Please sign in to comment.