-
Notifications
You must be signed in to change notification settings - Fork 13k
fix: Don't try to create a non-encrypted discussion if the parent room is encrypted #38279
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
41eca65
fix: Don't try to create a non-encrypted discussion if the parent is …
MartinSchoeler cb2a15b
test: add tests
MartinSchoeler 3fd3df5
Merge branch 'develop' into fix/encrypted-discussion
MartinSchoeler 3759ac4
review: update tests & storybook
MartinSchoeler bf104dc
fix: update tests
MartinSchoeler c64e150
chore: tweak
dougfabris 071995a
chore: changeset
MartinSchoeler 4b15b86
Update .changeset/odd-gorillas-obey.md
MartinSchoeler 1c850bb
Merge branch 'develop' into fix/encrypted-discussion
MartinSchoeler bb86c59
Merge branch 'develop' into fix/encrypted-discussion
kodiakhq[bot] 145600e
Merge branch 'develop' into fix/encrypted-discussion
kodiakhq[bot] f1b3cb3
Merge branch 'develop' into fix/encrypted-discussion
kodiakhq[bot] 78242c0
Merge branch 'develop' into fix/encrypted-discussion
kodiakhq[bot] ab17cf4
Merge branch 'develop' into fix/encrypted-discussion
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@rocket.chat/meteor": patch | ||
| --- | ||
|
|
||
| Fixes issue when trying to create an unencrypted discussion when a parent channel is encrypted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
apps/meteor/client/components/CreateDiscussion/CreateDiscussion.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { composeStories } from '@storybook/react'; | ||
| import { render, screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { axe } from 'jest-axe'; | ||
|
|
||
| import CreateDiscussion from './CreateDiscussion'; | ||
| import * as stories from './CreateDiscussion.stories'; | ||
| import { createFakeRoom } from '../../../tests/mocks/data'; | ||
|
|
||
| jest.mock('../../lib/utils/goToRoomById', () => ({ | ||
| goToRoomById: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../lib/rooms/roomCoordinator', () => ({ | ||
| roomCoordinator: { | ||
| getRoomDirectives: () => ({ | ||
| getRoomName: () => 'General', | ||
| }), | ||
| }, | ||
| })); | ||
|
|
||
| const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]); | ||
|
|
||
| const room1 = createFakeRoom({ encrypted: true, fname: 'Encrypted Room 1' }); | ||
| const room2 = createFakeRoom({ encrypted: false, fname: 'Unencrypted Room 2' }); | ||
|
|
||
| const appRoot = mockAppRoot() | ||
| .withEndpoint('POST', '/v1/rooms.createDiscussion', () => ({ | ||
| success: true, | ||
| discussion: { | ||
| ...createFakeRoom({ | ||
| _id: 'discussion-id', | ||
| t: 'p' as const, | ||
| name: 'discussion-name', | ||
| fname: 'Discussion Name', | ||
| prid: 'parent-room-id', | ||
| }), | ||
| rid: 'discussion-id', | ||
| } as any, | ||
| })) | ||
| .withEndpoint( | ||
| 'GET', | ||
| '/v1/rooms.autocomplete.channelAndPrivate', | ||
| () => | ||
| ({ | ||
| items: [room1, room2], | ||
| }) as any, | ||
| ) | ||
| .withTranslations('en', 'core', { | ||
| Encrypted: 'Encrypted', | ||
| Discussion_first_message_title: 'Message', | ||
| Discussion_target_channel: 'Parent channel or team', | ||
| }) | ||
| .build(); | ||
|
|
||
| describe('CreateDiscussion', () => { | ||
| test.each(testCases)(`renders %s without crashing`, async (_storyname, Story) => { | ||
| const { baseElement } = render(<Story />, { wrapper: appRoot }); | ||
| expect(baseElement).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test.each(testCases)('%s should have no a11y violations', async (_storyname, Story) => { | ||
| const { container } = render(<Story />, { wrapper: appRoot }); | ||
|
|
||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); | ||
|
|
||
| describe('Encrypted parent room behavior', () => { | ||
| it('should disable encrypted toggle and first message field when parent room is encrypted', () => { | ||
| render(<CreateDiscussion onClose={jest.fn()} encryptedParentRoom={true} />, { wrapper: appRoot }); | ||
|
|
||
| const encryptedToggle = screen.getByRole('checkbox', { name: 'Encrypted' }); | ||
| expect(encryptedToggle).toBeDisabled(); | ||
|
|
||
| const firstMessageField = screen.getByLabelText('Message'); | ||
| expect(firstMessageField).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should disable encrypted toggle and first message field when an encrypted parent room is selected', async () => { | ||
| render(<CreateDiscussion onClose={jest.fn()} />, { wrapper: appRoot }); | ||
|
|
||
| const parentRoomSelect = screen.getByRole('textbox', { name: 'Parent channel or team' }); | ||
|
|
||
| await userEvent.click(parentRoomSelect); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Encrypted Room 1')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Encrypted Room 1')); | ||
|
|
||
| const encryptedToggle = screen.getByRole('checkbox', { name: 'Encrypted' }); | ||
| expect(encryptedToggle).toBeDisabled(); | ||
|
|
||
| const firstMessageField = screen.getByLabelText('Message'); | ||
| expect(firstMessageField).toBeDisabled(); | ||
| }); | ||
| }); | ||
| }); |
13 changes: 13 additions & 0 deletions
13
apps/meteor/client/components/CreateDiscussion/CreateDiscussion.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { Meta, StoryFn } from '@storybook/react'; | ||
|
|
||
| import CreateDiscussion from './CreateDiscussion'; | ||
|
|
||
| export default { | ||
| component: CreateDiscussion, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| actions: { argTypesRegex: '^on.*' }, | ||
| }, | ||
| } satisfies Meta<typeof CreateDiscussion>; | ||
|
|
||
| export const Default: StoryFn<typeof CreateDiscussion> = (args) => <CreateDiscussion {...args} />; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.