diff --git a/apps/meteor/playwright.config.ts b/apps/meteor/playwright.config.ts index 12144d4091f4..5ec7008923ce 100644 --- a/apps/meteor/playwright.config.ts +++ b/apps/meteor/playwright.config.ts @@ -2,15 +2,9 @@ import { PlaywrightTestConfig } from '@playwright/test'; import * as constants from './tests/e2e/utils/constants'; -const setupIsLocalhost = constants.IS_LOCALHOST - ? { - globalSetup: require.resolve('./tests/e2e/configs/setup.ts'), - globalTeardown: require.resolve('./tests/e2e/configs/teardown.ts'), - } - : { testIgnore: '00-wizard.spec.ts' }; - export default { - ...setupIsLocalhost, + globalSetup: require.resolve('./tests/e2e/configs/setup.ts'), + globalTeardown: require.resolve('./tests/e2e/configs/teardown.ts'), use: { headless: true, viewport: { width: 1368, height: 768 }, diff --git a/apps/meteor/tests/e2e/00-wizard.spec.ts b/apps/meteor/tests/e2e/00-wizard.spec.ts deleted file mode 100644 index 42c3d4d05f63..000000000000 --- a/apps/meteor/tests/e2e/00-wizard.spec.ts +++ /dev/null @@ -1,252 +0,0 @@ -import { test, expect, Page, Locator } from '@playwright/test'; - -import { Auth } from './page-objects'; -import { ADMIN_CREDENTIALS } from './utils/constants'; - -class SetupWizard { - private readonly page: Page; - - constructor(page: Page) { - this.page = page; - } - - private get nextStep(): Locator { - return this.page.locator('//button[contains(text(), "Next")]'); - } - - private get fullName(): Locator { - return this.page.locator('[name="fullname"]'); - } - - private get userName(): Locator { - return this.page.locator('[name="username"]'); - } - - private get companyEmail(): Locator { - return this.page.locator('[name="companyEmail"]'); - } - - private get password(): Locator { - return this.page.locator('[name="password"]'); - } - - get goToWorkspace(): Locator { - return this.page.locator('//button[contains(text(), "Confirm")]'); - } - - get organizationType(): Locator { - return this.page.locator('[name="organizationType"]'); - } - - get organizationTypeSelect(): Locator { - return this.page.locator('.rcx-options .rcx-option:first-child'); - } - - get organizationName(): Locator { - return this.page.locator('[name="organizationName"]'); - } - - get industry(): Locator { - return this.page.locator('[name="organizationIndustry"]'); - } - - get industrySelect(): Locator { - return this.page.locator('.rcx-options .rcx-option:first-child'); - } - - get size(): Locator { - return this.page.locator('[name="organizationSize"]'); - } - - get sizeSelect(): Locator { - return this.page.locator('.rcx-options .rcx-option:first-child'); - } - - get country(): Locator { - return this.page.locator('[name="country"]'); - } - - get countrySelect(): Locator { - return this.page.locator('.rcx-options .rcx-option:first-child'); - } - - get registeredServer(): Locator { - return this.page.locator('input[name=email]'); - } - - get registerButton(): Locator { - return this.page.locator('//button[contains(text(), "Register")]'); - } - - get agreementField(): Locator { - return this.page.locator('//input[@name="agreement"]/../i[contains(@class, "rcx-check-box")]'); - } - - get standaloneServer(): Locator { - return this.page.locator('//a[contains(text(), "Continue as standalone")]'); - } - - get standaloneConfirmText(): Locator { - return this.page.locator('//*[contains(text(), "Standalone Server Confirmation")]'); - } - - get fullNameInvalidText(): Locator { - return this.page.locator('//input[@name="fullname"]/../following-sibling::span'); - } - - get userNameInvalidText(): Locator { - return this.page.locator('//input[@name="username"]/../following-sibling::span'); - } - - get companyEmailInvalidText(): Locator { - return this.page.locator('//input[@name="companyEmail"]/../following-sibling::span'); - } - - get passwordInvalidText(): Locator { - return this.page.locator('//input[@name="password"]/../../../span[contains(@class, "rcx-field__error")]'); - } - - get industryInvalidSelect(): Locator { - return this.page.locator('//div[@name="organizationIndustry"]/../following-sibling::span'); - } - - get sizeInvalidSelect(): Locator { - return this.page.locator('//div[@name="organizationSize"]/../following-sibling::span'); - } - - get countryInvalidSelect(): Locator { - return this.page.locator('//div[@name="country"]/../following-sibling::span'); - } - - get stepThreeInputInvalidMail(): Locator { - return this.page.locator('//input[@name="email"]/../../span[contains(text(), "This field is required")]'); - } - - async stepTwoSuccess(): Promise { - await this.organizationName.type('rocket.chat.reason'); - await this.organizationType.click(); - await this.organizationTypeSelect.click(); - await expect(this.page.locator('.rcx-options')).toHaveCount(0); - await this.industry.click(); - await this.industrySelect.click(); - await expect(this.page.locator('.rcx-options')).toHaveCount(0); - await this.size.click(); - await this.sizeSelect.click(); - await expect(this.page.locator('.rcx-options')).toHaveCount(0); - await this.country.click(); - await this.countrySelect.click(); - await this.nextStep.click(); - } - - async stepThreeSuccess(): Promise { - await this.standaloneServer.click(); - } - - async stepOneFailedBlankFields(): Promise { - await this.nextStep.click(); - await expect(this.fullNameInvalidText).toBeVisible(); - await expect(this.userNameInvalidText).toBeVisible(); - await expect(this.companyEmailInvalidText).toBeVisible(); - await expect(this.passwordInvalidText).toBeVisible(); - } - - async stepOneFailedWithInvalidEmail(adminCredentials: { name: string; password: string }): Promise { - await this.fullName.type(adminCredentials.name); - await this.userName.type(adminCredentials.name); - await this.companyEmail.type('mail'); - await this.password.type(adminCredentials.password); - await this.nextStep.click(); - await expect(this.companyEmail).toBeFocused(); - } - - async stepTwoFailedWithBlankFields(): Promise { - await this.nextStep.click(); - await expect(this.organizationName).toBeVisible(); - await expect(this.industryInvalidSelect).toBeVisible(); - await expect(this.sizeInvalidSelect).toBeVisible(); - await expect(this.countryInvalidSelect).toBeVisible(); - } - - async stepThreeFailedWithInvalidField(): Promise { - await this.registeredServer.type('mail'); - await this.registeredServer.click({ clickCount: 3 }); - await this.page.keyboard.press('Backspace'); - await expect(this.stepThreeInputInvalidMail).toBeVisible(); - } -} - -test.describe('[Wizard]', () => { - let page: Page; - let pageAuth: Auth; - - let setupWizard: SetupWizard; - - test.beforeEach(async ({ browser }) => { - page = await browser.newPage(); - pageAuth = new Auth(page); - setupWizard = new SetupWizard(page); - }); - - test.describe('[Step 2]', async () => { - test.beforeEach(async () => { - await pageAuth.doLogin(ADMIN_CREDENTIALS, false); - }); - - test('expect required field alert showed when user dont inform data', async () => { - await setupWizard.stepTwoFailedWithBlankFields(); - }); - - test('expect go to Step 3 successfully', async () => { - await setupWizard.stepTwoSuccess(); - await expect(page).toHaveURL(/.*\/setup-wizard\/3/); - }); - }); - - test.describe('[Step 3]', async () => { - test.beforeEach(async () => { - await pageAuth.doLogin(ADMIN_CREDENTIALS, false); - await setupWizard.stepTwoSuccess(); - }); - - test('expect have email field to register the server', async () => { - await expect(setupWizard.registeredServer).toBeVisible(); - }); - - test('expect start "Register" button disabled', async () => { - await expect(setupWizard.registerButton).toBeDisabled(); - }); - - test('expect show an error on invalid email', async () => { - await setupWizard.stepThreeFailedWithInvalidField(); - }); - - test('expect enable "Register" button when email is valid and terms checked', async () => { - await setupWizard.registeredServer.type('mail@mail.com'); - await setupWizard.agreementField.click(); - await expect(setupWizard.registerButton).toBeEnabled(); - }); - - test('expect have option for standalone server', async () => { - await expect(setupWizard.standaloneServer).toBeVisible(); - }); - }); - - test.describe('[Final Step]', async () => { - test.beforeEach(async () => { - await pageAuth.doLogin(ADMIN_CREDENTIALS, false); - await setupWizard.stepTwoSuccess(); - await setupWizard.stepThreeSuccess(); - }); - - test('expect confirm the standalone option', async () => { - await expect(setupWizard.goToWorkspace).toBeVisible(); - await expect(setupWizard.standaloneConfirmText).toBeVisible(); - }); - - test('expect confirm standalone', async () => { - await setupWizard.goToWorkspace.click(); - // HOME_SELECTOR - await page.waitForSelector('//span[@class="rc-header__block"]'); - }); - }); -}); diff --git a/apps/meteor/tests/e2e/configs/setup.ts b/apps/meteor/tests/e2e/configs/setup.ts index 83daf6401cea..144ba3e492b6 100644 --- a/apps/meteor/tests/e2e/configs/setup.ts +++ b/apps/meteor/tests/e2e/configs/setup.ts @@ -1,7 +1,8 @@ import type { IRoom, IUser, ISubscription } from '@rocket.chat/core-typings'; +import { chromium } from '@playwright/test'; import { MongoHelper } from '../utils/MongoHelper'; -import { URL_MONGODB } from '../utils/constants'; +import { URL_MONGODB, ADMIN_CREDENTIALS, BASE_URL } from '../utils/constants'; import { roomMock } from '../utils/mocks/roomMock'; import { userMock } from '../utils/mocks/userMock'; import { subscriptionMock } from '../utils/mocks/subscriptionMock'; @@ -27,4 +28,31 @@ export default async (): Promise => { await insertUser(); await subscribeUserInChannels(); await MongoHelper.disconnect(); + + const browser = await chromium.launch(); + const page = await browser.newPage(); + + await page.goto(BASE_URL); + + await page.locator('[name=emailOrUsername]').type(ADMIN_CREDENTIALS.email); + await page.locator('[name=pass]').type(ADMIN_CREDENTIALS.password); + await page.locator('.login').click(); + + await page.locator('[name="organizationName"]').type('any_name'); + await page.locator('[name="organizationType"]').click(); + await page.locator('.rcx-options .rcx-option:first-child >> text="Community"').click(); + await page.locator('[name="organizationIndustry"]').click(); + await page.locator('.rcx-options .rcx-option:first-child >> text="Aerospace & Defense"').click(); + await page.locator('[name="organizationSize"]').click(); + await page.locator('.rcx-options .rcx-option:first-child >> text="1-10 people"').click(); + await page.locator('[name="country"]').click(); + await page.locator('.rcx-options .rcx-option:first-child >> text="Afghanistan"').click(); + await page.locator('.rcx-button--primary.rcx-button >> text="Next"').click(); + + await page.locator('a.rcx-box.rcx-box--full >> text="Continue as standalone"').click(); + + await page.locator('.rcx-button--primary.rcx-button >> text="Confirm"').click(); + + await page.waitForURL('http://localhost:3000/home'); + await browser.close(); }; diff --git a/apps/meteor/tests/e2e/configs/teardown.ts b/apps/meteor/tests/e2e/configs/teardown.ts index b38910268225..efc9d7a774a9 100644 --- a/apps/meteor/tests/e2e/configs/teardown.ts +++ b/apps/meteor/tests/e2e/configs/teardown.ts @@ -1,27 +1,8 @@ import { MongoHelper } from '../utils/MongoHelper'; import { URL_MONGODB } from '../utils/constants'; -const deleteRoom = async (): Promise => { - const roomCollection = await MongoHelper.getCollection('rocketchat_room'); - await roomCollection.deleteMany({ _id: { $in: ['9kc9F8BghhCp5bc3T', 'fWJChTFjhQLXZrusq'] } }); -}; - -const deleteUser = async (): Promise => { - const userCollection = await MongoHelper.getCollection('users'); - await userCollection.deleteOne({ _id: 'vvsKGW5tKKqP9vj54' }); -}; - -const deleteSubscribeUserInChannels = async (): Promise => { - const subscribeCollections = await MongoHelper.getCollection('rocketchat_subscription'); - await subscribeCollections.deleteMany({ - _id: { $in: ['zjHWmhH4go9NoGwTP', 'cKZP37FdE8soBpJmN', 'RD7gjmtqnQtnR6BTt', 'T3Skt3gxZoTrWwWZx', 'TjtKQyfaGtrn6PjSk'] }, - }); -}; - export default async (): Promise => { await MongoHelper.connect(URL_MONGODB); - await deleteRoom(); - await deleteUser(); - await deleteSubscribeUserInChannels(); + await MongoHelper.dropDatabase(); await MongoHelper.disconnect(); }; diff --git a/apps/meteor/tests/e2e/page-objects/auth.ts b/apps/meteor/tests/e2e/page-objects/auth.ts index 0a5cb5fbbd60..0f583fed5a21 100644 --- a/apps/meteor/tests/e2e/page-objects/auth.ts +++ b/apps/meteor/tests/e2e/page-objects/auth.ts @@ -69,14 +69,12 @@ export class Auth { return this.page.locator('[name=confirm-pass]~.input-error'); } - async doLogin(input = ADMIN_CREDENTIALS, shouldWaitForHome = true): Promise { + async doLogin(input = ADMIN_CREDENTIALS): Promise { await this.page.goto('/'); await this.page.locator('[name=emailOrUsername]').type(input.email); await this.page.locator('[name=pass]').type(input.password); await this.page.locator('.login').click(); - if (shouldWaitForHome) { - await this.page.waitForSelector('text="Welcome to Rocket.Chat!"'); - } + await this.page.waitForSelector('text="Welcome to Rocket.Chat!"'); } } diff --git a/apps/meteor/tests/e2e/utils/MongoHelper.ts b/apps/meteor/tests/e2e/utils/MongoHelper.ts index 79c152fd57e0..410e781ee748 100644 --- a/apps/meteor/tests/e2e/utils/MongoHelper.ts +++ b/apps/meteor/tests/e2e/utils/MongoHelper.ts @@ -6,6 +6,7 @@ type MongoHelperConfig = { connect(uri: string): Promise; disconnect(): Promise; getCollection(name: string): Promise>; + dropDatabase(): Promise; }; export const MongoHelper: MongoHelperConfig = { @@ -17,6 +18,13 @@ export const MongoHelper: MongoHelperConfig = { this.client = await MongoClient.connect(uri); }, + async dropDatabase(): Promise { + if (this.client) { + const { databaseName } = this.client.db(); + await this.client.db(databaseName).dropDatabase(); + } + }, + async disconnect() { if (this.client) { this.client.close();