From 8fdb9ad35896c16711699a42970d45bb48eb2ef5 Mon Sep 17 00:00:00 2001 From: Julien Tant <785518+JulienTant@users.noreply.github.com> Date: Fri, 31 Jan 2025 19:50:08 -0700 Subject: [PATCH] Fix Playwright tests (#30079) Automatic Merge --- e2e-tests/playwright/support/flag.ts | 13 ++++++++++--- e2e-tests/playwright/support/test_fixture.ts | 11 ++++++++++- .../ui/components/channels/scheduled_draft_modal.ts | 9 ++++++++- .../ui/components/channels/search_popover.ts | 11 +++++++++++ .../support/ui/components/channels/sidebar_right.ts | 3 ++- .../channels/search/search_box_suggestions.spec.ts | 8 +++++--- .../channels/search/team_selector.spec.ts | 12 ++---------- 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/e2e-tests/playwright/support/flag.ts b/e2e-tests/playwright/support/flag.ts index f3288bb841..2f56bb64bc 100644 --- a/e2e-tests/playwright/support/flag.ts +++ b/e2e-tests/playwright/support/flag.ts @@ -32,7 +32,7 @@ export async function shouldHaveFeatureFlag(name: string, value: string | boolea export async function shouldRunInLinux() { const platform = os.platform(); - await expect(platform, 'Run in Linux or Playwright docker image only').toBe('linux'); + expect(platform, 'Run in Linux or Playwright docker image only').toBe('linux'); } export async function ensureLicense() { @@ -41,7 +41,7 @@ export async function ensureLicense() { if (license?.IsLicensed !== 'true') { const config = await adminClient.getClientConfigOld(); - await expect( + expect( config.ServiceEnvironment === 'dev', 'The trial license request fails in the local development environment. Please manually upload the test license.', ).toBeFalsy(); @@ -51,7 +51,7 @@ export async function ensureLicense() { license = await adminClient.getClientLicenseOld(); } - await expect(license?.IsLicensed === 'true', 'Ensure server has license').toBeTruthy(); + expect(license?.IsLicensed === 'true', 'Ensure server has license').toBeTruthy(); } export async function requestTrialLicense() { @@ -75,3 +75,10 @@ export async function skipIfNoLicense() { test.skip(license.IsLicensed === 'false', 'Skipping test - server not licensed'); } + +export async function skipIfFeatureFlagNotSet(name: string, value: string | boolean) { + const {adminClient} = await getAdminClient(); + const cfg = await adminClient.getConfig(); + + test.skip(cfg.FeatureFlags[name] !== value, `Skipping test - Feature Flag ${name} needs to be set to ${value}`); +} diff --git a/e2e-tests/playwright/support/test_fixture.ts b/e2e-tests/playwright/support/test_fixture.ts index 8f01931e31..f78d0c4dbe 100644 --- a/e2e-tests/playwright/support/test_fixture.ts +++ b/e2e-tests/playwright/support/test_fixture.ts @@ -3,7 +3,14 @@ import {AxeResults} from 'axe-core'; import AxeBuilder from '@axe-core/playwright'; import {TestBrowser} from './browser_context'; -import {shouldHaveCallsEnabled, shouldHaveFeatureFlag, shouldRunInLinux, ensureLicense, skipIfNoLicense} from './flag'; +import { + shouldHaveCallsEnabled, + shouldHaveFeatureFlag, + shouldRunInLinux, + ensureLicense, + skipIfNoLicense, + skipIfFeatureFlagNotSet, +} from './flag'; import {initSetup, getAdminClient} from './server'; import {hideDynamicChannelsContent, waitForAnimationEnd, waitUntil} from './test_action'; import pages from './ui/pages'; @@ -46,6 +53,7 @@ class PlaywrightExtended { readonly shouldRunInLinux; readonly ensureLicense; readonly skipIfNoLicense; + readonly skipIfFeatureFlagNotSet; // ./server readonly getAdminClient; @@ -81,6 +89,7 @@ class PlaywrightExtended { this.shouldRunInLinux = shouldRunInLinux; this.ensureLicense = ensureLicense; this.skipIfNoLicense = skipIfNoLicense; + this.skipIfFeatureFlagNotSet = skipIfFeatureFlagNotSet; // ./server this.initSetup = initSetup; diff --git a/e2e-tests/playwright/support/ui/components/channels/scheduled_draft_modal.ts b/e2e-tests/playwright/support/ui/components/channels/scheduled_draft_modal.ts index 0c05051929..89f3b4fd3c 100644 --- a/e2e-tests/playwright/support/ui/components/channels/scheduled_draft_modal.ts +++ b/e2e-tests/playwright/support/ui/components/channels/scheduled_draft_modal.ts @@ -47,6 +47,7 @@ export default class ScheduledDraftModal { await this.dateInput.click(); const pacificDate = this.getPacificDate(); + const originDate = new Date(pacificDate.getTime()); // If dayFromToday is provided, add days to the current date if (dayFromToday) { @@ -57,7 +58,13 @@ export default class ScheduledDraftModal { const month = pacificDate.toLocaleString('default', {month: 'long'}); const dayOfWeek = pacificDate.toLocaleDateString('en-US', {weekday: 'long'}); - await this.dateLocator(day, month, dayOfWeek).click(); + const dl = this.dateLocator(day, month, dayOfWeek); + + // If the date is not visible and the month has changed, click the next month button + if (!(await dl.isVisible()) && pacificDate.getMonth() !== originDate.getMonth()) { + this.container.locator('button[aria-label="Go to next month"]').click(); + } + await dl.click(); } async confirm() { diff --git a/e2e-tests/playwright/support/ui/components/channels/search_popover.ts b/e2e-tests/playwright/support/ui/components/channels/search_popover.ts index 05e52cd8d3..e1f5903cf8 100644 --- a/e2e-tests/playwright/support/ui/components/channels/search_popover.ts +++ b/e2e-tests/playwright/support/ui/components/channels/search_popover.ts @@ -12,6 +12,7 @@ export default class SearchPopover { readonly searchBoxClose; readonly selectedSuggestion; readonly searchHints; + readonly clearButton; constructor(container: Locator) { this.container = container; @@ -22,6 +23,16 @@ export default class SearchPopover { this.searchBoxClose = container.getByTestId('searchBoxClose'); this.selectedSuggestion = container.locator('.suggestion--selected').locator('.suggestion-list__main'); this.searchHints = container.locator('#searchHints'); + this.clearButton = container.locator('.input-clear-x'); + } + + // clearIfPossible clears the search input if the clear button is visible. Returns true if the clear button was clicked. + async clearIfPossible() { + if (await this.clearButton.isVisible()) { + await this.clearButton.click(); + return true; + } + return false; } async toBeVisible() { diff --git a/e2e-tests/playwright/support/ui/components/channels/sidebar_right.ts b/e2e-tests/playwright/support/ui/components/channels/sidebar_right.ts index bece0305e6..cb9b28a5c4 100644 --- a/e2e-tests/playwright/support/ui/components/channels/sidebar_right.ts +++ b/e2e-tests/playwright/support/ui/components/channels/sidebar_right.ts @@ -29,7 +29,8 @@ export default class ChannelsSidebarRight { this.scheduledDraftChannelInfoMessageText = container.locator('span:has-text("Message scheduled for")'); this.rhsPostBody = container.locator('.post-message__text'); this.postCreate = new components.ChannelsPostCreate(container.getByTestId('comment-create'), true); - this.closeButton = container.locator('#rhsCloseButton'); + this.closeButton = container.locator('.sidebar--right__close'); + this.editTextbox = container.locator('#edit_textbox'); this.postEdit = new components.ChannelsPostEdit(container.locator('.post-edit__container')); this.currentVersionEditedPosttext = (postID: any) => container.locator(`#rhsPostMessageText_${postID} p`); diff --git a/e2e-tests/playwright/tests/functional/channels/search/search_box_suggestions.spec.ts b/e2e-tests/playwright/tests/functional/channels/search/search_box_suggestions.spec.ts index 278cbdfb27..621fa7df75 100644 --- a/e2e-tests/playwright/tests/functional/channels/search/search_box_suggestions.spec.ts +++ b/e2e-tests/playwright/tests/functional/channels/search/search_box_suggestions.spec.ts @@ -22,7 +22,7 @@ test('Search box suggestion must be case insensitive', async ({pw}) => { // Should work as expected when using lowercase // # Type in lowercase "off" to search for the "Off-Topic" channel - const {searchInput} = await channelsPage.searchPopover; + const {searchInput} = channelsPage.searchPopover; await searchInput.pressSequentially(`In:${searchWord}`); // * The suggestion should be visible @@ -37,10 +37,12 @@ test('Search box suggestion must be case insensitive', async ({pw}) => { await expect(channelsPage.globalHeader.searchBox.getByText(searchOutput, {exact: true})).toBeVisible(); // Should work as expected when using uppercase - // # Close then open the search UI - await channelsPage.globalHeader.closeSearch(); + // # Open the search bar await channelsPage.globalHeader.openSearch(); + // # Clear its content + await channelsPage.searchPopover.clearIfPossible(); + // # Type in uppercase "OFF" to search for the "Off-Topic" channel await searchInput.pressSequentially(`In:${searchWord.toUpperCase()}`); diff --git a/e2e-tests/playwright/tests/functional/channels/search/team_selector.spec.ts b/e2e-tests/playwright/tests/functional/channels/search/team_selector.spec.ts index e6696990de..8539b1afef 100644 --- a/e2e-tests/playwright/tests/functional/channels/search/team_selector.spec.ts +++ b/e2e-tests/playwright/tests/functional/channels/search/team_selector.spec.ts @@ -5,17 +5,9 @@ import {createRandomTeam} from '@e2e-support/server'; import {expect, test} from '@e2e-support/test_fixture'; test('team selector must show all my teams', async ({pw}) => { - const {adminClient, adminConfig, user, team} = await pw.initSetup(); + pw.skipIfFeatureFlagNotSet('ExperimentalCrossTeamSearch', true); - // # Enable Cross Team Search Feature Flag - const newConfig = { - ...adminConfig, - FeatureFlags: { - ...adminConfig.FeatureFlags, - ExperimentalCrossTeamSearch: true, - }, - }; - await adminClient.updateConfig(newConfig); + const {adminClient, user, team} = await pw.initSetup(); // # create 2 more teams and add the user to them const teams = [team];