ActivityPub-federated video streaming platform using P2P directly in your web browser
Add E2E tests for channels
Chocobozzz489e07c21992
diff --git a/client/e2e/fixtures/avatar.png b/client/e2e/fixtures/avatar.pngnew file mode 100644index 0000000000..4b7fd2c0a2Binary files /dev/null and b/client/e2e/fixtures/avatar.png differdiff --git a/client/e2e/fixtures/banner.jpg b/client/e2e/fixtures/banner.jpgnew file mode 100644index 0000000000..e5f284f59dBinary files /dev/null and b/client/e2e/fixtures/banner.jpg differdiff --git a/client/e2e/src/po/channel.po.ts b/client/e2e/src/po/channel.po.tsnew file mode 100644index 0000000000..95c2919ef2--- /dev/null+++ b/client/e2e/src/po/channel.po.ts@@ -0,0 +1,258 @@+import { join } from 'node:path'+import { go, selectCustomSelect } from '../utils'++export class ChannelPage {+ private currentChannelName: string++ readonly avatarPath = join(__dirname, '../../../src/assets/images/default-avatar-video-channel.png')+ readonly bannerPath = join(__dirname, '../../../src/assets/images/favicon.png')++ async navigateToCreate () {+ await go('/my-library/video-channels/create')+ await $('#name').waitForDisplayed()+ }++ async createChannel (options: {+ name: string+ displayName: string+ }) {+ await this.navigateToCreate()++ this.currentChannelName = options.name++ await this.fillName(options.name)+ await this.fillDisplayName(options.displayName)+ await this.save()+ await this.waitForManagePage(options.name)+ }++ async updateDisplayName (displayName: string) {+ await this.fillDisplayName(displayName)+ await this.save()+ }++ async updateDescription (description: string) {+ await this.fillDescription(description)+ await this.save()+ }++ async updateSupport (support: string) {+ await this.fillSupport(support)+ await this.save()+ }++ async updatePlayerTheme (theme: string) {+ await selectCustomSelect('playerTheme', theme)+ await this.save()+ }++ async uploadAvatar (filePath = this.avatarPath) {+ await this.prepareImageInput('my-actor-avatar-edit input#avatarfile')+ await $('my-actor-avatar-edit input#avatarfile').chooseFile(filePath)+ }++ async uploadBanner (filePath = this.bannerPath) {+ await this.prepareImageInput('my-actor-banner-edit input#bannerfile')+ await $('my-actor-banner-edit input#bannerfile').chooseFile(filePath)+ }++ async openEditorPage (channelName = this.currentChannelName) {+ await go(`/my-library/video-channels/manage/${channelName}/editors`)++ await $('#addEditor').waitForDisplayed()+ }++ async inviteCollaborator (username: string) {+ const editorInput = $('#addEditor')+ await editorInput.waitForDisplayed()+ await editorInput.setValue(username)++ const inviteButton = $('my-video-channel-editors').$('button*=Invite')+ await inviteButton.waitForClickable()+ await inviteButton.click()++ const confirmInviteButton = $('.modal-content .modal-footer input.primary-button')+ await confirmInviteButton.waitForClickable()+ await confirmInviteButton.click()+ }++ async removeCollaborator (displayName: string) {+ const collaboratorBlock = await this.getCollaboratorBlock(displayName)+ const actionButton = collaboratorBlock.$('my-action-dropdown .action-button')++ await actionButton.waitForClickable()+ await actionButton.click()++ const deleteAction = await this.getDeleteCollaboratorAction()+ await deleteAction.waitForClickable()+ await deleteAction.click()++ const confirmButton = $('.modal-content .modal-footer input.primary-button')+ await confirmButton.waitForClickable()+ await confirmButton.click()+ }++ async save () {+ const saveButton = $('.save-button > button:not([disabled])')+ await saveButton.waitForClickable()+ await saveButton.click()+ await $('.save-button > button[disabled]').waitForDisplayed()+ }++ async waitForManagePage (channelName: string) {+ await browser.waitUntil(async () => {+ const url = await browser.getUrl()++ return url.includes(`/my-library/video-channels/manage/${channelName}`)+ })+ }++ async refreshManagePage () {+ await browser.refresh()+ await $('#displayName').waitForDisplayed()+ }++ async expectManageDisplayName (displayName: string) {+ await expect($('.actions h2')).toHaveText(expect.stringContaining(displayName))+ }++ async expectPlayerTheme (theme: string) {+ await expect($('[formcontrolname=playerTheme] span[role=combobox]')).toHaveText(expect.stringContaining(theme))+ }++ async expectBannerAndAvatarSaved () {+ await $('my-actor-banner-edit .banner-placeholder img').waitForDisplayed()+ await $('my-actor-avatar-edit my-actor-avatar img').waitForDisplayed()+ }++ async expectCollaboratorInvited (displayName: string) {+ const collaboratorBlock = await this.getCollaboratorBlock(displayName)++ expect(await collaboratorBlock.getText()).toContain(displayName)+ expect(await collaboratorBlock.getText()).toContain('Invitation sent')+ }++ async expectCollaboratorAccepted (displayName: string) {+ const collaboratorBlock = await this.getCollaboratorBlock(displayName)++ expect(await collaboratorBlock.getText()).toContain(displayName)+ expect(await collaboratorBlock.getText()).toContain('Editor')+ }++ async expectNoCollaborators () {+ await expect($('.collaborators')).toHaveText(expect.stringContaining('No editors at the moment'))+ }++ async getAvatarSrc () {+ const el = $('my-actor-avatar-edit my-actor-avatar img')+ if (!await el.isExisting()) return ''++ return el.getAttribute('src')+ }++ async goToPublicPage (channelName: string) {+ await go(`/c/${channelName}`)+ await $('.actor-display-name h1').waitForDisplayed()+ }++ async expectPublicPage (options: {+ displayName: string+ description: string+ support: string+ }) {+ await expect($('.actor-display-name h1')).toHaveText(options.displayName)+ await expect($('.channel-description .description-html')).toHaveText(expect.stringContaining(options.description))++ await $('.support-button').waitForClickable()+ await $('.support-button').click()++ await expect($('.modal-body')).toHaveText(expect.stringContaining(options.support))+ await $('.modal-footer input[value="Close"]').click()++ await $('.banner img').waitForDisplayed()+ await $('.channel-avatar-row my-actor-avatar img').waitForDisplayed()+ }++ async expectListedInMyVideoChannels (displayName: string) {+ await go('/my-library/video-channels')+ await $(`.display-name*=${displayName}`).waitForDisplayed()+ }++ private async fillName (name: string) {+ const nameInput = $('#name')+ await nameInput.waitForDisplayed()+ await nameInput.setValue(name)+ }++ private async fillDisplayName (displayName: string) {+ const displayNameInput = $('#displayName')+ await displayNameInput.waitForDisplayed()+ await displayNameInput.clearValue()+ await displayNameInput.setValue(displayName)+ }++ private async fillDescription (description: string) {+ const descriptionInput = $('#description')+ await descriptionInput.waitForDisplayed()+ await descriptionInput.clearValue()+ await descriptionInput.setValue(description)+ }++ private async fillSupport (support: string) {+ const supportInput = $('#support')+ await supportInput.waitForDisplayed()+ await supportInput.clearValue()+ await supportInput.setValue(support)+ }++ private async prepareImageInput (selector: string) {+ await browser.execute((imageSelector: string) => {+ const input = document.querySelector(imageSelector)++ if (input instanceof HTMLInputElement) input.style.opacity = '1'+ }, selector)++ await $(selector).waitForExist()+ }++ private async getCollaboratorBlock (displayName: string) {+ let matchingBlock: WebdriverIO.Element | undefined++ await browser.waitUntil(async () => {+ const blocks = $$('.collaborators .collaborator-block')++ await blocks.forEach(async block => {+ if (!block) return++ const text = await block.getText()+ if (text.includes(displayName)) {+ matchingBlock = block+ return true+ }+ })++ if (matchingBlock) return true+ })++ if (!matchingBlock) throw new Error(`Cannot find collaborator block for ${displayName}`)++ return matchingBlock+ }++ private async getDeleteCollaboratorAction () {+ let action: WebdriverIO.Element++ await browser.waitUntil(() => {+ return $$('.dropdown-menu .custom-action').some(async el => {+ if ((await el.getText()).includes('Delete')) {+ action = el+ return true+ }++ return false+ })+ })++ return action+ }+}diff --git a/client/e2e/src/po/notification.po.ts b/client/e2e/src/po/notification.po.tsnew file mode 100644index 0000000000..1e0c22c913--- /dev/null+++ b/client/e2e/src/po/notification.po.ts@@ -0,0 +1,46 @@+import { go } from '../utils'++export class NotificationPage {+ async navigateTo () {+ await go('/my-account/notifications')++ await $('my-user-notifications').waitForDisplayed()+ }++ async acceptChannelCollaborationInvitation (channelDisplayName: string) {+ const notification = await this.getNotification(channelDisplayName)+ const acceptButton = notification.$('button*=Accept')++ await acceptButton.waitForClickable()+ await acceptButton.click()++ await browser.waitUntil(async () => {+ const url = await browser.getUrl()++ return url.includes('/video-channels/manage/')+ })++ await $('.header-block').$('*=' + channelDisplayName).waitForDisplayed()+ }++ private async getNotification (channelDisplayName: string) {+ let notification: WebdriverIO.Element++ await browser.waitUntil(async () => {+ return $$('.notifications .notification').some(async el => {+ if ((await el.getText()).includes(channelDisplayName)) {+ notification = el+ return true+ }++ return false+ })+ })++ if (!notification) {+ throw new Error(`Cannot find channel collaboration notification for ${channelDisplayName}`)+ }++ return notification+ }+}diff --git a/client/e2e/src/suites-local/channel.e2e-spec.ts b/client/e2e/src/suites-local/channel.e2e-spec.tsnew file mode 100644index 0000000000..9985c6630d--- /dev/null+++ b/client/e2e/src/suites-local/channel.e2e-spec.ts@@ -0,0 +1,142 @@+import { AdminUserPage } from '../po/admin-user.po'+import { ChannelPage } from '../po/channel.po'+import { LoginPage } from '../po/login.po'+import { NotificationPage } from '../po/notification.po'+import { isMobileDevice, prepareWebBrowser, waitServerUp } from '../utils'++describe('Channel management', () => {+ let loginPage: LoginPage+ let adminUserPage: AdminUserPage+ let channelPage: ChannelPage+ let notificationPage: NotificationPage++ const seed = Math.random().toString().slice(2, 10)+ const classicUsername = `classic_user_${seed}`+ const classicUserPassword = 'superpassword'+ const collaboratorUsername = `collaborator_user_${seed}`+ const collaboratorPassword = 'superpassword'+ const channelName = `channel_${seed}`+ const channelDisplayName = `Channel ${seed}`+ const updatedChannelDisplayName = `Updated channel ${seed}`+ const updatedDescription = `Description ${seed}`+ const updatedSupport = `Support ${seed}`+ const updatedTheme = 'Lucide'++ before(async () => {+ await waitServerUp()++ loginPage = new LoginPage(isMobileDevice())+ adminUserPage = new AdminUserPage()+ channelPage = new ChannelPage()+ notificationPage = new NotificationPage()++ await prepareWebBrowser()+ })++ describe('Classic user channel management', function () {+ it('Should create a classic user', async function () {+ await loginPage.loginAsRootUser()++ await adminUserPage.createUser({+ username: classicUsername,+ password: classicUserPassword+ })++ await loginPage.logout()+ })++ it('Should create a collaborator user', async function () {+ await loginPage.loginAsRootUser()++ await adminUserPage.createUser({+ username: collaboratorUsername,+ password: collaboratorPassword+ })++ await loginPage.logout()+ })++ it('Should create a channel', async function () {+ await loginPage.login({ username: classicUsername, password: classicUserPassword })++ await channelPage.createChannel({+ name: channelName,+ displayName: channelDisplayName+ })++ await channelPage.expectManageDisplayName(channelDisplayName)+ })++ it('Should update the created channel', async function () {+ await channelPage.updateDisplayName(updatedChannelDisplayName)+ })++ it('Should update the channel description', async function () {+ await channelPage.updateDescription(updatedDescription)+ })++ it('Should update the channel support text', async function () {+ await channelPage.updateSupport(updatedSupport)+ })++ it('Should update the channel player theme', async function () {+ await channelPage.updatePlayerTheme(updatedTheme)++ await channelPage.refreshManagePage()+ await channelPage.expectPlayerTheme(updatedTheme)+ })++ it('Should update the channel banner and avatar', async function () {+ const previousAvatarSrc = await channelPage.getAvatarSrc()++ await channelPage.uploadBanner()+ await channelPage.uploadAvatar()+ await channelPage.save()++ await channelPage.refreshManagePage()+ await channelPage.expectBannerAndAvatarSaved()++ const updatedAvatarSrc = await channelPage.getAvatarSrc()+ expect(updatedAvatarSrc).not.toEqual(previousAvatarSrc)+ })++ it('Should display updated channel data on public page', async function () {+ await channelPage.goToPublicPage(channelName)+ await channelPage.expectPublicPage({+ displayName: updatedChannelDisplayName,+ description: updatedDescription,+ support: updatedSupport+ })++ await channelPage.expectListedInMyVideoChannels(updatedChannelDisplayName)+ })++ it('Should invite a collaborator to the channel', async function () {+ await channelPage.openEditorPage()+ await channelPage.inviteCollaborator(collaboratorUsername)+ await channelPage.expectCollaboratorInvited(collaboratorUsername)+ })++ it('Should let the collaborator accept the invitation and see the channel', async function () {+ await loginPage.logout()+ await loginPage.login({ username: collaboratorUsername, password: collaboratorPassword })++ await notificationPage.navigateTo()+ await notificationPage.acceptChannelCollaborationInvitation(updatedChannelDisplayName)+ await channelPage.expectListedInMyVideoChannels(updatedChannelDisplayName)++ await loginPage.logout()+ await loginPage.login({ username: classicUsername, password: classicUserPassword })++ await channelPage.openEditorPage()+ await channelPage.expectCollaboratorAccepted(collaboratorUsername)+ })++ it('Should remove the collaborator from the channel', async function () {+ await channelPage.openEditorPage()++ await channelPage.removeCollaborator(collaboratorUsername)+ await channelPage.expectNoCollaborators()+ })+ })+})diff --git a/client/e2e/wdio.local-test.conf.ts b/client/e2e/wdio.local-test.conf.tsindex 667e674872..af49bb6d31 100644--- a/client/e2e/wdio.local-test.conf.ts+++ b/client/e2e/wdio.local-test.conf.ts@@ -14,6 +14,10 @@ process.env.MOZ_HEADLESS_HEIGHT = '1024'const windowSizeArg = `--window-size=${process.env.MOZ_HEADLESS_WIDTH},${process.env.MOZ_HEADLESS_HEIGHT}`+const moreArgs = process.env.WDIO_HEADLESS === 'false'+ ? []+ : [ '--headless', windowSizeArg ]+module.exports = {config: {...mainConfig,@@ -28,7 +32,7 @@ module.exports = {'browserName': 'chrome','acceptInsecureCerts': true,'goog:chromeOptions': {- args: [ '--disable-gpu', windowSizeArg ],+ args: [ '--disable-gpu', windowSizeArg, ...moreArgs ],prefs}}@@ -36,7 +40,7 @@ module.exports = {// 'browserName': 'firefox',// 'moz:firefoxOptions': {// binary: '/usr/bin/firefox-developer-edition',- // args: [ '--headless', windowSizeArg ],+ // args: [ '--headless', windowSizeArg, ...moreArgs ],// prefs// }diff --git a/support/doc/development/tests.md b/support/doc/development/tests.mdindex 81eb0cf602..8f35516499 100644--- a/support/doc/development/tests.md+++ b/support/doc/development/tests.md@@ -129,5 +129,5 @@ To add E2E tests and quickly run tests using a local Chrome:```bashcd client/e2e-../node_modules/.bin/wdio wdio.local-test.conf.ts # you can also add --mochaOpts.grep to only run tests you want+WDIO_HEADLESS=false ../node_modules/.bin/wdio wdio.local-test.conf.ts # you can also add --mochaOpts.grep to only run tests you want```