Skip to content

Commit

Permalink
chore: Adjust mocha assertions (#30052)
Browse files Browse the repository at this point in the history
Co-authored-by: Tasso Evangelista <[email protected]>
  • Loading branch information
2 people authored and MartinSchoeler committed Aug 11, 2023
1 parent 59a8033 commit dd67f9c
Show file tree
Hide file tree
Showing 85 changed files with 285 additions and 252 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules/
/tests/e2e/
#/tests/e2e/
/tests/data/
/packages/
/app/emoji-emojione/generateEmojiIndex.js
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/marked": "^4.0.8",
"@types/meteor-collection-hooks": "^0.8.6",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^8.2.3",
"@types/mocha": "github:whitecolor/mocha-types",
"@types/moment-timezone": "^0.5.30",
"@types/node": "^14.18.51",
"@types/node-rsa": "^1.1.1",
Expand Down
14 changes: 0 additions & 14 deletions apps/meteor/tests/.eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions apps/meteor/tests/data/uploads.helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Response } from 'supertest';
import { expect } from 'chai';
import { after, before, it } from 'mocha';

import { api, request, credentials } from './api-data.js';
import { password } from './user';
Expand Down
3 changes: 0 additions & 3 deletions apps/meteor/tests/e2e/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
}
}
},
"env": {
"mocha": true
},
"parserOptions": {
"project": ["./tsconfig.json"]
}
Expand Down
122 changes: 61 additions & 61 deletions apps/meteor/tests/e2e/avatar-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { test, expect } from './utils/test';
test.use({ storageState: Users.admin.state });

const testAvatars = (homeChannel: HomeChannel, channel: string, url: string) => {
test('expect sidebar avatar to have provider prefix', async () => {
expect(homeChannel.sidenav.getSidebarItemByName(channel).locator('img').getAttribute('src')).toBe(url);
});
test('expect channel header avatar to have provider prefix', async () => {
await homeChannel.sidenav.openChat(channel);
expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url);
});

test('expect channel info avatar to have provider prefix', async () => {
await homeChannel.sidenav.openChat(channel);
expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url);
});
}
test('expect sidebar avatar to have provider prefix', async () => {
expect(homeChannel.sidenav.getSidebarItemByName(channel).locator('img').getAttribute('src')).toBe(url);
});

test('expect channel header avatar to have provider prefix', async () => {
await homeChannel.sidenav.openChat(channel);
expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url);
});

test('expect channel info avatar to have provider prefix', async () => {
await homeChannel.sidenav.openChat(channel);
expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url);
});
};

test.describe('avatar-settings', () => {
let poHomeChannel: HomeChannel;
Expand All @@ -32,67 +32,67 @@ test.describe('avatar-settings', () => {
});

test.describe('external avatar provider', () => {
const providerUrlPrefix = 'https://example.com/avatar/';
const providerUrlPrefix = 'https://example.com/avatar/';

test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', `${providerUrlPrefix}{username}`);
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', `${providerUrlPrefix}{username}`);
});
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', `${providerUrlPrefix}{username}`);
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', `${providerUrlPrefix}{username}`);
});

test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', '');
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', '');
})
test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', '');
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', '');
});

test.describe('public channels', () => {
let channelName = '';
let avatarUrl = '';
test.describe('public channels', () => {
let channelName = '';
let avatarUrl = '';

test.beforeAll(async ({ api }) => {
channelName = await createTargetChannel(api);
avatarUrl = `${providerUrlPrefix}${channelName}`;
});
test.beforeAll(async ({ api }) => {
channelName = await createTargetChannel(api);
avatarUrl = `${providerUrlPrefix}${channelName}`;
});

testAvatars(poHomeChannel, channelName, avatarUrl);
});
testAvatars(poHomeChannel, channelName, avatarUrl);
});

test.describe('private channels', () => {
let channelName = '';
let avatarUrl = '';
test.describe('private channels', () => {
let channelName = '';
let avatarUrl = '';

test.beforeAll(async ({ api }) => {
channelName = await createTargetPrivateChannel(api);
avatarUrl = `${providerUrlPrefix}${channelName}`;
});
test.beforeAll(async ({ api }) => {
channelName = await createTargetPrivateChannel(api);
avatarUrl = `${providerUrlPrefix}${channelName}`;
});

testAvatars(poHomeChannel, channelName, avatarUrl);
});
testAvatars(poHomeChannel, channelName, avatarUrl);
});

