Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into monorepo-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 11, 2022
2 parents fc334f8 + fbd8337 commit b722d1a
Show file tree
Hide file tree
Showing 46 changed files with 4,324 additions and 389 deletions.
58 changes: 54 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ jobs:
- name: Unit Test
run: yarn testunit

- name: Install Playwright
run: npx playwright install --with-deps

- name: E2E Test API
env:
TEST_MODE: "true"
Expand All @@ -251,7 +254,7 @@ jobs:
Xvfb -screen 0 1024x768x24 :99 &
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --test=testapi && s=0 && break || s=$? && sleep 1; done; (exit $s)
- name: E2E Test UI
- name: E2E Test UI (Legacy - Cypress)
env:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/rocketchat
Expand All @@ -262,6 +265,24 @@ jobs:
Xvfb -screen 0 1024x768x24 :99 &
for i in $(seq 1 2); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --test=testui && s=0 && break || s=$? && ([ ! -w tests/cypress/screenshots ] || mv tests/cypress/screenshots tests/cypress/screenshots-$i) && ([ ! -w tests/cypress/videos ] || mv tests/cypress/videos tests/cypress/videos-$i) && sleep 1; done; (exit $s)
- name: E2E Test UI
env:
TEST_MODE: 'true'
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
run: |
cd ./apps/meteor
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc
Xvfb -screen 0 1024x768x24 :99 &
docker exec mongo mongo rocketchat --eval 'db.dropDatabase()' && npm run testci -- --test=test:playwright
- name: Store playwright test trace
uses: actions/upload-artifact@v2
if: failure()
with:
name: playwright-test-trace
path: ./apps/meteor/tests/e2e/test-failures*

- name: Store cypress test screenshots
uses: actions/upload-artifact@v2
if: failure()
Expand Down Expand Up @@ -363,7 +384,7 @@ jobs:
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --enterprise --test=testapi && s=0 && break || s=$? && sleep 1; done; (exit $s)
- name: E2E Test UI
- name: E2E Test UI (Legacy - Cypress)
env:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/rocketchat
Expand All @@ -382,19 +403,48 @@ jobs:
for i in $(seq 1 2); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci -- --enterprise --test=testui && s=0 && break || s=$? && ([ ! -w tests/cypress/screenshots ] || mv tests/cypress/screenshots tests/cypress/screenshots-$i) && ([ ! -w tests/cypress/videos ] || mv tests/cypress/videos tests/cypress/videos-$i) && sleep 1; done; (exit $s)
- name: Install Playwright
run: npx playwright install --with-deps

- name: E2E Test UI
env:
TEST_MODE: 'true'
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
ENTERPRISE_LICENSE: ${{ secrets.ENTERPRISE_LICENSE }}
TRANSPORTER: nats://localhost:4222
CYPRESS_BASE_URL: http://localhost:4000
CYPRESS_TEST_API_URL: http://localhost:4000
OVERWRITE_SETTING_Site_Url: http://localhost:4000
SKIP_PROCESS_EVENT_REGISTRATION: "true"
run: |
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc
Xvfb -screen 0 1024x768x24 :99 &
cd ./apps/meteor
docker exec mongo mongo rocketchat --eval 'db.dropDatabase()' && npm run testci -- --enterprise --test=test:playwright:ee
- name: Store playwright test trace
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-playwright-test-trace
path: ./apps/meteor/tests/e2e/test-failures*

- name: Store cypress test screenshots
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-cypress-test-screenshots
path: apps/meteor/tests/cypress/screenshots*
path: ./apps/meteor/tests/cypress/screenshots*

- name: Store cypress test videos
uses: actions/upload-artifact@v2
if: failure()
with:
name: ee-cypress-test-videos
path: apps/meteor/tests/cypress/videos*
path: ./apps/meteor/tests/cypress/videos*
# notification:
# runs-on: ubuntu-20.04
# needs: test
Expand Down
31 changes: 0 additions & 31 deletions apps/meteor/app/livechat/imports/server/rest/messages.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../imports/server/rest/rooms.js';
import '../imports/server/rest/appearance.js';
import '../imports/server/rest/triggers.js';
import '../imports/server/rest/integrations.js';
import '../imports/server/rest/messages.js';
import '../imports/server/rest/visitors.js';
import '../imports/server/rest/visitors.ts';
import '../imports/server/rest/dashboards.js';
Expand Down
20 changes: 0 additions & 20 deletions apps/meteor/app/livechat/server/api/lib/messages.js

