From 84f10a8773ffb5e47ee5562f4cd283ad37d710f8 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Mon, 2 Sep 2024 04:48:40 -0600 Subject: [PATCH] Refactor/migrate/autocomplete database speabase specs to ts (#27837) * refactor: migrate database/users_spec.js to ts - migrate file autocomplete/database/users_spec.js to typescripts - udpate system.d.ts data type adding type for shouldHaveElasticsearchDisabled * refactor: migrate users_in_channel_switcher_spec.js - migrate file users_in_channel_switcher_spec to typescript - fix issue with data type on file autocomplete/helpers.ts function verifySuggestionAtChannelSwitcher - fix issue with data type on file autocomplete/common_test.ts function doTestQuickChannelSwitcher * refactor: migrate users_in_message_input_box_spec to ts - migrate file database/users_in_message_input_box_spec.js to typescript - migrate file support/ui/suggestion_list.js to typescript and update docs and type definitions - update references to doTestPostextbox function - update references to verifySuggestionAtPostTextbox function --------- Co-authored-by: Mattermost Build --- .../channels/autocomplete/common_test.ts | 8 +-- ...c.js => users_in_channel_switcher_spec.ts} | 4 +- ....js => users_in_message_input_box_spec.ts} | 4 +- .../database/{users_spec.js => users_spec.ts} | 6 +- .../channels/autocomplete/helpers.ts | 4 +- .../cypress/tests/support/api/system.d.ts | 8 +++ .../tests/support/ui/suggestion_list.d.ts | 41 ----------- .../tests/support/ui/suggestion_list.js | 36 ---------- .../tests/support/ui/suggestion_list.ts | 69 +++++++++++++++++++ 9 files changed, 90 insertions(+), 90 deletions(-) rename e2e-tests/cypress/tests/integration/channels/autocomplete/database/{users_in_channel_switcher_spec.js => users_in_channel_switcher_spec.ts} (97%) rename e2e-tests/cypress/tests/integration/channels/autocomplete/database/{users_in_message_input_box_spec.js => users_in_message_input_box_spec.ts} (97%) rename e2e-tests/cypress/tests/integration/channels/autocomplete/database/{users_spec.js => users_spec.ts} (91%) delete mode 100644 e2e-tests/cypress/tests/support/ui/suggestion_list.d.ts delete mode 100644 e2e-tests/cypress/tests/support/ui/suggestion_list.js create mode 100644 e2e-tests/cypress/tests/support/ui/suggestion_list.ts diff --git a/e2e-tests/cypress/tests/integration/channels/autocomplete/common_test.ts b/e2e-tests/cypress/tests/integration/channels/autocomplete/common_test.ts index 6971713024..d664ad0dc1 100644 --- a/e2e-tests/cypress/tests/integration/channels/autocomplete/common_test.ts +++ b/e2e-tests/cypress/tests/integration/channels/autocomplete/common_test.ts @@ -16,13 +16,13 @@ import { verifySuggestionAtPostTextbox, } from './helpers'; -export function doTestPostextbox(mention: string, ...suggestion: Cypress.UserProfile[]) { +export function doTestPostextbox(mention: string, ...suggestion: SimpleUser[]) { getPostTextboxInput(); startAtMention(mention); verifySuggestionAtPostTextbox(...suggestion); } -export function doTestQuickChannelSwitcher(mention: string, ...suggestion: Cypress.UserProfile[]) { +export function doTestQuickChannelSwitcher(mention: string, ...suggestion: SimpleUser[]) { getQuickChannelSwitcherInput(); startAtMention(mention); verifySuggestionAtChannelSwitcher(...suggestion); @@ -49,10 +49,10 @@ export function doTestUserChannelSection(prefix: string, testTeam: Cypress.Team, type(`@${prefix}odinson`); // * Thor should be a channel member - cy.uiVerifyAtMentionInSuggestionList(thor as Cypress.UserProfile, true); + cy.uiVerifyAtMentionInSuggestionList(thor, true); // * Loki should NOT be a channel member - cy.uiVerifyAtMentionInSuggestionList(loki as Cypress.UserProfile, false); + cy.uiVerifyAtMentionInSuggestionList(loki, false); } export function doTestDMChannelSidebar(testUsers: Record) { diff --git a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.js b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.ts similarity index 97% rename from e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.js rename to e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.ts index 9173a72184..13a81fb86a 100644 --- a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_channel_switcher_spec.ts @@ -12,11 +12,11 @@ import {getRandomLetter} from '../../../../utils'; import {doTestQuickChannelSwitcher} from '../common_test'; -import {createSearchData} from '../helpers'; +import {createSearchData, SimpleUser} from '../helpers'; describe('Autocomplete with Database - Users', () => { const prefix = getRandomLetter(3); - let testUsers; + let testUsers: Record; before(() => { cy.apiGetClientLicense().then(({isCloudLicensed}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.js b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.ts similarity index 97% rename from e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.js rename to e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.ts index 35efe333f3..4cb897f72b 100644 --- a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_in_message_input_box_spec.ts @@ -12,11 +12,11 @@ import {getRandomLetter} from '../../../../utils'; import {doTestPostextbox} from '../common_test'; -import {createSearchData} from '../helpers'; +import {createSearchData, SimpleUser} from '../helpers'; describe('Autocomplete with Database - Users', () => { const prefix = getRandomLetter(3); - let testUsers; + let testUsers: Record; before(() => { cy.apiGetClientLicense().then(({isCloudLicensed}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.js b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.ts similarity index 91% rename from e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.js rename to e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.ts index 93bc2d4ff0..7c8072d2ea 100644 --- a/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/autocomplete/database/users_spec.ts @@ -12,12 +12,12 @@ import {getRandomLetter} from '../../../../utils'; import {doTestDMChannelSidebar, doTestUserChannelSection} from '../common_test'; -import {createSearchData} from '../helpers'; +import {createSearchData, SimpleUser} from '../helpers'; describe('Autocomplete with Database - Users', () => { const prefix = getRandomLetter(3); - let testUsers; - let testTeam; + let testUsers: Record; + let testTeam: Cypress.Team; before(() => { cy.apiGetClientLicense().then(({isCloudLicensed}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/autocomplete/helpers.ts b/e2e-tests/cypress/tests/integration/channels/autocomplete/helpers.ts index a381785f25..3a467d6a08 100644 --- a/e2e-tests/cypress/tests/integration/channels/autocomplete/helpers.ts +++ b/e2e-tests/cypress/tests/integration/channels/autocomplete/helpers.ts @@ -210,14 +210,14 @@ function startAtMention(string: string) { cy.get('#suggestionList').should('be.visible'); } -function verifySuggestionAtPostTextbox(...expectedUsers: Cypress.UserProfile[]) { +function verifySuggestionAtPostTextbox(...expectedUsers: SimpleUser[]) { expectedUsers.forEach((user) => { cy.wait(TIMEOUTS.HALF_SEC); cy.uiVerifyAtMentionSuggestion(user); }); } -function verifySuggestionAtChannelSwitcher(...expectedUsers: Cypress.UserProfile[]) { +function verifySuggestionAtChannelSwitcher(...expectedUsers: SimpleUser[]) { expectedUsers.forEach((user) => { cy.findByTestId(user.username). should('be.visible'). diff --git a/e2e-tests/cypress/tests/support/api/system.d.ts b/e2e-tests/cypress/tests/support/api/system.d.ts index 9d2e4a2cf1..b7f63711ab 100644 --- a/e2e-tests/cypress/tests/support/api/system.d.ts +++ b/e2e-tests/cypress/tests/support/api/system.d.ts @@ -146,6 +146,14 @@ declare namespace Cypress { */ apiInvalidateCache(): Chainable>; + /** + * Allow test if matches elastic search disabled. + * Otherwise, fail fast. + * @example + * cy.shouldHaveElasticsearchDisabled(); + */ + shouldHaveElasticsearchDisabled(): Chainable; + /** * Allow test for server other than Cloud edition or with Cloud license. * Otherwise, fail fast. diff --git a/e2e-tests/cypress/tests/support/ui/suggestion_list.d.ts b/e2e-tests/cypress/tests/support/ui/suggestion_list.d.ts deleted file mode 100644 index 74aade4830..0000000000 --- a/e2e-tests/cypress/tests/support/ui/suggestion_list.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -/// - -// *************************************************************** -// Each command should be properly documented using JSDoc. -// See https://jsdoc.app/index.html for reference. -// Basic requirements for documentation are the following: -// - Meaningful description -// - Each parameter with `@params` -// - Return value with `@returns` -// - Example usage with `@example` -// Custom command should follow naming convention of having `ui` prefix, e.g. `uiCheckLicenseExists`. -// *************************************************************** - -declare namespace Cypress { - interface Chainable { - - /** - * Verify user's at-mention in the suggestion list - * @param {UserProfile} user - user object - * @param {boolean} isSelected - check if user is selected with false as default - * @param {string} sectionDividerName - name of the section in suggestion list, ex. "Channel Members" - * - * @example - * cy.uiVerifyAtMentionInSuggestionList(user, true, 'Channel Members'); - */ - uiVerifyAtMentionInSuggestionList(user: UserProfile, isSelected: boolean, sectionDividerName?: string): Chainable; - - /** - * Verify user's at-mention suggestion - * @param {UserProfile} user - user object - * @param {boolean} isSelected - check if user is selected with false as default - * - * @example - * cy.uiVerifyAtMentionSuggestion(user, true); - */ - uiVerifyAtMentionSuggestion(user: UserProfile, isSelected?: boolean): Chainable; - } -} diff --git a/e2e-tests/cypress/tests/support/ui/suggestion_list.js b/e2e-tests/cypress/tests/support/ui/suggestion_list.js deleted file mode 100644 index c187e14d41..0000000000 --- a/e2e-tests/cypress/tests/support/ui/suggestion_list.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -Cypress.Commands.add('uiVerifyAtMentionInSuggestionList', (user, isSelected = false, sectionDividerName = null) => { - // * Verify that the suggestion list is open and visible - return cy.get('#suggestionList').should('be.visible').within(() => { - if (sectionDividerName) { - // * Verify the section name is as expected - cy.get('.suggestion-list__divider').findByText(sectionDividerName).should('be.visible'); - cy.get('.suggestion-list__divider').next().findByTestId(`mentionSuggestion_${user.username}`).should('be.visible'); - } - - // * Verify that the user is selected - return cy.uiVerifyAtMentionSuggestion(user, isSelected); - }); -}); - -Cypress.Commands.add('uiVerifyAtMentionSuggestion', (user, isSelected = false) => { - const { - username, - first_name: firstName, - last_name: lastName, - nickname, - } = user; - - // * Verify that the user is selected - cy.findByTestId(`mentionSuggestion_${username}`).as('selectedMentionSuggestion').should('be.visible'); - if (isSelected) { - cy.get('@selectedMentionSuggestion').should('have.class', 'suggestion--selected'); - } - - cy.get('@selectedMentionSuggestion').findByText(`@${username}`).should('be.visible'); - cy.get('@selectedMentionSuggestion').findByText(`${firstName} ${lastName} (${nickname})`).should('be.visible'); - - return cy.findByTestId(`mentionSuggestion_${username}`); -}); diff --git a/e2e-tests/cypress/tests/support/ui/suggestion_list.ts b/e2e-tests/cypress/tests/support/ui/suggestion_list.ts new file mode 100644 index 0000000000..f3f5ec444f --- /dev/null +++ b/e2e-tests/cypress/tests/support/ui/suggestion_list.ts @@ -0,0 +1,69 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {SimpleUser} from 'tests/integration/channels/autocomplete/helpers'; +import {ChainableT} from 'tests/types'; + +/** + * Verify user's at-mention in the suggestion list + * @param {SimpleUser} user - user object + * @param {boolean} isSelected - check if user is selected with false as default + * @param {string} sectionDividerName - name of the section in suggestion list, ex. "Channel Members" + * + * @example + * cy.uiVerifyAtMentionInSuggestionList(user, true, 'Channel Members'); + */ +function uiVerifyAtMentionInSuggestionList(user: SimpleUser, isSelected = false, sectionDividerName: string = null): ChainableT { + // * Verify that the suggestion list is open and visible + return cy.get('#suggestionList').should('be.visible').within(() => { + if (sectionDividerName) { + // * Verify the section name is as expected + cy.get('.suggestion-list__divider').findByText(sectionDividerName).should('be.visible'); + cy.get('.suggestion-list__divider').next().findByTestId(`mentionSuggestion_${user.username}`).should('be.visible'); + } + + // * Verify that the user is selected + return cy.uiVerifyAtMentionSuggestion(user, isSelected); + }); +} +Cypress.Commands.add('uiVerifyAtMentionInSuggestionList', uiVerifyAtMentionInSuggestionList); + +/** + * Verify user's at-mention suggestion + * @param {SimpleUser} user - user object + * @param {boolean} isSelected - check if user is selected with false as default + * + * @example + * cy.uiVerifyAtMentionSuggestion(user, true); + */ +function uiVerifyAtMentionSuggestion(user: SimpleUser, isSelected = false): ChainableT { + const { + username, + first_name: firstName, + last_name: lastName, + nickname, + } = user; + + // * Verify that the user is selected + cy.findByTestId(`mentionSuggestion_${username}`).as('selectedMentionSuggestion').should('be.visible'); + if (isSelected) { + cy.get('@selectedMentionSuggestion').should('have.class', 'suggestion--selected'); + } + + cy.get('@selectedMentionSuggestion').findByText(`@${username}`).should('be.visible'); + cy.get('@selectedMentionSuggestion').findByText(`${firstName} ${lastName} (${nickname})`).should('be.visible'); + + return cy.findByTestId(`mentionSuggestion_${username}`); +} + +Cypress.Commands.add('uiVerifyAtMentionSuggestion', uiVerifyAtMentionSuggestion); + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + uiVerifyAtMentionInSuggestionList: typeof uiVerifyAtMentionInSuggestionList; + uiVerifyAtMentionSuggestion: typeof uiVerifyAtMentionSuggestion; + } + } +}