test.describe('direct messages', () => {
const channelName = Users.user2.data.username;
const avatarUrl = `${providerUrlPrefix}${channelName}`;
test.describe('direct messages', () => {
const channelName = Users.user2.data.username;
const avatarUrl = `${providerUrlPrefix}${channelName}`;

test.beforeAll(async ({ api }) => {
await createDirectMessage(api);
test.beforeAll(async ({ api }) => {
await createDirectMessage(api);

// send a message as user 2
test.use({ storageState: Users.user2.state });
await poHomeChannel.sidenav.openChat(Users.user1.data.username);
await poHomeChannel.content.sendMessage('hello world');
// send a message as user 2
test.use({ storageState: Users.user2.state });
await poHomeChannel.sidenav.openChat(Users.user1.data.username);
await poHomeChannel.content.sendMessage('hello world');

test.use({ storageState: Users.user1.state });
});
test.use({ storageState: Users.user1.state });
});

testAvatars(poHomeChannel, channelName, avatarUrl);
testAvatars(poHomeChannel, channelName, avatarUrl);

test('expect message avatar to have provider prefix', async () => {
expect(poHomeChannel.content.lastUserMessage.locator('img').getAttribute('src')).toBe(avatarUrl);
});
test('expect message avatar to have provider prefix', async () => {
expect(poHomeChannel.content.lastUserMessage.locator('img').getAttribute('src')).toBe(avatarUrl);
});

test('expect user card avatar to have provider prefix', async () => {
await poHomeChannel.content.lastUserMessage.locator('.rcx-message-header__name-container').click();
expect(poHomeChannel.content.userCard.locator('img').getAttribute('src')).toBe(avatarUrl);
});
});
test('expect user card avatar to have provider prefix', async () => {
await poHomeChannel.content.lastUserMessage.locator('.rcx-message-header__name-container').click();
expect(poHomeChannel.content.userCard.locator('img').getAttribute('src')).toBe(avatarUrl);
});
});
});
});
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/e2e-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test.describe.serial('e2e-encryption initial setup', () => {

await injectInitialData();

await restoreState(page, Users.admin, {except: ['public_key', 'private_key']});
await restoreState(page, Users.admin, { except: ['public_key', 'private_key'] });

await page.locator('role=banner >> text="Enter your E2E password"').click();

Expand Down
1 change: 0 additions & 1 deletion apps/meteor/tests/e2e/federation/config/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export default async function (): Promise<void> {
if (requiredEnvVars.some((envVar) => !process.env[envVar])) {
throw new Error(`Missing required environment variables: ${requiredEnvVars.filter((envVar) => !process.env[envVar]).join(', ')}`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class FederationSidenav {
await this.page.locator('role=search >> role=searchbox').type(name);
await this.page.locator(`role=search >> role=listbox >> role=link >> text="${name}"`).waitFor();
await this.page.waitForTimeout(2000);

return this.page.locator(`role=search >> role=listbox >> role=link >> text="${name}"`).count();
}

Expand Down
16 changes: 4 additions & 12 deletions apps/meteor/tests/e2e/federation/tests/admin/users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ test.describe.parallel('Federation - Admin Panel - Users', () => {
page,
apiServer2,
}) => {
const before = parseInt(
(await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0',
);
const before = parseInt((await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0');
const newUserFromServer2 = await registerUser(apiServer2);
const page2 = await browser.newPage();
const poFederationChannelServer1ForUser2 = new FederationChannel(page2);
Expand All @@ -100,9 +98,7 @@ test.describe.parallel('Federation - Admin Panel - Users', () => {
fullUsernameFromServer: fullUsernameFromServer2,
server: constants.RC_SERVER_1,
});
const after = parseInt(
(await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0',
);
const after = parseInt((await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0');
expect(before).toEqual(after);
await page2.close();
});
Expand All @@ -112,9 +108,7 @@ test.describe.parallel('Federation - Admin Panel - Users', () => {
page,
apiServer1,
}) => {
const before = parseInt(
(await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0',
);
const before = parseInt((await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0');
const newUserFromServer1 = await registerUser(apiServer1);
const page2 = await browser.newPage();
const poFederationChannelServer1ForUser2 = new FederationChannel(page2);
Expand All @@ -126,9 +120,7 @@ test.describe.parallel('Federation - Admin Panel - Users', () => {
server: constants.RC_SERVER_1,
});
await page.reload();
const after = parseInt(
(await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0',
);
const after = parseInt((await page.locator('role=status').textContent())?.replace('Seats Available', '').trim() || '0');
expect(before).not.toEqual(after);
expect(before - 1).toEqual(after);
await page2.close();
Expand Down
44 changes: 27 additions & 17 deletions apps/meteor/tests/e2e/federation/tests/messaging/dm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,9 @@ test.describe.parallel('Federation - DM Messaging', () => {
await poFederationChannel1ForUser2.content.sendMessage('hello world from server A (user 2)');
await poFederationChannel1ForUser2.content.sendMessage('hello world from server A (user 2) message 2');

await expect(poFederationChannelServer2.content.lastUserMessageBody).toHaveText(
'hello world from server A (user 2) message 2',
);
await expect(poFederationChannel1ForUser2.content.lastUserMessageBody).toHaveText(
'hello world from server A (user 2) message 2',
);
await expect(poFederationChannelServer1.content.lastUserMessageBody).toHaveText(
'hello world from server A (user 2) message 2',
);
await expect(poFederationChannelServer2.content.lastUserMessageBody).toHaveText('hello world from server A (user 2) message 2');
await expect(poFederationChannel1ForUser2.content.lastUserMessageBody).toHaveText('hello world from server A (user 2) message 2');
await expect(poFederationChannelServer1.content.lastUserMessageBody).toHaveText('hello world from server A (user 2) message 2');

await page2.close();
await pageForServer2.close();
Expand Down Expand Up @@ -480,12 +474,20 @@ test.describe.parallel('Federation - DM Messaging', () => {
await poFederationChannelServer2.sidenav.openChat(adminUsernameWithDomainFromServer1);

await poFederationChannelServer1.content.inputMessage.type(`@${userFromServer2UsernameOnly}`, { delay: 100 });
await poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`).waitFor();
await expect(poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`)).toBeVisible();
await poFederationChannelServer1.content.messagePopUpItems
.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`)
.waitFor();
await expect(
poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`),
).toBeVisible();

await poFederationChannelServer2.content.inputMessage.type(`@${constants.RC_SERVER_1.username}`, { delay: 100 });
await poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`).waitFor();
await expect(poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`)).toBeVisible();
await poFederationChannelServer2.content.messagePopUpItems
.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`)
.waitFor();
await expect(
poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`),
).toBeVisible();

await poFederationChannelServer1.content.inputMessage.fill('');
await poFederationChannelServer2.content.inputMessage.fill('');
Expand All @@ -511,12 +513,20 @@ test.describe.parallel('Federation - DM Messaging', () => {
await poFederationChannelServer1.sidenav.openChat(usernameWithDomainFromServer2);

await poFederationChannelServer2.content.inputMessage.type(`@${constants.RC_SERVER_1.username}`, { delay: 100 });
await poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`).waitFor();
await expect(poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`)).toBeVisible();
await poFederationChannelServer2.content.messagePopUpItems
.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`)
.waitFor();
await expect(
poFederationChannelServer2.content.messagePopUpItems.locator(`role=listitem >> text="${adminUsernameWithDomainFromServer1}"`),
).toBeVisible();

await poFederationChannelServer1.content.inputMessage.type(`@${userFromServer2UsernameOnly}`, { delay: 100 });
await poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`).waitFor();
await expect(poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`)).toBeVisible();
await poFederationChannelServer1.content.messagePopUpItems
.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`)
.waitFor();
await expect(
poFederationChannelServer1.content.messagePopUpItems.locator(`role=listitem >> text="${usernameWithDomainFromServer2}"`),
).toBeVisible();

await poFederationChannelServer1.content.inputMessage.fill('');
await poFederationChannelServer2.content.inputMessage.fill('');
Expand Down
Loading

0 comments on commit dd67f9c

Please sign in to comment.