This file was deleted.

2 changes: 0 additions & 2 deletions apps/meteor/app/models/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import LivechatDepartmentAgents from './models/LivechatDepartmentAgents';
import LivechatRooms from './models/LivechatRooms';
import LivechatVisitors from './models/LivechatVisitors';
import LivechatInquiry from './models/LivechatInquiry';
import LivechatExternalMessage from './models/LivechatExternalMessages';
import OmnichannelQueue from './models/OmnichannelQueue';
import ImportData from './models/ImportData';

Expand All @@ -35,7 +34,6 @@ export {
LivechatDepartmentAgents,
LivechatRooms,
LivechatVisitors,
LivechatExternalMessage,
LivechatInquiry,
OmnichannelQueue,
ImportData,
Expand Down
18 changes: 0 additions & 18 deletions apps/meteor/app/models/server/models/LivechatExternalMessages.js

This file was deleted.

9 changes: 0 additions & 9 deletions apps/meteor/app/models/server/raw/LivechatExternalMessages.js

This file was deleted.

3 changes: 0 additions & 3 deletions apps/meteor/app/models/server/raw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { LivechatBusinessHoursRaw } from './LivechatBusinessHours';
import { LivechatCustomFieldRaw } from './LivechatCustomField';
import { LivechatDepartmentAgentsRaw } from './LivechatDepartmentAgents';
import { LivechatDepartmentRaw } from './LivechatDepartment';
import { LivechatExternalMessageRaw } from './LivechatExternalMessages';
import { LivechatInquiryRaw } from './LivechatInquiry';
import { LivechatRoomsRaw } from './LivechatRooms';
import { LivechatTriggerRaw } from './LivechatTrigger';
Expand Down Expand Up @@ -58,7 +57,6 @@ import LivechatBusinessHoursModel from '../models/LivechatBusinessHours';
import LivechatCustomFieldModel from '../models/LivechatCustomField';
import LivechatDepartmentAgentsModel from '../models/LivechatDepartmentAgents';
import LivechatDepartmentModel from '../models/LivechatDepartment';
import LivechatExternalMessagesModel from '../models/LivechatExternalMessages';
import LivechatInquiryModel from '../models/LivechatInquiry';
import LivechatRoomsModel from '../models/LivechatRooms';
import LivechatVisitorsModel from '../models/LivechatVisitors';
Expand All @@ -85,7 +83,6 @@ export const LivechatDepartmentAgents = new LivechatDepartmentAgentsRaw(
);
export const LivechatRooms = new LivechatRoomsRaw(LivechatRoomsModel.model.rawCollection(), trashCollection);
export const Messages = new MessagesRaw(MessagesModel.model.rawCollection(), trashCollection);
export const LivechatExternalMessage = new LivechatExternalMessageRaw(LivechatExternalMessagesModel.model.rawCollection(), trashCollection);
export const LivechatVisitors = new LivechatVisitorsRaw(LivechatVisitorsModel.model.rawCollection(), trashCollection);
export const LivechatInquiry = new LivechatInquiryRaw(LivechatInquiryModel.model.rawCollection(), trashCollection);
export const LivechatBusinessHours = new LivechatBusinessHoursRaw(LivechatBusinessHoursModel.model.rawCollection(), trashCollection);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/contexts/ServerContext/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type ServerMethods = {
'getUsersOfRoom': (...args: any[]) => any;
'hideRoom': (...args: any[]) => any;
'ignoreUser': (...args: any[]) => any;
'insertOrUpdateSound': (...args: any[]) => any;
'insertOrUpdateSound': (args: { previousName?: string; name?: string; _id?: string; extension: string }) => string;
'insertOrUpdateUserStatus': (...args: any[]) => any;
'instances/get': (...args: any[]) => any;
'jitsi:generateAccessToken': (...args: any[]) => any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, TextInput, Box, Icon, Margins, Button, ButtonGroup } from '@rocket.chat/fuselage';
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, ReactElement, FormEvent } from 'react';

