Files
upstream-rocketchat/apps/meteor/tests/e2e/retention-policy.spec.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

216 lines
9.2 KiB
TypeScript

import { faker } from '@faker-js/faker';
import type { Page } from '@playwright/test';
import { createAuxContext } from './fixtures/createAuxContext';
import { Users } from './fixtures/userStates';
import { HomeChannel, HomeTeam } from './page-objects';
import { createTargetTeam, createTargetPrivateChannel, getSettingValueById, setSettingValueById } from './utils';
import { test, expect } from './utils/test';
import { timeUnitToMs, TIMEUNIT } from '../../client/lib/convertTimeUnit';
test.use({ storageState: Users.admin.state });
test.describe.serial('retention-policy', () => {
let poHomeChannel: HomeChannel;
const targetChannel = faker.string.uuid();
let targetTeam: string;
let targetGroup: string;
test.beforeAll(async ({ api }) => {
const response = await api.post('/channels.create', { name: targetChannel, members: ['user1'] });
const { channel } = await response.json();
await api.post('/channels.addOwner', { roomId: channel._id, userId: Users.user1.data._id });
targetGroup = await createTargetPrivateChannel(api);
targetTeam = await createTargetTeam(api);
});
test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);
await poHomeChannel.goto();
});
test.describe('retention policy disabled', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_Enabled', false);
});
test('should not show prune banner in channel', async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
});
test('should not show prune banner in team', async () => {
await poHomeChannel.navbar.openChat(targetTeam);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
});
test('should not show prune section on edit channel', async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await expect(poHomeChannel.tabs.editRoom.pruneAccordion).not.toBeVisible();
});
});
test.describe('retention policy enabled', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_Enabled', true);
});
test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_Enabled', false);
await setSettingValueById(api, 'RetentionPolicy_AppliesToChannels', false);
await setSettingValueById(api, 'RetentionPolicy_AppliesToGroups', false);
await setSettingValueById(api, 'RetentionPolicy_AppliesToDMs', false);
await setSettingValueById(api, 'RetentionPolicy_TTL_Channels', timeUnitToMs(TIMEUNIT.days, 30));
});
test('should not show prune banner even with retention policy setting enabled in any type of room', async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
await poHomeChannel.navbar.openChat(targetTeam);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
await poHomeChannel.navbar.openChat(targetGroup);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
await poHomeChannel.navbar.openChat('user1');
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible();
});
test('should show prune section in edit channel', async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await expect(poHomeChannel.tabs.editRoom.pruneAccordion).toBeVisible();
});
test.describe('edit-room-retention-policy permission', async () => {
let auxContext: { page: Page; poHomeChannel: HomeChannel };
test.beforeEach(async ({ browser }) => {
const { page } = await createAuxContext(browser, Users.user1);
auxContext = { page, poHomeChannel: new HomeChannel(page) };
await auxContext.poHomeChannel.navbar.openChat(targetChannel);
await auxContext.poHomeChannel.roomToolbar.openRoomInfo();
await auxContext.poHomeChannel.tabs.room.btnEdit.click();
});
test.afterEach(async () => {
await auxContext.page.close();
});
test('should not show prune section in edit channel for users without permission', async () => {
await expect(poHomeChannel.tabs.editRoom.pruneAccordion).not.toBeVisible();
});
test('users without permission should be able to edit the channel', async () => {
await auxContext.poHomeChannel.tabs.editRoom.advancedSettingsAccordion.click();
await auxContext.poHomeChannel.tabs.editRoom.checkboxReadOnly.check();
await auxContext.poHomeChannel.tabs.editRoom.btnSave.click();
await expect(auxContext.poHomeChannel.content.getSystemMessageByText('set room to read only')).toBeVisible();
});
});
test.describe('retention policy applies enabled by default', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'RetentionPolicy_AppliesToChannels', true);
await setSettingValueById(api, 'RetentionPolicy_AppliesToGroups', true);
await setSettingValueById(api, 'RetentionPolicy_AppliesToDMs', true);
});
test('should prune old messages checkbox enabled by default in channel and show retention policy banner', async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible();
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.editRoom.pruneAccordion.click();
await expect(poHomeChannel.tabs.editRoom.checkboxPruneMessages).toBeChecked();
});
test('should prune old messages checkbox enabled by default in team and show retention policy banner', async ({ page }) => {
const poHomeTeam = new HomeTeam(page);
await poHomeTeam.navbar.openChat(targetTeam);
await expect(poHomeTeam.content.channelRetentionPolicyWarning).toBeVisible();
await poHomeTeam.headerToolbar.openTeamInfo();
await poHomeTeam.tabs.room.btnEdit.click();
await poHomeTeam.tabs.editRoom.pruneAccordion.click();
await expect(poHomeTeam.tabs.editRoom.checkboxPruneMessages).toBeChecked();
});
test('should prune old messages checkbox enabled by default in group and show retention policy banner', async () => {
await poHomeChannel.navbar.openChat(targetGroup);
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible();
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.editRoom.pruneAccordion.click();
await expect(poHomeChannel.tabs.editRoom.checkboxPruneMessages).toBeChecked();
});
test('should show retention policy banner in DMs', async () => {
await poHomeChannel.navbar.openChat('user1');
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible();
});
});
test.describe('retention policy override', () => {
let ignoreThreadsSetting: boolean;
test.beforeAll(async ({ api }) => {
ignoreThreadsSetting = (await getSettingValueById(api, 'RetentionPolicy_DoNotPruneThreads')) as boolean;
expect((await setSettingValueById(api, 'RetentionPolicy_TTL_Channels', timeUnitToMs(TIMEUNIT.days, 15))).status()).toBe(200);
});
test.beforeEach(async () => {
await poHomeChannel.navbar.openChat(targetChannel);
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.editRoom.pruneAccordion.click();
});
test('should display the default max age in edit channel', async () => {
await poHomeChannel.tabs.editRoom.checkboxOverrideGlobalRetention.click();
await expect(poHomeChannel.tabs.editRoom.getMaxAgeLabel('15')).toBeVisible();
});
test('should display overridden retention max age value', async () => {
await poHomeChannel.tabs.editRoom.checkboxOverrideGlobalRetention.click();
await poHomeChannel.tabs.editRoom.inputRetentionMaxAge.fill('365');
await poHomeChannel.tabs.editRoom.btnSave.click();
await poHomeChannel.toastMessage.dismissToast();
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.editRoom.pruneAccordion.click();
await expect(poHomeChannel.tabs.editRoom.getMaxAgeLabel('15')).toBeVisible();
await expect(poHomeChannel.tabs.editRoom.inputRetentionMaxAge).toHaveValue('365');
});
test('should ignore threads be checked accordingly with the global default value', async () => {
await expect(poHomeChannel.tabs.editRoom.checkboxIgnoreThreads).toBeChecked({ checked: ignoreThreadsSetting });
});
test('should override ignore threads default value', async () => {
await poHomeChannel.tabs.editRoom.checkboxIgnoreThreads.click();
await poHomeChannel.tabs.editRoom.btnSave.click();
await poHomeChannel.toastMessage.dismissToast();
await poHomeChannel.roomToolbar.openRoomInfo();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.editRoom.pruneAccordion.click();
await expect(poHomeChannel.tabs.editRoom.checkboxIgnoreThreads).toBeChecked({ checked: !ignoreThreadsSetting });
});
});
});
});