Skip to content

Commit

Permalink
chore: enhance waiting for channels in multiple users e2e test; Make …
Browse files Browse the repository at this point in the history
…username bold in system message about deleted messages
  • Loading branch information
EmiM committed Apr 22, 2024
1 parent 7468db5 commit 6655c22
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PublicChannelStorage } from '@quiet/types'
export const createdChannelMessage = (channelName: string): string => `Created #${channelName}`

export const generalChannelDeletionMessage = (username: string): string =>
`@${username} deleted all messages in #general`
`**@${username}** deleted all messages in #general`

export const userJoinedMessage = (username: string): string =>
`**@${username}** has joined and will be registered soon. 🎉 [Learn more](https://github.com/TryQuiet/quiet/wiki/Quiet-FAQ#how-does-username-registration-work)`
Expand Down
27 changes: 27 additions & 0 deletions packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,33 @@ export class Sidebar {
return channels
}

/**
* Get names of all channels in the sidebar
*/
async getChannelsNames() {
const elements = await this.getChannelList()
return Promise.all(
elements.map(async element => {
const fullName = await element.getText()
return fullName.split(' ')[1]
})
)
}

async waitForChannelsNum(num: number) {
console.log(`Waiting for ${num} channels`)
return this.driver.wait(async () => {
const channels = await this.getChannelList()
return channels.length === num
})
}

async waitForChannels(channelsNames: Array<string>) {
await this.waitForChannelsNum(channelsNames.length)
const names = await this.getChannelsNames()
expect(names).toEqual(expect.arrayContaining(channelsNames))
}

async openSettings() {
const button = await this.driver.findElement(By.xpath('//span[@data-testid="settings-panel-button"]'))
await button.click()
Expand Down
24 changes: 6 additions & 18 deletions packages/e2e-tests/src/tests/multipleClients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,15 @@ describe('Multiple Clients', () => {
users.owner.username,
`@${users.owner.username} deleted #${newChannelName}`
)
await sidebarUser1.waitForChannels(['general'])
})

it('Channel deletion - User can create channel with the same name and is fresh channel', async () => {
await sidebarUser1.addNewChannel(newChannelName)
await sidebarUser1.switchChannel(newChannelName)
const messages = await secondChannelUser1.getUserMessages(users.user1.username)
expect(messages.length).toEqual(1)
await new Promise<void>(resolve =>
setTimeout(() => {
resolve()
}, 2000)
)
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
await sidebarOwner.waitForChannels(['general', newChannelName])
})

it('Channel deletion - Owner creates third channel', async () => {
Expand All @@ -348,13 +344,7 @@ describe('Multiple Clients', () => {
thirdChannelOwner = new Channel(users.owner.app.driver, thirdChannelName)
const messages = await thirdChannelOwner.getUserMessages(users.owner.username)
expect(messages.length).toEqual(1)
await new Promise<void>(resolve =>
setTimeout(() => {
resolve()
}, 2000)
)
const channels = await sidebarUser1.getChannelList()
expect(channels.length).toEqual(3)
await sidebarUser1.waitForChannels(['general', newChannelName, thirdChannelName])
})

// End of tests for Windows
Expand All @@ -373,8 +363,7 @@ describe('Multiple Clients', () => {
await channelContextMenuOwner.openMenu()
await channelContextMenuOwner.openDeletionChannelModal()
await channelContextMenuOwner.deleteChannel()
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
await sidebarOwner.waitForChannels(['general', newChannelName])
})

// Delete general channel while guest is absent
Expand All @@ -386,8 +375,7 @@ describe('Multiple Clients', () => {
await channelContextMenuOwner.openMenu()
await channelContextMenuOwner.openDeletionChannelModal()
await channelContextMenuOwner.deleteChannel()
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
await sidebarOwner.waitForChannels(['general', newChannelName])
})

it('User 1 re-opens app', async () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/e2e-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class BuildSetup {
this.debugPort = await getPort()
}

// Note: .env file is being used locally right now, mainly by script e2e:linux:build
static getEnvFileName() {
const { parsed, error } = config()
console.log('Dotenv config', { parsed, error })
Expand Down Expand Up @@ -239,7 +240,11 @@ export class BuildSetup {
return
}
console.log(`Deleting data directory at ${this.dataDirPath}`)
fs.rmdirSync(this.dataDirPath, { recursive: true })
try {
fs.rmdirSync(this.dataDirPath, { recursive: true })
} catch (e) {
console.error(`Could not delete ${this.dataDirPath}. Reason: ${e.message}`)
}
}

public getProcessData = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DateTime } from 'luxon'
import { publicChannelsSelectors } from '../publicChannels.selectors'
import { combineReducers } from '@reduxjs/toolkit'
import { reducers } from '../../reducers'
import { generateChannelId } from '@quiet/common'
import { generalChannelDeletionMessage, generateChannelId } from '@quiet/common'
import { type Community, type PublicChannel } from '@quiet/types'

describe('sendInitialChannelMessageSaga', () => {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('sendInitialChannelMessageSaga', () => {
.put(
messagesActions.sendMessage({
type: 3,
message: `@${owner.nickname} deleted all messages in #general`,
message: generalChannelDeletionMessage(owner.nickname),
channelId: generalChannel.id,
})
)
Expand Down

0 comments on commit 6655c22

Please sign in to comment.