import VerticalBar from '../../../components/VerticalBar';
import { useMethod } from '../../../contexts/ServerContext';
Expand All @@ -8,12 +8,18 @@ import { useTranslation } from '../../../contexts/TranslationContext';
import { useFileInput } from '../../../hooks/useFileInput';
import { validate, createSoundData } from './lib';

function AddCustomSound({ goToNew, close, onChange, ...props }) {
type AddCustomSoundProps = {
goToNew: (where: string) => () => void;
close: () => void;
onChange: () => void;
};

const AddCustomSound = function AddCustomSound({ goToNew, close, onChange, ...props }: AddCustomSoundProps): ReactElement {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

const [name, setName] = useState('');
const [sound, setSound] = useState();
const [sound, setSound] = useState<{ name: string }>();

const uploadCustomSound = useMethod('uploadCustomSound');

Expand All @@ -26,54 +32,56 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
const [clickUpload] = useFileInput(handleChangeFile, 'audio/mp3');

const saveAction = useCallback(
async (name, soundFile) => {
const soundData = createSoundData(soundFile, name);
const validation = validate(soundData, soundFile);
if (validation.length === 0) {
let soundId;
try {
soundId = await insertOrUpdateSound(soundData);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
async (name, soundFile): Promise<string | undefined> => {
const soundData = createSoundData(soundFile, name) as { extension: string; _id?: string; name: string; newFile?: true };
const validation = validate(soundData, soundFile) as Array<Parameters<typeof t>[0]>;

validation.forEach((error) => {
throw new Error(t('error-the-field-is-required', { field: t(error) }));
});

try {
const soundId = await insertOrUpdateSound(soundData);

soundData._id = soundId;
soundData.random = Math.round(Math.random() * 1000);

if (soundId) {
dispatchToastMessage({ type: 'success', message: t('Uploading_file') });

const reader = new FileReader();
reader.readAsBinaryString(soundFile);
reader.onloadend = () => {
try {
uploadCustomSound(reader.result, soundFile.type, soundData);
dispatchToastMessage({ type: 'success', message: t('File_uploaded') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
};
if (!soundId) {
return undefined;
}

dispatchToastMessage({ type: 'success', message: t('Uploading_file') });

const reader = new FileReader();
reader.readAsBinaryString(soundFile);
reader.onloadend = (): void => {
try {
uploadCustomSound(reader.result, soundFile.type, {
...soundData,
_id: soundId,
random: Math.round(Math.random() * 1000),
});
dispatchToastMessage({ type: 'success', message: t('File_uploaded') });
} catch (error) {
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
};
return soundId;
} catch (error) {
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
validation.forEach((error) => {
throw new Error({
type: 'error',
message: t('error-the-field-is-required', { field: t(error) }),
});
});
},
[dispatchToastMessage, insertOrUpdateSound, t, uploadCustomSound],
);

const handleSave = useCallback(async () => {
try {
const result = await saveAction(name, sound);
if (!result) {
throw new Error('error-something-went-wrong');
}
goToNew(result);
dispatchToastMessage({ type: 'success', message: t('Custom_Sound_Saved_Successfully') });
goToNew(result)();
onChange();
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
(typeof error === 'string' || error instanceof Error) && dispatchToastMessage({ type: 'error', message: error });
}
}, [dispatchToastMessage, goToNew, name, onChange, saveAction, sound, t]);

Expand All @@ -82,7 +90,11 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
<Field>
<Field.Label>{t('Name')}</Field.Label>
<Field.Row>
<TextInput value={name} onChange={(e) => setName(e.currentTarget.value)} placeholder={t('Name')} />
<TextInput
value={name}
onChange={(e: FormEvent<HTMLInputElement>): void => setName(e.currentTarget.value)}
placeholder={t('Name')}
/>
</Field.Row>
</Field>
<Field>
Expand All @@ -92,7 +104,7 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
<Button square onClick={clickUpload}>
<Icon name='upload' size='x20' />
</Button>
{(sound && sound.name) || 'none'}
{sound?.name || t('None')}
</Margins>
</Box>
</Field>
Expand All @@ -110,6 +122,6 @@ function AddCustomSound({ goToNew, close, onChange, ...props }) {
</Field>
</VerticalBar.ScrollableContent>
);
}
};

export default AddCustomSound;
Loading

0 comments on commit b722d1a

Please sign in to comment.