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

Chore: e2e changes tests #27987

Merged
merged 23 commits into from
Feb 11, 2023
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
3 changes: 0 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ jobs:
- name: yarn build
run: yarn build

- name: Unit Test
run: yarn testunit --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Restore build
uses: actions/download-artifact@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
}
],
"typescript.tsdk": "./node_modules/typescript/lib",
"cSpell.words": ["katex", "livechat", "omnichannel", "photoswipe", "tmid"]
"cSpell.words": ["katex", "listbox", "livechat", "omnichannel", "photoswipe", "searchbox", "tmid"]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import { Modal, Field, FieldGroup, ToggleSwitch, TextInput, TextAreaInput, Button, Icon, Box } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React from 'react';

import { useEndpointAction } from '../../hooks/useEndpointAction';
import { useForm } from '../../hooks/useForm';
import { goToRoomById } from '../../lib/utils/goToRoomById';
import RoomAutoComplete from '../RoomAutoComplete';
Expand Down Expand Up @@ -44,23 +44,14 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug

const canCreate = (parentRoom || defaultParentRoom) && name;

const createDiscussion = useEndpointAction('POST', '/v1/rooms.createDiscussion');
const createDiscussion = useEndpoint('POST', '/v1/rooms.createDiscussion');

const create = useMutableCallback(async (): Promise<void> => {
try {
const result = await createDiscussion({
prid: defaultParentRoom || parentRoom,
t_name: name,
users: usernames,
reply: encrypted ? undefined : firstMessage,
...(parentMessageId && { pmid: parentMessageId }),
});

goToRoomById(result.discussion._id);
const createDiscussionMutation = useMutation({
mutationFn: createDiscussion,
onSuccess: ({ discussion }) => {
goToRoomById(discussion._id);
onClose();
} catch (error) {
console.warn(error);
}
},
});

const onChangeUsers = useMutableCallback((value, action) => {
Expand Down Expand Up @@ -140,7 +131,19 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Modal.Footer>
<Modal.FooterControllers>
<Button onClick={onClose}>{t('Cancel')}</Button>
<Button primary disabled={!canCreate} onClick={create}>
<Button
primary
disabled={!canCreate || createDiscussionMutation.isLoading}
onClick={() =>
createDiscussionMutation.mutate({
prid: defaultParentRoom || parentRoom,
t_name: name,
users: usernames,
reply: encrypted ? undefined : firstMessage,
...(parentMessageId && { pmid: parentMessageId }),
})
}
>
{t('Create')}
</Button>
</Modal.FooterControllers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AutoComplete, Option, Box } from '@rocket.chat/fuselage';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement, ComponentProps } from 'react';
import React, { memo, useMemo, useState } from 'react';

import { useEndpointData } from '../../hooks/useEndpointData';
import RoomAvatar from '../avatar/RoomAvatar';
import Avatar from './Avatar';

Expand All @@ -20,14 +21,21 @@ type RoomAutoCompleteProps<T> = Omit<ComponentProps<typeof AutoComplete>, 'value
/* @deprecated */
const RoomAutoComplete = <T,>(props: RoomAutoCompleteProps<T>): ReactElement => {
const [filter, setFilter] = useState('');
const { value: data } = useEndpointData('/v1/rooms.autocomplete.channelAndPrivate', { params: useMemo(() => query(filter), [filter]) });
const autocomplete = useEndpoint('GET', '/v1/rooms.autocomplete.channelAndPrivate');

const result = useQuery(['rooms.autocomplete.channelAndPrivate', filter], () => autocomplete(query(filter)), {
keepPreviousData: true,
});

const options = useMemo(
() =>
data?.items.map(({ name, _id, avatarETag, t }) => ({
value: _id,
label: { name, avatarETag, type: t },
})) || [],
[data],
result.isSuccess
? result.data.items.map(({ name, _id, avatarETag, t }) => ({
value: _id,
label: { name, avatarETag, type: t },
}))
: [],
[result.data?.items, result.isSuccess],
) as unknown as { value: string; label: string }[];

return (
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/client/providers/TooltipProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const TooltipProvider: FC = ({ children }) => {
}
anchor.setAttribute('data-title', title);
anchor.setAttribute('data-tooltip', title);
anchor.removeAttribute('title');
lastAnchor.current = anchor;
setTooltip(<TooltipComponent title={title} anchor={anchor} />);
}, 300);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebar/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const HeaderWithData = (): ReactElement => {
<UserAvatarButton />
<Sidebar.TopBar.Actions>
<Home title={t('Home')} />
<Search title={t('Search')} data-qa='sidebar-search' />
<Search title={t('Search')} />
{user && (
<>
<Directory title={t('Directory')} />
Expand Down
7 changes: 5 additions & 2 deletions apps/meteor/client/sidebar/search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,30 @@ const SearchList = forwardRef(function SearchList({ onClose }: SearchListProps,
top: 0;
`}
ref={ref}
role='search'
>
<Sidebar.TopBar.Section {...({ role: 'search', flexShrink: 0 } as any)} is='form'>
<Sidebar.TopBar.Section {...({ flexShrink: 0 } as any)} is='form'>
<TextInput
aria-owns={listId}
data-qa='sidebar-search-input'
ref={autofocus}
{...filter}
placeholder={placeholder}
role='searchbox'
addon={<Icon name='cross' size='x20' onClick={onClose} />}
/>
</Sidebar.TopBar.Section>
<Box
ref={boxRef}
aria-expanded='true'
role='listbox'
id={listId}
tabIndex={-1}
flexShrink={1}
h='full'
w='full'
data-qa='sidebar-search-result'
aria-live='polite'
aria-atomic='true'
aria-busy={isLoading}
onClick={handleClick}
>
Expand Down
74 changes: 39 additions & 35 deletions apps/meteor/client/startup/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,53 @@ Meteor.startup(() => {

observable = Subscriptions.find().observe({
changed: async (sub: ISubscription) => {
if (!sub.encrypted && !sub.E2EKey) {
e2e.removeInstanceByRoomId(sub.rid);
return;
}

const e2eRoom = await e2e.getInstanceByRoomId(sub.rid);
if (!e2eRoom) {
return;
}

if (sub.E2ESuggestedKey) {
if (await e2eRoom.importGroupKey(sub.E2ESuggestedKey)) {
e2e.acceptSuggestedKey(sub.rid);
} else {
console.warn('Invalid E2ESuggestedKey, rejecting', sub.E2ESuggestedKey);
e2e.rejectSuggestedKey(sub.rid);
Meteor.defer(async () => {
if (!sub.encrypted && !sub.E2EKey) {
e2e.removeInstanceByRoomId(sub.rid);
return;
}
}

sub.encrypted ? e2eRoom.resume() : e2eRoom.pause();
const e2eRoom = await e2e.getInstanceByRoomId(sub.rid);
if (!e2eRoom) {
return;
}

if (sub.E2ESuggestedKey) {
if (await e2eRoom.importGroupKey(sub.E2ESuggestedKey)) {
e2e.acceptSuggestedKey(sub.rid);
} else {
console.warn('Invalid E2ESuggestedKey, rejecting', sub.E2ESuggestedKey);
e2e.rejectSuggestedKey(sub.rid);
}
}

sub.encrypted ? e2eRoom.resume() : e2eRoom.pause();

// Cover private groups and direct messages
if (!e2eRoom.isSupportedRoomType(sub.t)) {
e2eRoom.disable();
return;
}
// Cover private groups and direct messages
if (!e2eRoom.isSupportedRoomType(sub.t)) {
e2eRoom.disable();
return;
}

if (sub.E2EKey && e2eRoom.isWaitingKeys()) {
e2eRoom.keyReceived();
return;
}
if (sub.E2EKey && e2eRoom.isWaitingKeys()) {
e2eRoom.keyReceived();
return;
}

if (!e2eRoom.isReady()) {
return;
}
if (!e2eRoom.isReady()) {
return;
}

e2eRoom.decryptSubscription();
e2eRoom.decryptSubscription();
});
},
added: async (sub: ISubscription) => {
if (!sub.encrypted && !sub.E2EKey) {
return;
}
return e2e.getInstanceByRoomId(sub.rid);
Meteor.defer(async () => {
if (!sub.encrypted && !sub.E2EKey) {
return;
}
return e2e.getInstanceByRoomId(sub.rid);
});
},
removed: (sub: ISubscription) => {
e2e.removeInstanceByRoomId(sub.rid);
Expand Down
Loading