Skip to content

Commit

Permalink
test: updated test files to use setting util
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Nov 27, 2024
1 parent 2903203 commit 3454423
Show file tree
Hide file tree
Showing 34 changed files with 232 additions and 239 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
import { Registration } from './page-objects';
import { setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.describe.serial('Forget session on window close setting', () => {
Expand All @@ -13,7 +14,7 @@ test.describe.serial('Forget session on window close setting', () => {

test.describe('Setting off', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
await setSettingValueById(api, 'Accounts_ForgetUserSessionOnWindowClose', false);
});

test('Login using credentials and reload to stay logged in', async ({ page, context }) => {
Expand All @@ -33,11 +34,11 @@ test.describe.serial('Forget session on window close setting', () => {
// TODO: Fix this test
test.describe.skip('Setting on', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true });
await setSettingValueById(api, 'Accounts_ForgetUserSessionOnWindowClose', true);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
await setSettingValueById(api, 'Accounts_ForgetUserSessionOnWindowClose', false);
});

test('Login using credentials and reload to get logged out', async ({ page, context }) => {
Expand Down
52 changes: 26 additions & 26 deletions apps/meteor/tests/e2e/e2e-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createAuxContext } from './fixtures/createAuxContext';
import injectInitialData from './fixtures/inject-initial-data';
import { Users, storeState, restoreState } from './fixtures/userStates';
import { AccountProfile, HomeChannel } from './page-objects';
import { setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand All @@ -22,13 +23,11 @@ test.describe.serial('e2e-encryption initial setup', () => {
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
await Promise.all([setSettingValueById(api, 'E2E_Enable', true), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', true)]);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', false), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

test.afterEach(async ({ api }) => {
Expand Down Expand Up @@ -239,19 +238,18 @@ test.describe.serial('e2e-encryption', () => {
test.use({ storageState: Users.userE2EE.state });

test.beforeEach(async ({ page, api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await setSettingValueById(api, 'E2E_Enable', true);

poHomeChannel = new HomeChannel(page);
await page.goto('/home');
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
await setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', true);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', false), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

test('expect create a private channel encrypted and send an encrypted message', async ({ page }) => {
Expand Down Expand Up @@ -504,8 +502,10 @@ test.describe.serial('e2e-encryption', () => {

test.describe('File Encryption', async () => {
test.afterAll(async ({ api }) => {
await api.post('/settings/FileUpload_MediaTypeWhiteList', { value: '' });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'image/svg+xml' });
await Promise.all([
setSettingValueById(api, 'FileUpload_MediaTypeWhiteList', ''),
setSettingValueById(api, 'FileUpload_MediaTypeBlackList', 'image/svg+xml'),
]);
});

test('File and description encryption', async ({ page }) => {
Expand Down Expand Up @@ -566,7 +566,7 @@ test.describe.serial('e2e-encryption', () => {
});

await test.step('set whitelisted media type setting', async () => {
await api.post('/settings/FileUpload_MediaTypeWhiteList', { value: 'text/plain' });
await setSettingValueById(api, 'FileUpload_MediaTypeWhiteList', 'text/plain');
});

await test.step('send text file again with whitelist setting set', async () => {
Expand All @@ -581,7 +581,7 @@ test.describe.serial('e2e-encryption', () => {
});

await test.step('set blacklisted media type setting to not accept application/octet-stream media type', async () => {
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'application/octet-stream' });
await setSettingValueById(api, 'FileUpload_MediaTypeBlackList', 'application/octet-stream');
});

await test.step('send text file again with blacklisted setting set, file upload should fail', async () => {
Expand All @@ -598,13 +598,17 @@ test.describe.serial('e2e-encryption', () => {

test.describe('File encryption setting disabled', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable_Encrypt_Files', { value: false });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'application/octet-stream' });
await Promise.all([
setSettingValueById(api, 'E2E_Enable_Encrypt_Files', false),
setSettingValueById(api, 'FileUpload_MediaTypeBlackList', 'application/octet-stream'),
]);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable_Encrypt_Files', { value: true });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'image/svg+xml' });
await Promise.all([
setSettingValueById(api, 'E2E_Enable_Encrypt_Files', true),
setSettingValueById(api, 'FileUpload_MediaTypeBlackList', 'image/svg+xml'),
]);
});

test('Upload file without encryption in e2ee room', async ({ page }) => {
Expand Down Expand Up @@ -682,11 +686,11 @@ test.describe.serial('e2e-encryption', () => {
await page.goto('/home');
});
test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
await setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', true);
});

test('expect slash commands to be disabled in an e2ee room', async ({ page }) => {
Expand Down Expand Up @@ -845,13 +849,11 @@ test.describe.serial('e2ee room setup', () => {
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', true), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', false), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

test.afterEach(async ({ api }) => {
Expand Down Expand Up @@ -1034,13 +1036,11 @@ test.describe('e2ee support legacy formats', () => {
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', true), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
await Promise.all([setSettingValueById(api, 'E2E_Enable', false), setSettingValueById(api, 'E2E_Allow_Unencrypted_Messages', false)]);
});

// ->>>>>>>>>>>Not testing upload since it was not implemented in the legacy format
Expand Down
47 changes: 29 additions & 18 deletions apps/meteor/tests/e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Page } from '@playwright/test';

import { IS_EE } from './config/constants';
import { Users } from './fixtures/userStates';
import { setSettingValueById } from './utils';
import { expect, test } from './utils/test';

const CardIds = {
Expand All @@ -27,8 +28,11 @@ test.describe.serial('homepage', () => {
});

test.afterAll(async ({ api }) => {
expect((await api.post('/settings/Layout_Home_Custom_Block_Visible', { value: false })).status()).toBe(200);
expect((await api.post('/settings/Layout_Custom_Body_Only', { value: false })).status()).toBe(200);
await Promise.all([
setSettingValueById(api, 'Layout_Home_Custom_Block_Visible', false),
setSettingValueById(api, 'Layout_Custom_Body_Only', false),
]);

await adminPage.close();
});

Expand All @@ -44,7 +48,7 @@ test.describe.serial('homepage', () => {

test.describe('custom body with empty custom content', async () => {
test.beforeAll(async ({ api }) => {
await expect((await api.post('/settings/Layout_Home_Body', { value: '' })).status()).toBe(200);
await setSettingValueById(api, 'Layout_Home_Body', '');
});

test('visibility and button functionality in custom body with empty custom content', async () => {
Expand All @@ -65,7 +69,7 @@ test.describe.serial('homepage', () => {

test.describe('custom body with custom content', () => {
test.beforeAll(async ({ api }) => {
await expect((await api.post('/settings/Layout_Home_Body', { value: 'Hello admin' })).status()).toBe(200);
await setSettingValueById(api, 'Layout_Home_Body', { value: 'Hello admin' });
});

test('visibility and button functionality in custom body with custom content', async () => {
Expand All @@ -83,9 +87,11 @@ test.describe.serial('homepage', () => {
test.skip(!IS_EE, 'Enterprise Only');

test.beforeAll(async ({ api }) => {
await expect((await api.post('/settings/Layout_Home_Body', { value: 'Hello admin' })).status()).toBe(200);
await expect((await api.post('/settings/Layout_Home_Custom_Block_Visible', { value: true })).status()).toBe(200);
await expect((await api.post('/settings/Layout_Custom_Body_Only', { value: true })).status()).toBe(200);
await Promise.all([
setSettingValueById(api, 'Layout_Home_Body', 'Hello admin'),
setSettingValueById(api, 'Layout_Home_Custom_Block_Visible', true),
setSettingValueById(api, 'Layout_Custom_Body_Only', true),
]);
});

test('display custom content only', async () => {
Expand All @@ -110,7 +116,7 @@ test.describe.serial('homepage', () => {
const notVisibleCards = [CardIds.Users, CardIds.Custom];

test.beforeAll(async ({ api, browser }) => {
expect((await api.post('/settings/Layout_Home_Body', { value: '' })).status()).toBe(200);
await setSettingValueById(api, 'Layout_Home_Body', { value: '' });
regularUserPage = await browser.newPage({ storageState: Users.user2.state });
await regularUserPage.goto('/home');
await regularUserPage.waitForSelector('[data-qa-id="home-header"]');
Expand Down Expand Up @@ -148,16 +154,17 @@ test.describe.serial('homepage', () => {

test.describe('custom values', () => {
test.beforeAll(async ({ api }) => {
expect((await api.post('/settings/Site_Name', { value: 'NewSiteName' })).status()).toBe(200);
expect((await api.post('/settings/Layout_Home_Title', { value: 'NewTitle' })).status()).toBe(200);
await Promise.all([
setSettingValueById(api, 'Site_Name', 'NewSiteName'),
setSettingValueById(api, 'Layout_Home_Title', 'NewTitle'),
]);

await regularUserPage.goto('/home');
await regularUserPage.waitForSelector('[data-qa-id="home-header"]');
});

test.afterAll(async ({ api }) => {
expect((await api.post('/settings/Site_Name', { value: 'Rocket.Chat' })).status()).toBe(200);
expect((await api.post('/settings/Layout_Home_Title', { value: 'Home' })).status()).toBe(200);
await Promise.all([setSettingValueById(api, 'Site_Name', 'Rocket.Chat'), setSettingValueById(api, 'Layout_Home_Title', 'Home')]);
});

test('expect welcome text and header text to be correct', async () => {
Expand All @@ -173,16 +180,20 @@ test.describe.serial('homepage', () => {

test.describe('custom body with content', () => {
test.beforeAll(async ({ api }) => {
expect((await api.post('/settings/Layout_Home_Body', { value: 'Hello' })).status()).toBe(200);
expect((await api.post('/settings/Layout_Home_Custom_Block_Visible', { value: true })).status()).toBe(200);
await Promise.all([
setSettingValueById(api, 'Layout_Home_Body', 'Hello'),
setSettingValueById(api, 'Layout_Home_Custom_Block_Visible', true),
]);

await regularUserPage.goto('/home');
await regularUserPage.waitForSelector('[data-qa-id="home-header"]');
});

test.afterAll(async ({ api }) => {
expect((await api.post('/settings/Layout_Home_Body', { value: '' })).status()).toBe(200);
expect((await api.post('/settings/Layout_Home_Custom_Block_Visible', { value: false })).status()).toBe(200);
await Promise.all([
setSettingValueById(api, 'Layout_Home_Body', ''),
setSettingValueById(api, 'Layout_Home_Custom_Block_Visible', false),
]);
});

test('expect custom body to be visible', async () => {
Expand All @@ -193,11 +204,11 @@ test.describe.serial('homepage', () => {
test.skip(!IS_EE, 'Enterprise Only');

test.beforeAll(async ({ api }) => {
expect((await api.post('/settings/Layout_Custom_Body_Only', { value: true })).status()).toBe(200);
await setSettingValueById(api, 'Layout_Custom_Body_Only', true);
});

test.afterAll(async ({ api }) => {
expect((await api.post('/settings/Layout_Custom_Body_Only', { value: false })).status()).toBe(200);
await setSettingValueById(api, 'Layout_Custom_Body_Only', false);
});

test('expect default layout not be visible and custom body visible', async () => {
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/tests/e2e/omnichannel/omnichannel-agents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IS_EE } from '../config/constants';
import { Users } from '../fixtures/userStates';
import { OmnichannelAgents } from '../page-objects';
import { setSettingValueById } from '../utils';
import { createDepartment } from '../utils/omnichannel/departments';
import { test, expect } from '../utils/test';

Expand All @@ -26,9 +27,9 @@ test.describe.serial('OC - Manage Agents', () => {
// Ensure that there is no leftover data even if test fails
test.afterEach(async ({ api }) => {
await api.delete('/livechat/users/agent/user1');
await api.post('/settings/Omnichannel_enable_department_removal', { value: true }).then((res) => expect(res.status()).toBe(200));
await setSettingValueById(api, 'Omnichannel_enable_department_removal', true);
await department.delete();
await api.post('/settings/Omnichannel_enable_department_removal', { value: false }).then((res) => expect(res.status()).toBe(200));
await setSettingValueById(api, 'Omnichannel_enable_department_removal', false);
});

test('OC - Manage Agents - Add, search and remove using table', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IS_EE } from '../config/constants';
import { Users } from '../fixtures/userStates';
import { OmnichannelLivechatAppearance } from '../page-objects/omnichannel-livechat-appearance';
import { setSettingValueById } from '../utils';
import { test, expect } from '../utils/test';

test.use({ storageState: Users.admin.state });
Expand All @@ -19,8 +20,8 @@ test.describe.serial('OC - Livechat Appearance', () => {

test.afterAll(async ({ api }) => {
const res = await Promise.all([
api.post('/settings/Livechat_hide_system_messages', { value: ['uj', 'ul', 'livechat-close'] }),
api.post('/settings/Livechat_background', { value: '' }),
setSettingValueById(api, 'Livechat_hide_system_messages', ['uj', 'ul', 'livechat-close']),
setSettingValueById(api, 'Livechat_background', ''),
]);

if (res.some((r) => r.status() !== 200)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IS_EE } from '../config/constants';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { OmnichannelLiveChat, HomeChannel } from '../page-objects';
import { setSettingValueById } from '../utils';
import { test, expect } from '../utils/test';

test.describe('omnichannel-auto-onhold-chat-closing', () => {
Expand All @@ -18,9 +19,9 @@ test.describe('omnichannel-auto-onhold-chat-closing', () => {
test.beforeAll(async ({ api, browser }) => {
await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_auto_close_on_hold_chats_timeout', { value: 5 }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_allow_manual_on_hold', { value: true }).then((res) => expect(res.status()).toBe(200)),
setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection'),
setSettingValueById(api, 'Livechat_auto_close_on_hold_chats_timeout', 5),
setSettingValueById(api, 'Livechat_allow_manual_on_hold', true),
]);

const { page } = await createAuxContext(browser, Users.user1);
Expand All @@ -31,8 +32,8 @@ test.describe('omnichannel-auto-onhold-chat-closing', () => {

await Promise.all([
api.delete('/livechat/users/agent/user1').then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_auto_close_on_hold_chats_timeout', { value: 3600 }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_allow_manual_on_hold', { value: false }).then((res) => expect(res.status()).toBe(200)),
setSettingValueById(api, 'Livechat_auto_close_on_hold_chats_timeout', 3600),
setSettingValueById(api, 'Livechat_allow_manual_on_hold', false),
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IS_EE } from '../config/constants';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { OmnichannelLiveChat, HomeChannel } from '../page-objects';
import { setSettingValueById } from '../utils';
import { test, expect } from '../utils/test';

test.describe('omnichannel-auto-transfer-unanswered-chat', () => {
Expand All @@ -20,8 +21,8 @@ test.describe('omnichannel-auto-transfer-unanswered-chat', () => {
await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }).then((res) => expect(res.status()).toBe(200)),
api.post('/livechat/users/agent', { username: 'user2' }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }).then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_auto_transfer_chat_timeout', { value: 5 }).then((res) => expect(res.status()).toBe(200)),
setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection'),
setSettingValueById(api, 'Livechat_auto_transfer_chat_timeout', 5),
]);

const { page } = await createAuxContext(browser, Users.user1);
Expand All @@ -38,7 +39,7 @@ test.describe('omnichannel-auto-transfer-unanswered-chat', () => {
await Promise.all([
api.delete('/livechat/users/agent/user1').then((res) => expect(res.status()).toBe(200)),
api.delete('/livechat/users/agent/user2').then((res) => expect(res.status()).toBe(200)),
api.post('/settings/Livechat_auto_transfer_chat_timeout', { value: 0 }).then((res) => expect(res.status()).toBe(200)),
setSettingValueById(api, 'Livechat_auto_transfer_chat_timeout', 0),
]);
});

Expand Down
Loading

0 comments on commit 3454423

Please sign in to comment.