Skip to content

Commit

Permalink
Add file upload/download/cancel test cases for multiple users
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Dec 19, 2024
1 parent a5b758e commit 81420d0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
36 changes: 30 additions & 6 deletions packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,15 @@ export class Channel {
baseElement: WebElement
): Promise<WebElement | undefined> {
try {
const filenameComponentElement = await baseElement.findElement(By.xpath(`//*[@class='FileComponentfilename']`))
const filenameComponentElement = await await this.driver.wait(
baseElement.findElement(By.xpath(`//*[@class='FileComponentfilename']`)),
45_000
)
const parsedPath = path.parse(filename)
// this is split because we print the message as multiple lines and contains doesn't return true when searching the full filename
const filenameElement = await filenameComponentElement.findElement(
By.xpath(`//h5[contains(text(), "${parsedPath.name}")]`)
const filenameElement = await this.driver.wait(
filenameComponentElement.findElement(By.xpath(`//h5[contains(text(), "${parsedPath.name}")]`)),
45_000
)
if ((await filenameElement.getText()) === filename) {
return filenameElement
Expand All @@ -426,7 +430,10 @@ export class Channel {
baseElement: WebElement
): Promise<WebElement | undefined> {
try {
const filenameElement = await baseElement.findElement(By.xpath(`//p[text()='${filename}']`))
const filenameElement = await this.driver.wait(
baseElement.findElement(By.xpath(`//p[text()='${filename}']`)),
45_000
)
return filenameElement
} catch (e) {
if (!e.message.includes('no such element')) {
Expand All @@ -450,7 +457,7 @@ export class Channel {
}

get uploadFileInput() {
return this.driver.wait(until.elementLocated(By.xpath('//*[@data-testid="uploadFileInput"]')))
return this.driver.wait(this.driver.findElement(By.xpath('//*[@data-testid="uploadFileInput"]')))
}

async sendMessage(message: string, username: string): Promise<MessageIds> {
Expand All @@ -471,10 +478,27 @@ export class Channel {
await uploadFileInput.sendKeys(filePath)
const sendMessageInput = await this.messageInput
await sendMessageInput.sendKeys(Key.ENTER)
await sleep(10_000)
await sleep(5_000)
return this.getMessageIdsByFile(filename, fileType, username)
}

async cancelFileDownload(messageIds: MessageIds): Promise<boolean> {
try {
const messageElement = await this.waitForMessageContentById(messageIds.messageId)
const downloadingElement = await this.driver.wait(
messageElement.findElement(By.xpath(`//p[text()='Downloading...']`)),
45_000
)
await downloadingElement.click()
await sleep(10_000)
await this.driver.wait(messageElement.findElement(By.xpath(`//p[text()='Download file']`)), 45_000)
return true
} catch (e) {
logger.error(`Error occurred while canceling download`, e)
return false
}
}

async getMessageIdsByText(message: string, username: string): Promise<MessageIds> {
const messageElement = await this.waitForUserMessageByText(username, message)
if (!messageElement) {
Expand Down
51 changes: 50 additions & 1 deletion packages/e2e-tests/src/tests/multipleClients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
Sidebar,
} from '../selectors'
import { promiseWithRetries, sleep } from '../utils'
import { UserTestData } from '../types'
import { MessageIds, UserTestData } from '../types'
import { createLogger } from '../logger'
import * as path from 'path'
import { UploadedFileType } from '../enums'

const logger = createLogger('multipleClients')

Expand Down Expand Up @@ -467,6 +469,53 @@ describe('Multiple Clients', () => {
})
})

describe('Uploading and downloading files', () => {
let largeFileMessageIds: MessageIds | undefined = undefined

it('Owner uploads an image', async () => {
const filename = 'testImage.gif'
const uploadFilePath = path.resolve('./src/tests/resources/', filename)
await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.IMAGE, users.owner.username)
})

it('Guest sees uploaded image', async () => {
await sleep(10_000)
const filename = 'testImage.gif'
await generalChannelUser1.getMessageIdsByFile(filename, UploadedFileType.IMAGE, users.owner.username)
})

it('Owner uploads a file', async () => {
const filename = 'testFile.pdf'
const uploadFilePath = path.resolve('./src/tests/resources/', filename)
await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, users.owner.username)
})

it('Guest sees uploaded file and it downloads', async () => {
const filename = 'testFile.pdf'
await generalChannelUser1.getMessageIdsByFile(filename, UploadedFileType.FILE, users.owner.username)
})

it('Owner uploads a large file', async () => {
const filename = 'largeTestFile.bin'
const uploadFilePath = path.resolve('./src/tests/resources/', filename)
await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, users.owner.username)
})

it(`Guest sees uploaded large file`, async () => {
const filename = 'largeTestFile.bin'
largeFileMessageIds = await generalChannelUser1.getMessageIdsByFile(
filename,
UploadedFileType.FILE,
users.owner.username
)
})

it(`Guest cancels download of large file`, async () => {
expect(largeFileMessageIds).toBeDefined()
expect(await generalChannelUser1.cancelFileDownload(largeFileMessageIds!)).toBeTruthy()
})
})

describe('Guest Closes App', () => {
it('Owner closes app', async () => {
await users.owner.app.close({ forceSaveState: true })
Expand Down
2 changes: 0 additions & 2 deletions packages/e2e-tests/src/tests/oneClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,12 @@ describe('One Client', () => {
it('Owner uploads an image', async () => {
const filename = 'testImage.gif'
const uploadFilePath = path.resolve('./src/tests/resources/', filename)
logger.info(`Upload image path`, uploadFilePath)
await generalChannel.uploadFile(filename, uploadFilePath, UploadedFileType.IMAGE, ownerUserName)
})

it('Owner uploads a non-image file', async () => {
const filename = 'testFile.pdf'
const uploadFilePath = path.resolve('./src/tests/resources/', filename)
logger.info(`Upload file path`, uploadFilePath)
await generalChannel.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, ownerUserName)
})
})
Expand Down
Binary file not shown.

0 comments on commit 81420d0

Please sign in to comment.