Skip to content

Commit

Permalink
Merge branch 'develop' into channel-edit-floky
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Apr 3, 2024
2 parents 150744b + 1626945 commit 232cc62
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/pink-ants-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
---

Fixed a UI issue that allowed a user to "mark" a room as favorite even when a room was not default. The Back-End was correctly ignoring the `favorite` property from being updated when the room was not default, but the UI still allowed users to try.
As UI allowed but changes were not saved, this gave the impression that the function was not working.
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/rooms/EditRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const EditRoom = ({ room, onChange, onDelete }: EditRoomProps) => {
canViewReactWhenReadOnly,
} = useEditAdminRoomPermissions(room);

const { roomType, readOnly, archived } = watch();
const { roomType, readOnly, archived, isDefault } = watch();

const changeArchiving = archived !== !!room.archived;

Expand Down Expand Up @@ -324,7 +324,7 @@ const EditRoom = ({ room, onChange, onDelete }: EditRoomProps) => {
name='favorite'
control={control}
render={({ field: { value, ...field } }) => (
<ToggleSwitch id={favoriteField} {...field} disabled={isDeleting} checked={value} />
<ToggleSwitch id={favoriteField} {...field} disabled={isDeleting || !isDefault} checked={value} />
)}
/>
</FieldRow>
Expand Down
15 changes: 15 additions & 0 deletions apps/meteor/tests/e2e/administration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ test.describe.parallel('administration', () => {
await poAdmin.getRoomRow(targetChannel).click();
await expect(poAdmin.favoriteInput).toBeChecked();
});

test('should see favorite switch disabled when default is not true', async () => {
await poAdmin.inputSearchRooms.type(targetChannel);
await poAdmin.getRoomRow(targetChannel).click();
await poAdmin.defaultLabel.click();

await expect(poAdmin.favoriteInput).toBeDisabled();
});

test('should see favorite switch enabled when default is true', async () => {
await poAdmin.inputSearchRooms.type(targetChannel);
await poAdmin.getRoomRow(targetChannel).click();

await expect(poAdmin.favoriteInput).toBeEnabled();
});
});
});

Expand Down
61 changes: 60 additions & 1 deletion apps/meteor/tests/end-to-end/api/09-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ describe('[Rooms]', function () {
});
});

describe('/rooms.saveRoomSettings', () => {
describe('rooms.saveRoomSettings', () => {
let testChannel;
const randomString = `randomString${Date.now()}`;
let discussion;
Expand Down Expand Up @@ -1847,5 +1847,64 @@ describe('[Rooms]', function () {
expect(res.body.room).to.have.property('fname', newDiscussionName);
});
});

it('should mark a room as favorite', async () => {
await request
.post(api('rooms.saveRoomSettings'))
.set(credentials)
.send({
rid: testChannel._id,
favorite: {
favorite: true,
defaultValue: true,
},
})
.expect('Content-Type', 'application/json')
.expect(200);

await request
.get(api('rooms.info'))
.set(credentials)
.query({
roomId: testChannel._id,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('room').and.to.be.an('object');

expect(res.body.room).to.have.property('_id', testChannel._id);
expect(res.body.room).to.have.property('favorite', true);
});
});
it('should not mark a room as favorite when room is not a default room', async () => {
await request
.post(api('rooms.saveRoomSettings'))
.set(credentials)
.send({
rid: testChannel._id,
favorite: {
favorite: true,
defaultValue: false,
},
})
.expect('Content-Type', 'application/json')
.expect(200);

await request
.get(api('rooms.info'))
.set(credentials)
.query({
roomId: testChannel._id,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('room').and.to.be.an('object');

expect(res.body.room).to.have.property('_id', testChannel._id);
expect(res.body.room).to.not.have.property('favorite');
});
});
});
});

0 comments on commit 232cc62

Please sign in to comment.