Skip to content

Commit

Permalink
Chore: cleanup startup of test and put wizard in setup function (#26306)
Browse files Browse the repository at this point in the history
  • Loading branch information
weslley543 committed Jul 22, 2022
1 parent 5dffebf commit 0777bd1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 285 deletions.
10 changes: 2 additions & 8 deletions apps/meteor/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
252 changes: 0 additions & 252 deletions apps/meteor/tests/e2e/00-wizard.spec.ts

This file was deleted.

30 changes: 29 additions & 1 deletion apps/meteor/tests/e2e/configs/setup.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -27,4 +28,31 @@ export default async (): Promise<void> => {
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();
};
21 changes: 1 addition & 20 deletions apps/meteor/tests/e2e/configs/teardown.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
import { MongoHelper } from '../utils/MongoHelper';
import { URL_MONGODB } from '../utils/constants';

const deleteRoom = async (): Promise<void> => {
const roomCollection = await MongoHelper.getCollection('rocketchat_room');
await roomCollection.deleteMany({ _id: { $in: ['9kc9F8BghhCp5bc3T', 'fWJChTFjhQLXZrusq'] } });
};

const deleteUser = async (): Promise<void> => {
const userCollection = await MongoHelper.getCollection('users');
await userCollection.deleteOne({ _id: 'vvsKGW5tKKqP9vj54' });
};

const deleteSubscribeUserInChannels = async (): Promise<void> => {
const subscribeCollections = await MongoHelper.getCollection('rocketchat_subscription');
await subscribeCollections.deleteMany({
_id: { $in: ['zjHWmhH4go9NoGwTP', 'cKZP37FdE8soBpJmN', 'RD7gjmtqnQtnR6BTt', 'T3Skt3gxZoTrWwWZx', 'TjtKQyfaGtrn6PjSk'] },
});
};

export default async (): Promise<void> => {
await MongoHelper.connect(URL_MONGODB);
await deleteRoom();
await deleteUser();
await deleteSubscribeUserInChannels();
await MongoHelper.dropDatabase();
await MongoHelper.disconnect();
};
6 changes: 2 additions & 4 deletions apps/meteor/tests/e2e/page-objects/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ export class Auth {
return this.page.locator('[name=confirm-pass]~.input-error');
}

async doLogin(input = ADMIN_CREDENTIALS, shouldWaitForHome = true): Promise<void> {
async doLogin(input = ADMIN_CREDENTIALS): Promise<void> {
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!"');
}
}
8 changes: 8 additions & 0 deletions apps/meteor/tests/e2e/utils/MongoHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type MongoHelperConfig = {
connect(uri: string): Promise<void>;
disconnect(): Promise<void>;
getCollection<T>(name: string): Promise<Collection<T>>;
dropDatabase(): Promise<void>;
};

export const MongoHelper: MongoHelperConfig = {
Expand All @@ -17,6 +18,13 @@ export const MongoHelper: MongoHelperConfig = {
this.client = await MongoClient.connect(uri);
},

async dropDatabase(): Promise<void> {
if (this.client) {
const { databaseName } = this.client.db();
await this.client.db(databaseName).dropDatabase();
}
},

async disconnect() {
if (this.client) {
this.client.close();
Expand Down

0 comments on commit 0777bd1

Please sign in to comment.