From 23623fc9c937c002a75d0eeb711b566dba339861 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Wed, 9 Oct 2024 05:22:45 -0600 Subject: [PATCH] MM-47288 refactor: convert channels/channel/ files to ts (#28483) * refactor: convert channels/channel/ files to ts - convert js files to typescript - update types - fix lint issues Fixes: 21299 * fix: solve lint issues channels/channel - fix lint issues - udpate types * fix: adjustment to test case MM-T1687 - code reorganization for test case MM-T1687 * fix: update types on function apiCreateCustomAdmin - update types for apiCreateCustomAdmin on user.d.ts so that lint issue is solved --- ..._1_spec.js => archived_channels_1_spec.ts} | 24 ++++++++++--------- ..._2_spec.js => archived_channels_2_spec.ts} | 17 ++++++++----- ...annels_spec.js => browse_channels_spec.ts} | 19 ++++++++------- ...spec.js => browse_public_channels_spec.ts} | 9 ++++--- .../channel/channel_bookmarks_spec.ts | 13 +++++----- ...o_rhs_spec.js => channel_info_rhs_spec.ts} | 23 ++++++++++-------- ...hs_spec.js => channel_members_rhs_spec.ts} | 18 ++++++++------ ...s => channel_mention_autocomplete_spec.ts} | 13 ++++++---- ..._spec.js => channel_name_tooltips_spec.ts} | 11 +++++---- ...outing_spec.js => channel_routing_spec.ts} | 11 +++++---- ...tings_spec.js => channel_settings_spec.ts} | 3 ++- ...tcher_spec.js => channel_switcher_spec.ts} | 8 ++++--- ...oup_spec.js => close_direct_group_spec.ts} | 23 +++++++++++------- ....js => convert_channel_to_private_spec.ts} | 7 ++++-- ... convert_group_message_to_private_spec.ts} | 24 +++++++++++-------- ..._channel_spec.js => leave_channel_spec.ts} | 9 ++++--- ...pdates_manage_channel_members_rhs_spec.ts} | 0 ...pdates_manage_channel_members_rhs_spec.ts} | 7 +++--- e2e-tests/cypress/tests/support/api/role.d.ts | 2 +- e2e-tests/cypress/tests/support/api/user.d.ts | 4 ++-- .../tests/support/ui/{search.js => search.ts} | 24 +++++++++++++++---- .../cypress/tests/support/ui_commands.ts | 2 +- 22 files changed, 168 insertions(+), 103 deletions(-) rename e2e-tests/cypress/tests/integration/channels/channel/{archived_channels_1_spec.js => archived_channels_1_spec.ts} (95%) rename e2e-tests/cypress/tests/integration/channels/channel/{archived_channels_2_spec.js => archived_channels_2_spec.ts} (89%) rename e2e-tests/cypress/tests/integration/channels/channel/{browse_channels_spec.js => browse_channels_spec.ts} (96%) rename e2e-tests/cypress/tests/integration/channels/channel/{browse_public_channels_spec.js => browse_public_channels_spec.ts} (95%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_info_rhs_spec.js => channel_info_rhs_spec.ts} (97%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_members_rhs_spec.js => channel_members_rhs_spec.ts} (96%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_mention_autocomplete_spec.js => channel_mention_autocomplete_spec.ts} (94%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_name_tooltips_spec.js => channel_name_tooltips_spec.ts} (93%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_routing_spec.js => channel_routing_spec.ts} (96%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_settings_spec.js => channel_settings_spec.ts} (98%) rename e2e-tests/cypress/tests/integration/channels/channel/{channel_switcher_spec.js => channel_switcher_spec.ts} (96%) rename e2e-tests/cypress/tests/integration/channels/channel/{close_direct_group_spec.js => close_direct_group_spec.ts} (88%) rename e2e-tests/cypress/tests/integration/channels/channel/{convert_channel_to_private_spec.js => convert_channel_to_private_spec.ts} (97%) rename e2e-tests/cypress/tests/integration/channels/channel/{convert_group_message_to_private_spec.js => convert_group_message_to_private_spec.ts} (91%) rename e2e-tests/cypress/tests/integration/channels/channel/{leave_channel_spec.js => leave_channel_spec.ts} (94%) rename e2e-tests/cypress/tests/integration/channels/channel/{user_to_admin_updates_manage_channel_members_rhs_spec.js => user_to_admin_updates_manage_channel_members_rhs_spec.ts} (100%) rename e2e-tests/cypress/tests/integration/channels/channel/{user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.js => user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.ts} (94%) rename e2e-tests/cypress/tests/support/ui/{search.js => search.ts} (61%) diff --git a/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.ts similarity index 95% rename from e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.ts index 0e6124d20f..215fb828d4 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_1_spec.ts @@ -10,11 +10,13 @@ // Stage: @prod // Group: @channels @channel +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; import {getRandomId} from '../../../utils'; describe('Leave an archived channel', () => { - let testTeam; - let offTopicUrl; + let testTeam: Team; + let offTopicUrl: string; const channelType = { all: 'Channel Type: All', public: 'Channel Type: Public', @@ -63,13 +65,13 @@ describe('Leave an archived channel', () => { // # Search for the new post and jump to it from the search results cy.uiSearchPosts(otherPostText); - cy.get('@otherPostId').then((otherPostId) => cy.uiJumpToSearchResult(otherPostId)); + cy.get('@otherPostId').then((otherPostId) => cy.uiJumpToSearchResult(otherPostId)); // # Search for a post in the archived channel cy.uiSearchPosts(archivedPostText); // # Open it in the RHS - cy.get('@archivedPostId').then((archivedPostId) => { + cy.get('@archivedPostId').then((archivedPostId) => { cy.clickPostCommentIcon(archivedPostId, 'SEARCH'); // * Verify that the RHS has switched from search results to the thread @@ -114,8 +116,8 @@ describe('Leave an archived channel', () => { }); it('MM-T1699 - Browse Channels for all channel types shows archived channels option', () => { - let archivedPrivateChannel; - let archivedPublicChannel; + let archivedPrivateChannel: Channel; + let archivedPublicChannel: Channel; // # Create private channel cy.uiCreateChannel({isPrivate: true, isNewSidebar: true}).as('channel').then((channel) => { @@ -161,8 +163,8 @@ describe('Leave an archived channel', () => { }); it('MM-T1700 - All archived public channels are shown Important', () => { - let archivedPublicChannel1; - let archivedPublicChannel2; + let archivedPublicChannel1: Channel; + let archivedPublicChannel2: Channel; // # Create public channel cy.apiCreateChannel(testTeam.id, 'channel', 'channel').then(({channel}) => { @@ -214,8 +216,8 @@ describe('Leave an archived channel', () => { }); it('MM-T1701 - Only Private channels you are a member of are displayed', () => { - let archivedPrivateChannel1; - let archivedPrivateChannel2; + let archivedPrivateChannel1: Channel; + let archivedPrivateChannel2: Channel; // # Create private channel cy.uiCreateChannel({isPrivate: true, isNewSidebar: true}).as('channel').then((channel) => { @@ -268,7 +270,7 @@ describe('Leave an archived channel', () => { }); it('MM-T1703 - User can open archived channels', () => { - let archivedChannel; + let archivedChannel: Channel; // # Create a public channel cy.apiCreateChannel(testTeam.id, 'channel', 'channel').then(({channel}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.ts similarity index 89% rename from e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.ts index cda79d0115..e580d58a2b 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/archived_channels_2_spec.ts @@ -10,12 +10,15 @@ // Stage: @prod // Group: @channels @channel +import {Channel, ServerChannel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import {getAdminAccount} from '../../../support/env'; import {getRandomId} from '../../../utils'; describe('Leave an archived channel', () => { - let testTeam; - let testUser; + let testTeam: Team; + let testUser: UserProfile; before(() => { cy.apiUpdateConfig({ @@ -37,19 +40,21 @@ describe('Leave an archived channel', () => { }); it('MM-T1687 App does not crash when another user archives a channel', () => { - cy.makeClient({user: getAdminAccount()}).then((client) => { + cy.makeClient({user: getAdminAccount()}).then(async (client) => { // # Have another user create a private channel const channelName = `channel${getRandomId()}`; - cy.wrap(client.createChannel({ + const channelTest = { display_name: channelName, name: channelName, team_id: testTeam.id, type: 'P', - })).then(async (channel) => { + } as Channel; + + cy.wrap(client.createChannel(channelTest)).then(async (channel: ServerChannel) => { // # Then invite us to it await client.addToChannel(testUser.id, channel.id); - cy.wrap(channel); + return channel; }).then((channel) => { // * Verify that the newly created channel is in the sidebar cy.get(`#sidebarItem_${channel.name}`).should('be.visible'); diff --git a/e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.ts similarity index 96% rename from e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.ts index 948f1ec09e..edc0739e55 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/browse_channels_spec.ts @@ -10,6 +10,9 @@ // Stage: @prod // Group: @channels @channel +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as TIMEOUTS from '../../../fixtures/timeouts'; import {createPrivateChannel} from '../enterprise/elasticsearch_autocomplete/helpers'; @@ -21,10 +24,10 @@ const channelType = { }; describe('Channels', () => { - let testUser; - let otherUser; - let testTeam; - let testChannel; + let testUser: UserProfile; + let otherUser: UserProfile; + let testTeam: Team; + let testChannel: Channel; before(() => { cy.apiInitSetup().then(({team, user}) => { @@ -151,7 +154,7 @@ describe('Channels', () => { cy.apiLogin(otherUser); cy.visit(`/${testTeam.name}/channels/town-square`); - let newChannel; + let newChannel: Channel; cy.apiCreateChannel(testTeam.id, 'channel-to-leave', 'Channel to leave').then(({channel}) => { newChannel = channel; cy.visit(`/${testTeam.name}/channels/${newChannel.name}`); @@ -185,9 +188,9 @@ describe('Channels', () => { ExperimentalViewArchivedChannels: true, }, }); - let newChannel; - let testArchivedChannel; - let testPrivateArchivedChannel; + let newChannel: Channel; + let testArchivedChannel: Channel; + let testPrivateArchivedChannel: Channel; cy.apiCreateTeam('team', 'Test NoMember').then(({team}) => { cy.apiCreateChannel(team.id, 'not-archived-channel', 'Not Archived Channel').then(({channel}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.ts similarity index 95% rename from e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.ts index b9b83c06d8..07b3f7399b 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/browse_public_channels_spec.ts @@ -1,6 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -15,9 +18,9 @@ function verifyNoChannelToJoinMessage(isVisible) { } describe('browse public channels', () => { - let testUser; - let otherUser; - let testTeam; + let testUser: UserProfile; + let otherUser: UserProfile; + let testTeam: Team; before(() => { cy.apiInitSetup().then(({team, user}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_bookmarks_spec.ts b/e2e-tests/cypress/tests/integration/channels/channel/channel_bookmarks_spec.ts index 8c5b79ce4c..d76c438233 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_bookmarks_spec.ts +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_bookmarks_spec.ts @@ -10,6 +10,9 @@ // Group: @channels @channel @channel_bookmarks // node run_tests.js --group='@channel' +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import {getRandomId} from '../../../utils'; import * as TIMEOUTS from '../../../fixtures/timeouts'; @@ -17,14 +20,12 @@ describe('Channel Bookmarks', () => { const SpaceKeyCode = 32; const RightArrowKeyCode = 39; - let testTeam: Cypress.Team; + let testTeam: Team; // eslint-disable-next-line @typescript-eslint/no-unused-vars - let user1: Cypress.UserProfile; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let admin: Cypress.UserProfile; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let channel: Cypress.Channel; + let user1: UserProfile; + let admin: UserProfile; + let channel: Channel; before(() => { cy.apiGetMe().then(({user: adminUser}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.ts similarity index 97% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.ts index 624eea18b0..4311d1fce3 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_info_rhs_spec.ts @@ -10,17 +10,20 @@ // Stage: @prod // Group: @channels @channel @rhs @channel_info +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import {stubClipboard} from '../../../utils'; describe('Channel Info RHS', () => { - let testTeam; - let testChannel; - let groupChannel; - let directChannel; - let directUser; - let admin; - let user; - const otherUsers = []; + let testTeam: Team; + let testChannel: Channel; + let groupChannel: Channel; + let directChannel: Channel; + let directUser: UserProfile; + let admin: UserProfile; + let user: UserProfile; + const otherUsers: UserProfile[] = []; before(() => { cy.apiInitSetup({promoteNewUserAsAdmin: true}).then(({team, user: newAdmin}) => { @@ -41,7 +44,7 @@ describe('Channel Info RHS', () => { // Users used for GM/DM cy.apiCreateUser().then(({user: newUser}) => { otherUsers.push(newUser); - cy.apiPatchUser(newUser.id, {position: 'Upside down'}).then(({user: patchedUser}) => { + cy.apiPatchUser(newUser.id, {position: 'Upside down'} as UserProfile).then(({user: patchedUser}) => { cy.apiCreateDirectChannel([newAdmin.id, newUser.id]).then(({channel}) => { directChannel = channel; }); @@ -66,7 +69,7 @@ describe('Channel Info RHS', () => { return !(['manage_public_channel_members', 'manage_private_channel_members', 'manage_public_channel_properties', 'manage_private_channel_properties'].includes(permission)); }); - if (permissions.length !== role.permissions) { + if (permissions.length !== role.permissions.length) { cy.apiPatchRole(role.id, {permissions}); } }); diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.ts similarity index 96% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.ts index 0b89b9f3f8..8d310a7a62 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_members_rhs_spec.ts @@ -1,6 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; + const {generateRandomUser} = require('../../../support/api/user'); // *************************************************************** @@ -12,7 +16,7 @@ const {generateRandomUser} = require('../../../support/api/user'); // Stage: @prod // Group: @channels @channel @rhs @channel_members -function openChannelMembersRhs(testTeam, testChannel) { +function openChannelMembersRhs(testTeam: Team, testChannel: Channel) { // # Go to test channel cy.visit(`/${testTeam.name}/channels/${testChannel.name}`); @@ -24,10 +28,10 @@ function openChannelMembersRhs(testTeam, testChannel) { } describe('Channel members RHS', () => { - let testTeam; - let testChannel; - let admin; - let user; + let testTeam: Team; + let testChannel: Channel; + let admin: UserProfile; + let user: UserProfile; before(() => { cy.apiInitSetup({promoteNewUserAsAdmin: true}).then(({team, user: newAdmin}) => { @@ -53,7 +57,7 @@ describe('Channel members RHS', () => { return !(['manage_public_channel_members', 'manage_private_channel_members', 'manage_public_channel_properties', 'manage_private_channel_properties'].includes(permission)); }); - if (permissions.length !== role.permissions) { + if (permissions.length !== role.permissions.length) { cy.apiPatchRole(role.id, {permissions}); } }); @@ -168,7 +172,7 @@ describe('Channel members RHS', () => { it('should hide deactivated members', () => { cy.apiCreateChannel(testTeam.id, 'hide-test-channel', 'Hide Test Channel', 'O').then(({channel}) => { - let testUser = null; + let testUser: UserProfile; cy.apiCreateUser().then(({user: newUser}) => { cy.apiAddUserToTeam(testTeam.id, newUser.id).then(() => { cy.apiAddUserToChannel(channel.id, newUser.id).then(() => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.ts similarity index 94% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.ts index 6b6a8810d7..7847c055ba 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_mention_autocomplete_spec.ts @@ -10,14 +10,17 @@ // Stage: @prod // Group: @channels @channel +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as TIMEOUTS from '../../../fixtures/timeouts'; describe('Channel', () => { - let testTeam; - let ownChannel; - let otherChannel; - let testUser; - let offTopicUrl; + let testTeam: Team; + let ownChannel: Channel; + let otherChannel: Channel; + let testUser: UserProfile; + let offTopicUrl: string; const myChannelsDividerText = 'My Channels'; const otherChannelsDividerText = 'Other Channels'; diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.ts similarity index 93% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.ts index e0327ec6d2..aae9568166 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_name_tooltips_spec.ts @@ -10,11 +10,14 @@ // Stage: @prod // Group: @channels @channel @not_cloud +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as TIMEOUTS from '../../../fixtures/timeouts'; const timestamp = Date.now(); -function verifyChannel(channel, verifyExistence = true) { +function verifyChannel(channel: Channel, verifyExistence = true) { // # Wait for Channel to be created cy.wait(TIMEOUTS.HALF_SEC); @@ -35,9 +38,9 @@ function verifyChannel(channel, verifyExistence = true) { } describe('channel name tooltips', () => { - let loggedUser; - let longUser; - let testTeam; + let loggedUser: UserProfile; + let longUser: UserProfile; + let testTeam: Team; before(() => { cy.shouldNotRunOnCloudEdition(); diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.ts similarity index 96% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.ts index 8349d0491c..031dd41676 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_routing_spec.ts @@ -1,6 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -11,10 +14,10 @@ // Group: @channels @channel describe('Channel routing', () => { - let testUser; - let otherUser1; - let otherUser2; - let testTeam; + let testUser: UserProfile; + let otherUser1: UserProfile; + let otherUser2: UserProfile; + let testTeam: Team; before(() => { cy.apiInitSetup().then(({team, user}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.ts similarity index 98% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.ts index 56568c35d8..bcfe332c9e 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_settings_spec.ts @@ -10,13 +10,14 @@ // Stage: @prod // Group: @channels @channel @channel_settings +import {Team} from '@mattermost/types/teams'; import { beMuted, beUnmuted, } from '../../../support/assertions'; describe('Channel Settings', () => { - let testTeam; + let testTeam: Team; before(() => { cy.apiInitSetup().then(({team, user}) => { testTeam = team; diff --git a/e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.ts similarity index 96% rename from e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.ts index eb4e12255a..9cfde8ea93 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/channel_switcher_spec.ts @@ -1,6 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Team} from '@mattermost/types/teams'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -11,9 +13,9 @@ // Group: @channels @channel @smoke describe('Channel Switcher', () => { - let testTeam; - let testChannelName; - let offTopicUrl; + let testTeam: Team; + let testChannelName: string; + let offTopicUrl: string; const channelNamePrefix = 'aswitchchannel'; const channelDisplayNamePrefix = 'ASwitchChannel'; diff --git a/e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.ts similarity index 88% rename from e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.ts index 6afddf0cbe..1b74b9bf58 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/close_direct_group_spec.ts @@ -1,6 +1,11 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; +import {ChainableT} from '../../../types'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -13,7 +18,7 @@ // Make sure that the current channel is Town Square and that the // channel identified by the passed name is no longer in the channel // sidebar -function verifyChannelWasProperlyClosed(channelName) { +function verifyChannelWasProperlyClosed(channelName: string) { // * Make sure that we have switched channels cy.get('#channelHeaderTitle').should('contain', 'Town Square'); @@ -22,9 +27,9 @@ function verifyChannelWasProperlyClosed(channelName) { } describe('Close direct messages', () => { - let testUser; - let otherUser; - let testTeam; + let testUser: UserProfile; + let otherUser: UserProfile; + let testTeam: Team; before(() => { cy.shouldNotRunOnCloudEdition(); @@ -54,7 +59,7 @@ describe('Close direct messages', () => { }); }); - function createAndVisitDMChannel(userIds) { + function createAndVisitDMChannel(userIds: string[]): ChainableT { return cy.apiCreateDirectChannel(userIds).then(({channel}) => { // # Visit the new channel cy.visit(`/${testTeam.name}/channels/${channel.name}`); @@ -68,10 +73,10 @@ describe('Close direct messages', () => { }); describe('Close group messages', () => { - let testUser; - let otherUser1; - let otherUser2; - let testTeam; + let testUser: UserProfile; + let otherUser1: UserProfile; + let otherUser2: UserProfile; + let testTeam: Team; before(() => { cy.apiAdminLogin(); diff --git a/e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.ts similarity index 97% rename from e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.ts index 93d92c30da..c4fad224db 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/convert_channel_to_private_spec.ts @@ -1,6 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -11,8 +14,8 @@ // Group: @channels @channel describe('Channels', () => { - let testUser; - let testTeam; + let testUser: UserProfile; + let testTeam: Team; before(() => { cy.apiInitSetup().then(({team, user}) => { diff --git a/e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.ts similarity index 91% rename from e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.ts index 111853edce..4f49e2ec71 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/convert_group_message_to_private_spec.ts @@ -1,6 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {Channel} from '@mattermost/types/channels'; +import {Team, TeamMembership} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -11,14 +15,14 @@ // Group: @channels @channel describe('Group Message Conversion To Private Channel', () => { - let testTeam1; - let testTeam2; + let testTeam1: Team; + let testTeam2: Team; - let testUser1; - let testUser2; - let testUser3; + let testUser1: UserProfile; + let testUser2: UserProfile; + let testUser3: UserProfile; - let gm; + let gm: Channel; before(() => { // we need two teams, and a set of users belonging to both teams @@ -36,9 +40,9 @@ describe('Group Message Conversion To Private Channel', () => { testUser3 = user3; const teamMembers1 = [testUser1, testUser2, testUser3].map((u) => ({team_id: testTeam1.id, user_id: u.id})); - cy.apiAddUsersToTeam(testTeam1.id, teamMembers1).then(() => { + cy.apiAddUsersToTeam(testTeam1.id, teamMembers1 as TeamMembership[]).then(() => { const teamMembers2 = [testUser1, testUser2, testUser3].map((u) => ({team_id: testTeam2.id, user_id: u.id})); - cy.apiAddUsersToTeam(testTeam2.id, teamMembers2).then(() => { + cy.apiAddUsersToTeam(testTeam2.id, teamMembers2 as TeamMembership[]).then(() => { cy.apiCreateGroupChannel([testUser1.id, testUser2.id, testUser3.id]).then(({channel}) => { gm = channel; }); @@ -91,7 +95,7 @@ describe('Group Message Conversion To Private Channel', () => { user_id: u.id, })); - cy.apiAddUsersToTeam(testTeam2.id, teamMembers).then(() => { + cy.apiAddUsersToTeam(testTeam2.id, teamMembers as TeamMembership[]).then(() => { cy.apiCreateGroupChannel([testUser1.id, testUser2.id, testUser3.id, testUser4.id]).then(({channel}) => { gm2 = channel; @@ -130,7 +134,7 @@ describe('Group Message Conversion To Private Channel', () => { user_id: testUser5.id, }]; - cy.apiAddUsersToTeam(testTeam3.id, teamMembers).then(() => { + cy.apiAddUsersToTeam(testTeam3.id, teamMembers as TeamMembership[]).then(() => { cy.apiCreateGroupChannel([testUser1.id, testUser2.id, testUser3.id, testUser5.id]).then(({channel}) => { gm3 = channel; diff --git a/e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.ts similarity index 94% rename from e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.ts index c5a9cefcee..60fa01e671 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/leave_channel_spec.ts @@ -10,12 +10,15 @@ // Stage: @prod // Group: @channels @channel +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as TIMEOUTS from '../../../fixtures/timeouts'; describe('Leave channel', () => { - let testTeam; - let testUser; - let testChannel; + let testTeam: Team; + let testUser: UserProfile; + let testChannel: Channel; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/channel/user_to_admin_updates_manage_channel_members_rhs_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/user_to_admin_updates_manage_channel_members_rhs_spec.ts similarity index 100% rename from e2e-tests/cypress/tests/integration/channels/channel/user_to_admin_updates_manage_channel_members_rhs_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/user_to_admin_updates_manage_channel_members_rhs_spec.ts diff --git a/e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.js b/e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.ts similarity index 94% rename from e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.js rename to e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.ts index 2ca0eedac2..cb24808d3e 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/channel/user_to_channel_admin_member_updates_manage_channel_members_rhs_spec.ts @@ -9,6 +9,7 @@ // Group: @channels @channel +import {UserProfile} from '@mattermost/types/users'; import {getAdminAccount} from '../../../support/env'; const demoteToChannelMember = (user, channelId, admin) => { @@ -37,8 +38,8 @@ const promoteToChannelAdmin = (user, channelId, admin) => { describe('Change Roles', () => { const admin = getAdminAccount(); - let testUser; - let testChannelId; + let testUser: UserProfile; + let testChannelId: string; beforeEach(() => { // # Login as test user and visit test channel @@ -57,7 +58,7 @@ describe('Change Roles', () => { return !(['manage_public_channel_members', 'manage_private_channel_members', 'manage_public_channel_properties', 'manage_private_channel_properties'].includes(permission)); }); - if (permissions.length !== role.permissions) { + if (permissions.length !== role.permissions.length) { cy.apiPatchRole(role.id, {permissions}); } }); diff --git a/e2e-tests/cypress/tests/support/api/role.d.ts b/e2e-tests/cypress/tests/support/api/role.d.ts index d7ee8a611c..686f6cda8d 100644 --- a/e2e-tests/cypress/tests/support/api/role.d.ts +++ b/e2e-tests/cypress/tests/support/api/role.d.ts @@ -42,7 +42,7 @@ declare namespace Cypress { * // do something with roles * }); */ - apiGetRolesByNames(names: string[]): Chainable; + apiGetRolesByNames(names: string[]): Chainable<{roles: Role[]}>; /** * Patch a role by ID. diff --git a/e2e-tests/cypress/tests/support/api/user.d.ts b/e2e-tests/cypress/tests/support/api/user.d.ts index 0d04ef83c8..81f1965a27 100644 --- a/e2e-tests/cypress/tests/support/api/user.d.ts +++ b/e2e-tests/cypress/tests/support/api/user.d.ts @@ -193,7 +193,7 @@ declare namespace Cypress { * * @returns {UserProfile} `out.sysadmin` as `UserProfile` object */ - apiCreateCustomAdmin(options: {loginAfter: boolean; hideAdminTrialModal?: boolean}): Chainable<{sysadmin: UserProfile}>; + apiCreateCustomAdmin({loginAfter = false, hideAdminTrialModal = true} = {}): Chainable<{sysadmin: UserProfile}>; /** * Create a new user with an options to set name prefix and be able to bypass tutorial steps. @@ -248,7 +248,7 @@ declare namespace Cypress { * // do something with users * }); */ - apiGetUsers(queryParams: Record): Chainable; + apiGetUsers(queryParams: Record): Chainable<{users: UserProfile[]}>; /** * Get list of users that are not team members. diff --git a/e2e-tests/cypress/tests/support/ui/search.js b/e2e-tests/cypress/tests/support/ui/search.ts similarity index 61% rename from e2e-tests/cypress/tests/support/ui/search.js rename to e2e-tests/cypress/tests/support/ui/search.ts index 8342379954..c2eccdb89c 100644 --- a/e2e-tests/cypress/tests/support/ui/search.js +++ b/e2e-tests/cypress/tests/support/ui/search.ts @@ -1,16 +1,20 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -Cypress.Commands.add('uiSearchPosts', (searchTerm) => { +import {ChainableT} from 'tests/types'; + +function uiSearchPosts(searchTerm: string) { // # Enter the search terms and hit enter to start the search cy.get('#searchBox').clear().type(searchTerm).type('{enter}'); // * Wait for the RHS to open and the search results to appear cy.contains('.sidebar--right__header', 'Search Results').should('be.visible'); cy.get('#searchContainer .LoadingSpinner').should('not.exist'); -}); +} -Cypress.Commands.add('uiJumpToSearchResult', (postId) => { +Cypress.Commands.add('uiSearchPosts', uiSearchPosts); + +function uiJumpToSearchResult(postId: string) { // # Find the post in the search results and click Jump cy.get(`#searchResult_${postId}`).contains('a', 'Jump').click(); @@ -19,4 +23,16 @@ Cypress.Commands.add('uiJumpToSearchResult', (postId) => { // * Verify that the permalinked post is highlighted in the center channel cy.get(`#post_${postId}.post--highlight`).should('be.visible'); -}); +} + +Cypress.Commands.add('uiJumpToSearchResult', uiJumpToSearchResult); + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + uiSearchPosts(searchTerm: string): ChainableT; + uiJumpToSearchResult(postId: string): ChainableT; + } + } +} diff --git a/e2e-tests/cypress/tests/support/ui_commands.ts b/e2e-tests/cypress/tests/support/ui_commands.ts index a5a0d81a0b..ed999ed0a6 100644 --- a/e2e-tests/cypress/tests/support/ui_commands.ts +++ b/e2e-tests/cypress/tests/support/ui_commands.ts @@ -638,7 +638,7 @@ declare global { * @example * cy.uiPostMessageQuickly('Hello world') */ - uiPostMessageQuickly(message: string): void; + uiPostMessageQuickly(message: string): ChainableT; /** * Clicks on a visible emoji in the emoji picker.