Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(tests): Adds filesharing tests.
damencho6564ba52a2a4
diff --git a/react/features/conference/components/web/Conference.tsx b/react/features/conference/components/web/Conference.tsxindex b81adebdbf..7fe2683c4f 100644--- a/react/features/conference/components/web/Conference.tsx+++ b/react/features/conference/components/web/Conference.tsx@@ -529,6 +529,7 @@ export default reactReduxConnect(_mapStateToProps)(translate(props => {return (<div+ data-testid = 'conference-drag-zone'onDragEnter = { handleDragEnter }onDragLeave = { handleDragLeave }onDragOver = { handleDragOver }diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.tsindex af2a856b6b..61eb888b7a 100644--- a/tests/helpers/Participant.ts+++ b/tests/helpers/Participant.ts@@ -8,6 +8,7 @@ import { IConfig } from '../../react/features/base/config/configType';import { urlObjectToString } from '../../react/features/base/util/uri';import BreakoutRooms from '../pageobjects/BreakoutRooms';import ChatPanel from '../pageobjects/ChatPanel';+import FileSharingPanel from '../pageobjects/FileSharingPanel';import Filmstrip from '../pageobjects/Filmstrip';import IframeAPI from '../pageobjects/IframeAPI';import InviteDialog from '../pageobjects/InviteDialog';@@ -534,6 +535,13 @@ export class Participant {return new ChatPanel(this);}+ /**+ * Returns the file sharing panel for this participant.+ */+ getFileSharingPanel(): FileSharingPanel {+ return new FileSharingPanel(this);+ }+/*** Returns the BreakoutRooms for this participant.*diff --git a/tests/helpers/expectations.ts b/tests/helpers/expectations.tsindex a382da7e02..08bbeb03be 100644--- a/tests/helpers/expectations.ts+++ b/tests/helpers/expectations.ts@@ -22,6 +22,7 @@ const defaultExpectations = {enabled: true},jaas: {+ fileSharingEnabled: true,liveStreamingEnabled: true,recordingEnabled: true,transcriptionEnabled: true,diff --git a/tests/helpers/token.ts b/tests/helpers/token.tsindex 6dab5ebc06..18bb0a0959 100644--- a/tests/helpers/token.ts+++ b/tests/helpers/token.ts@@ -10,6 +10,11 @@ export type ITokenOptions = {* The duration for which the token is valid, e.g. "1h" for one hour.*/exp?: string;+ /**+ * Additional JWT features to include (merged with the defaults).+ * Keys are feature names (e.g. 'file-upload'), values are boolean or string.+ */+ features?: Record<string, boolean | string>;/*** The key ID to use for the token.* If not provided, the kid configured with environment variables will be used (see env.example).@@ -72,7 +77,8 @@ export function generatePayload(options: ITokenOptions): any {'transcription': 'true','recording': 'true','sip-outbound-call': true,- 'livestreaming': true+ 'livestreaming': true,+ ...options.features},},'room': options.room || '*'diff --git a/tests/pageobjects/FileSharingPanel.ts b/tests/pageobjects/FileSharingPanel.tsnew file mode 100644index 0000000000..23ddac1906--- /dev/null+++ b/tests/pageobjects/FileSharingPanel.ts@@ -0,0 +1,172 @@+import BasePageObject from './BasePageObject';++const FILE_SHARING_TAB_ID = 'file_sharing-tab';+const FILE_SHARING_PANEL_ID = 'file_sharing-tab-panel';+const UPLOAD_BUTTON_LABEL = 'Share file';+const DOWNLOAD_BUTTON_LABEL = 'Download';+const REMOVE_BUTTON_LABEL = 'Remove';++/**+ * Page object for the file sharing panel.+ */+export default class FileSharingPanel extends BasePageObject {+ /**+ * Opens the chat sidebar and navigates to the file sharing tab.+ */+ async open(): Promise<void> {+ if (!await this.participant.driver.$('#sideToolbarContainer').isExisting()) {+ await this.participant.getToolbar().clickChatButton();+ }+ await this.participant.driver.$(`#${FILE_SHARING_TAB_ID}`).click();+ }++ /**+ * Returns whether the file sharing panel is the currently active tab.+ */+ async isActive(): Promise<boolean> {+ return this.participant.execute(() => {+ // @ts-ignore+ const state = APP?.store?.getState?.();++ return state?.['features/chat']?.focusedTab === 'file_sharing-tab';+ });+ }++ /**+ * Returns whether the upload button is enabled (not disabled).+ */+ async isUploadButtonEnabled(): Promise<boolean> {+ const btn = this.participant.driver.$(`[aria-label="${UPLOAD_BUTTON_LABEL}"]`);++ return !await btn.getAttribute('disabled');+ }++ /**+ * Uploads a file via the hidden file input.+ *+ * @param {string} localFilePath - Local path to the file to upload.+ */+ async uploadFile(localFilePath: string): Promise<void> {+ const remotePath = await this.participant.driver.uploadFile(localFilePath);+ const input = this.participant.driver.$(`#${FILE_SHARING_PANEL_ID} input[type="file"]`);++ await input.addValue(remotePath);+ }++ /**+ * Waits until a file with the given name appears in the file list.+ *+ * @param {string} fileName - The file name to wait for.+ * @param {number} timeout - Timeout in milliseconds.+ */+ async waitForFile(fileName: string, timeout = 15_000): Promise<void> {+ await this.participant.driver.$(`#${FILE_SHARING_PANEL_ID} [title="${fileName}"]`)+ .waitForExist({ timeout, timeoutMsg: `File "${fileName}" did not appear within ${timeout}ms` });+ }++ /**+ * Waits until a file with the given name disappears from the file list.+ *+ * @param {string} fileName - The file name to wait for.+ * @param {number} timeout - Timeout in milliseconds.+ */+ async waitForFileGone(fileName: string, timeout = 15_000): Promise<void> {+ await this.participant.driver.$(`#${FILE_SHARING_PANEL_ID} [title="${fileName}"]`)+ .waitForExist({ timeout, reverse: true, timeoutMsg: `File "${fileName}" still present after ${timeout}ms` });+ }++ /**+ * Returns whether a file with the given name exists in the file list.+ *+ * @param {string} fileName - The file name to check.+ */+ async hasFile(fileName: string): Promise<boolean> {+ return this.participant.driver.$(`#${FILE_SHARING_PANEL_ID} [title="${fileName}"]`).isExisting();+ }++ /**+ * Clicks the download button for the given file. Hovers over the file item first to make action buttons visible.+ *+ * @param {string} fileName - The file name to download.+ */+ async downloadFile(fileName: string): Promise<void> {+ await this.hoverOverFileItem(fileName);+ await this.participant.driver+ .$(`button[aria-label="${DOWNLOAD_BUTTON_LABEL} ${fileName}"]`)+ .click();+ }++ /**+ * Clicks the remove button for the given file. Hovers over the file item first to make action buttons visible.+ *+ * @param {string} fileName - The file name to remove.+ */+ async removeFile(fileName: string): Promise<void> {+ await this.hoverOverFileItem(fileName);+ await this.participant.driver+ .$(`button[aria-label="${REMOVE_BUTTON_LABEL} ${fileName}"]`)+ .click();+ }++ /**+ * Returns whether the remove button exists in the DOM for the given file.+ * The remove button is only rendered when the participant has the 'file-upload' JWT feature.+ *+ * @param {string} fileName - The file name.+ */+ canRemoveFile(fileName: string) {+ return this.participant.driver+ .$(`button[aria-label="${REMOVE_BUTTON_LABEL} ${fileName}"]`)+ .isExisting();+ }++ /**+ * Returns whether the download button exists in the DOM for the given file.+ *+ * @param {string} fileName - The file name.+ */+ canDownloadFile(fileName: string) {+ return this.participant.driver+ .$(`button[aria-label="${DOWNLOAD_BUTTON_LABEL} ${fileName}"]`)+ .isExisting();+ }++ /**+ * Simulates dragging a file into the conference area and dispatches drag events.+ * A dragenter event sets the React isDragging state, then after a short delay a+ * dragover event triggers the file sharing tab to open.+ */+ async simulateDragIntoConference(): Promise<void> {+ await this.participant.driver.executeAsync((done: () => void) => {+ const el = document.querySelector('[data-testid="conference-drag-zone"]') ?? document.body;++ el.dispatchEvent(new DragEvent('dragenter', {+ bubbles: true,+ cancelable: true+ }));+ setTimeout(() => {+ el.dispatchEvent(new DragEvent('dragover', {+ bubbles: true,+ cancelable: true+ }));+ done();+ }, 200);+ });+ }++ /**+ * Returns whether the chat sidebar is currently open.+ */+ isChatOpen() {+ return this.participant.driver.$('#sideToolbarContainer').isExisting();+ }++ /**+ * Hovers over the file item element to make its action buttons visible.+ *+ * @param {string} fileName - The file name whose item should be hovered.+ */+ private async hoverOverFileItem(fileName: string): Promise<void> {+ await this.participant.driver.$(`#${FILE_SHARING_PANEL_ID} [title="${fileName}"]`).moveTo();+ }+}diff --git a/tests/resources/test-upload.txt b/tests/resources/test-upload.txtnew file mode 100644index 0000000000..1ad6858b91--- /dev/null+++ b/tests/resources/test-upload.txt@@ -0,0 +1 @@+This is a test file for file sharing upload tests.\ No newline at end of filediff --git a/tests/specs/jaas/fileSharing.spec.ts b/tests/specs/jaas/fileSharing.spec.tsnew file mode 100644index 0000000000..9ef2faeff3--- /dev/null+++ b/tests/specs/jaas/fileSharing.spec.ts@@ -0,0 +1,169 @@+import { expect } from '@wdio/globals';++import type { Participant } from '../../helpers/Participant';+import { setTestProperties } from '../../helpers/TestProperties';+import { expectations } from '../../helpers/expectations';+import { joinJaasMuc, generateJaasToken as t } from '../../helpers/jaas';++setTestProperties(__filename, {+ useJaas: true,+ usesBrowsers: [ 'p1', 'p2' ]+});++const TEST_FILE_PATH = 'tests/resources/test-upload.txt';+const TEST_FILE_NAME = 'test-upload.txt';++describe('File sharing', () => {+ let p1: Participant, p2: Participant;+ let fileSharingEnabled: boolean;++ it('setup', async () => {+ const room = ctx.roomName;++ p1 = await joinJaasMuc({+ name: 'p1',+ token: t({ room, features: { 'file-upload': 'true' } })+ });++ fileSharingEnabled = await p1.execute(+ () => Boolean((window as any).config?.fileSharing?.enabled && (window as any).config?.fileSharing?.apiUrl)+ );++ expect(fileSharingEnabled).toBe(expectations.jaas.fileSharingEnabled);+ });++ it('upload button enabled with file-upload feature', async () => {+ if (!fileSharingEnabled) {+ return;+ }+ const panel = p1.getFileSharingPanel();++ await panel.open();++ expect(await panel.isUploadButtonEnabled()).toBe(true);+ });++ it('upload button disabled without file-upload feature', async () => {+ if (!fileSharingEnabled) {+ return;+ }++ p2 = await joinJaasMuc({ name: 'p2', token: t({ room: ctx.roomName }) });++ const panel = p2.getFileSharingPanel();++ await panel.open();++ expect(await panel.isUploadButtonEnabled()).toBe(false);+ });++ it('user with file-upload can delete files uploaded by another participant', async () => {+ if (!fileSharingEnabled) {+ return;+ }++ // p1 (with file-upload) uploads a file+ const p1Panel = p1.getFileSharingPanel();++ await p1Panel.open();+ await p1Panel.uploadFile(TEST_FILE_PATH);+ await p1Panel.waitForFile(TEST_FILE_NAME);++ // p2 (joined earlier without file-upload) rejoins with file-upload to test deletion of p1's file+ p2 = await joinJaasMuc({+ name: 'p2',+ token: t({ room: ctx.roomName, features: { 'file-upload': 'true' } })+ });++ const p2Panel = p2.getFileSharingPanel();++ await p2Panel.open();+ await p2Panel.waitForFile(TEST_FILE_NAME);++ // p2 should be able to see and use the remove button for p1's file+ expect(await p2Panel.canRemoveFile(TEST_FILE_NAME)).toBe(true);++ await p2Panel.removeFile(TEST_FILE_NAME);++ await p1Panel.waitForFileGone(TEST_FILE_NAME);+ });++ it('user without file-upload can download but not delete files', async () => {+ if (!fileSharingEnabled) {+ return;+ }++ // p1 (with file-upload) uploads a fresh file+ const p1Panel = p1.getFileSharingPanel();++ await p1Panel.open();+ await p1Panel.uploadFile(TEST_FILE_PATH);+ await p1Panel.waitForFile(TEST_FILE_NAME);++ // p2 rejoins without file-upload+ p2 = await joinJaasMuc({ name: 'p2', token: t({ room: ctx.roomName }) });++ const p2Panel = p2.getFileSharingPanel();++ await p2Panel.open();+ await p2Panel.waitForFile(TEST_FILE_NAME);++ // Download button should be present, remove button should not+ expect(await p2Panel.canDownloadFile(TEST_FILE_NAME)).toBe(true);+ expect(await p2Panel.canRemoveFile(TEST_FILE_NAME)).toBe(false);+ });++ it('dragging into conference opens file sharing tab', async () => {+ if (!fileSharingEnabled) {+ return;+ }++ // p1 already has file-upload feature+ const panel = p1.getFileSharingPanel();++ // Ensure chat is closed before starting+ if (await panel.isChatOpen()) {+ await p1.getToolbar().clickCloseChatButton();+ }++ await panel.simulateDragIntoConference();++ await p1.driver.waitUntil(+ () => panel.isChatOpen(),+ { timeout: 3000, timeoutMsg: 'Chat did not open after drag' }+ );++ expect(await panel.isActive()).toBe(true);+ });++ it('dragging on pre-join screen does not open file sharing', async () => {+ if (!fileSharingEnabled) {+ return;+ }++ // Join with iFrame API, file-upload feature, and pre-join screen enabled — but do NOT click join+ p1 = await joinJaasMuc(+ {+ name: 'p1',+ iFrameApi: true,+ token: t({ room: ctx.roomName, features: { 'file-upload': 'true' } })+ },+ {+ configOverwrite: { prejoinConfig: { enabled: true } },+ skipPrejoinButtonClick: true,+ skipWaitToJoin: true+ }+ );++ // Wait for pre-join screen to appear+ await p1.getPreJoinScreen().waitForLoading();++ // Simulate drag while on pre-join screen+ const panel = p1.getFileSharingPanel();++ await panel.simulateDragIntoConference();++ // Chat/file sharing should NOT have opened+ expect(await panel.isChatOpen()).toBe(false);+ });+});diff --git a/tests/wdio.dev.conf.ts b/tests/wdio.dev.conf.tsindex b23d7b52dc..5fe28f65ed 100644--- a/tests/wdio.dev.conf.ts+++ b/tests/wdio.dev.conf.ts@@ -7,5 +7,5 @@ import { merge } from 'lodash-es';import { config as defaultConfig } from './wdio.conf.ts';export const config = merge(defaultConfig, {- baseUrl: 'https://127.0.0.1:8080/torture'+ baseUrl: 'https://localhost:8080/torture'}, { clone: false });