fix: Overriding Retention Policy not working (#32454)
Co-authored-by: Guilherme Gazzo <5263975+ggazzo@users.noreply.github.com>pull/32444/head^2
parent
f83bd56cc5
commit
fa55c49a49
@ -0,0 +1,5 @@ |
||||
--- |
||||
'@rocket.chat/meteor': patch |
||||
--- |
||||
|
||||
Fixes an issue not allowing override retention policy in channels |
||||
@ -1,14 +0,0 @@ |
||||
import moment from 'moment'; |
||||
import { useCallback } from 'react'; |
||||
|
||||
export const useFormatRelativeTime = (): ((timeMs: number) => string) => |
||||
useCallback((timeMs: number) => { |
||||
moment.relativeTimeThreshold('s', 60); |
||||
moment.relativeTimeThreshold('ss', 0); |
||||
moment.relativeTimeThreshold('m', 60); |
||||
moment.relativeTimeThreshold('h', 24); |
||||
moment.relativeTimeThreshold('d', 31); |
||||
moment.relativeTimeThreshold('M', 12); |
||||
|
||||
return moment.duration(timeMs).humanize(); |
||||
}, []); |
||||
@ -0,0 +1,138 @@ |
||||
import { Users } from './fixtures/userStates'; |
||||
import { HomeChannel } from './page-objects'; |
||||
import { createTargetChannel, createTargetPrivateChannel, setSettingValueById } from './utils'; |
||||
import { test, expect } from './utils/test'; |
||||
|
||||
test.use({ storageState: Users.admin.state }); |
||||
|
||||
test.describe.serial('retention-policy', () => { |
||||
let poHomeChannel: HomeChannel; |
||||
let targetChannel: string; |
||||
let targetGroup: string; |
||||
|
||||
test.beforeAll(async ({ api }) => { |
||||
targetChannel = await createTargetChannel(api); |
||||
targetGroup = await createTargetPrivateChannel(api); |
||||
}) |
||||
|
||||
test.beforeEach(async ({ page }) => { |
||||
poHomeChannel = new HomeChannel(page); |
||||
|
||||
await page.goto('/home'); |
||||
}); |
||||
|
||||
test.describe('retention policy disabled', () => { |
||||
test('should not show prune banner in channel', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
|
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible(); |
||||
}); |
||||
|
||||
test('should not show prune section on edit channel', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
|
||||
await expect(poHomeChannel.tabs.room.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_MaxAge_Channels', 30); |
||||
}); |
||||
|
||||
test('should not show prune banner even with retention policy setting enabled in any type of room', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible(); |
||||
|
||||
await poHomeChannel.sidenav.openChat(targetGroup); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible(); |
||||
|
||||
await poHomeChannel.sidenav.openChat('user1'); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).not.toBeVisible(); |
||||
}); |
||||
|
||||
test('should show prune section in edit channel', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
|
||||
await expect(poHomeChannel.tabs.room.pruneAccordion).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.sidenav.openChat(targetChannel); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible(); |
||||
|
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
await poHomeChannel.tabs.room.pruneAccordion.click(); |
||||
await expect(poHomeChannel.tabs.room.checkboxPruneMessages).toBeChecked(); |
||||
}); |
||||
|
||||
test('should prune old messages checkbox enabled by default in group and show retention policy banner', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetGroup); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible(); |
||||
|
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
await poHomeChannel.tabs.room.pruneAccordion.click(); |
||||
await expect(poHomeChannel.tabs.room.checkboxPruneMessages).toBeChecked(); |
||||
}); |
||||
|
||||
test('should show retention policy banner in DMs', async () => { |
||||
await poHomeChannel.sidenav.openChat('user1'); |
||||
await expect(poHomeChannel.content.channelRetentionPolicyWarning).toBeVisible(); |
||||
}); |
||||
}); |
||||
|
||||
test.describe('retention policy override', () => { |
||||
test.beforeAll(async ({ api }) => { |
||||
expect((await setSettingValueById(api, 'RetentionPolicy_MaxAge_Channels', 15)).status()).toBe(200); |
||||
}); |
||||
|
||||
test('should display the default max age in edit channel', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
await poHomeChannel.tabs.room.pruneAccordion.click(); |
||||
await poHomeChannel.tabs.room.checkboxOverrideGlobalRetention.click(); |
||||
|
||||
await expect(poHomeChannel.tabs.room.getMaxAgeLabel('15')).toBeVisible(); |
||||
}); |
||||
|
||||
test('should display overridden retention max age value', async () => { |
||||
await poHomeChannel.sidenav.openChat(targetChannel); |
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
await poHomeChannel.tabs.room.pruneAccordion.click(); |
||||
await poHomeChannel.tabs.room.checkboxOverrideGlobalRetention.click(); |
||||
await poHomeChannel.tabs.room.inputRetentionMaxAge.fill('365'); |
||||
await poHomeChannel.tabs.room.btnSave.click(); |
||||
await poHomeChannel.dismissToast(); |
||||
|
||||
await poHomeChannel.tabs.btnRoomInfo.click(); |
||||
await poHomeChannel.tabs.room.btnEdit.click(); |
||||
await poHomeChannel.tabs.room.pruneAccordion.click(); |
||||
|
||||
await expect(poHomeChannel.tabs.room.getMaxAgeLabel('15')).toBeVisible(); |
||||
await expect(poHomeChannel.tabs.room.inputRetentionMaxAge).toHaveValue('365'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue