From 3d38d239ffba8125fd98d98045a48f9a5d35e239 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Tue, 8 Oct 2024 15:15:43 -0600 Subject: [PATCH] MM-47291 refactor: migrate collapsed_reply_threads to ts (#27808) * refactor: migrate collapsed_reply_threads to ts - migrate collapsed_reply_threads e2e tests to typescript - update matterpollPlugin plugin constant so that it matches with apiUploadAndEnablePlugin argument Fixes: #21296 * refactor: use PostMessageResp on channel_notifications_spec - use type PostMessageResp - convert cy.wrap to regular for loop * refactor: update types on collapsed_reply_threads - add missing types to variables - update types on current variables - remove unnecessary commands on following_spec.ts * fix: solve issue with non callable function - move wait call to next line * refactor: remove functions from global scope - keep functions as helper functions - fix lint issue --- ..._spec.js => channel_notifications_spec.ts} | 31 +++++++++++-------- ..._settings_spec.js => crt_settings_spec.ts} | 4 ++- .../{crt_tour_spec.js => crt_tour_spec.ts} | 13 +++++--- .../{files_1_spec.js => files_1_spec.ts} | 9 ++++-- .../{files_spec.js => files_spec.ts} | 9 ++++-- .../{following_spec.js => following_spec.ts} | 17 +++++----- ...threads_spec.js => global_threads_spec.ts} | 21 ++++++++----- ...ast_viewed_spec.js => last_viewed_spec.ts} | 13 +++++--- ...read_dm_spec.js => open_thread_dm_spec.ts} | 9 ++++-- .../{replies_spec.js => replies_spec.ts} | 16 ++++++---- .../{unread_spec.js => unread_spec.ts} | 11 ++++--- .../accessibility_modals_dialogs_spec.js | 2 +- .../guest_identification_ui_not_cloud_spec.ts | 3 +- .../cypress/tests/support/task_commands.ts | 2 +- e2e-tests/cypress/tests/utils/plugins.js | 1 + 15 files changed, 101 insertions(+), 60 deletions(-) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{channel_notifications_spec.js => channel_notifications_spec.ts} (94%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{crt_settings_spec.js => crt_settings_spec.ts} (95%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{crt_tour_spec.js => crt_tour_spec.ts} (98%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{files_1_spec.js => files_1_spec.ts} (93%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{files_spec.js => files_spec.ts} (95%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{following_spec.js => following_spec.ts} (96%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{global_threads_spec.js => global_threads_spec.ts} (97%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{last_viewed_spec.js => last_viewed_spec.ts} (92%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{open_thread_dm_spec.js => open_thread_dm_spec.ts} (92%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{replies_spec.js => replies_spec.ts} (95%) rename e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/{unread_spec.js => unread_spec.ts} (92%) diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.ts similarity index 94% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.ts index cf267b3035..474234ad34 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/channel_notifications_spec.ts @@ -10,15 +10,18 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; +import {PostMessageResp} from '../../../support/task_commands'; import {spyNotificationAs} from '../../../support/notification'; describe('CRT Desktop notifications', () => { - let testTeam; - let testChannelUrl; - let testChannelId; - let testChannelName; - let receiver; - let sender; + let testTeam: Team; + let testChannelUrl: string; + let testChannelId: string; + let testChannelName: string; + let receiver: UserProfile; + let sender: UserProfile; before(() => { cy.apiUpdateConfig({ @@ -265,11 +268,12 @@ describe('CRT Desktop notifications', () => { cy.get('#sidebarItem_threads #unreadMentions').should('exist').and('have.text', '1'); // # Delete the replies - cy.wrap(['@reply', '@replyMention']).each((reply) => { - cy.get(reply).then(({id}) => { + const replies = ['@reply', '@replyMention']; + for (const reply of replies) { + cy.get(reply).then(({id}) => { cy.apiDeletePost(id); }); - }); + } // * Verify there is no notification cy.get('#sidebarItem_threads #unreadMentions').should('not.exist'); @@ -288,7 +292,7 @@ describe('CRT Desktop notifications', () => { cy.postMessageAs({sender, message: 'a thread', channelId: dmChannel.id, rootId: ''}).as('rootPost'); // # Get post id of message - cy.get('@rootPost').then(({id: rootId}) => { + cy.get('@rootPost').then(({id: rootId}) => { // # Post a reply to the thread, which will trigger a follow cy.postMessageAs({sender: receiver, message: 'following the thread', channelId: dmChannel.id, rootId}); @@ -303,11 +307,12 @@ describe('CRT Desktop notifications', () => { cy.get('#sidebarItem_threads #unreadMentions').should('exist'); // # Delete the replies - cy.wrap(['@reply', '@replyMention']).each((reply) => { - cy.get(reply).then(({id}) => { + const replies = ['@reply', '@replyMention']; + for (const reply of replies) { + cy.get(reply).then(({id}) => { cy.apiDeletePost(id); }); - }); + } // * Verify there is no notification cy.get('#sidebarItem_threads #unreadMentions').should('not.exist'); diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_spec.ts similarity index 95% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_spec.ts index e82dc66502..9975131002 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_settings_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,7 +13,7 @@ // Group: @channels @collapsed_reply_threads describe('Collapsed Reply Threads', () => { - let testTeam; + let testTeam: Team; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_spec.ts similarity index 98% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_spec.ts index cbcd3181b9..c7847fcf28 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/crt_tour_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 {PostMessageResp} from 'tests/support/task_commands'; + // *************************************************************** // - [#] indicates a test step (e.g. # Go to a page) // - [*] indicates an assertion (e.g. * Check the title) @@ -11,10 +16,10 @@ // Group: @channels @collapsed_reply_threads describe('Collapsed Reply Threads', () => { - let testTeam; - let otherUser; - let testChannel; - let rootPost; + let testTeam: Team; + let otherUser: UserProfile; + let testChannel: Channel; + let rootPost: PostMessageResp; beforeEach(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.ts similarity index 93% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.ts index f180da77ee..776b57f269 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_1_spec.ts @@ -10,14 +10,17 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads @not_cloud +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as MESSAGES from '../../../fixtures/messages'; import {matterpollPlugin} from '../../../utils/plugins'; import {interceptFileUpload} from '../files_and_attachments/helpers'; describe('Collapsed Reply Threads', () => { - let testTeam; - let testChannel; - let user1; + let testTeam: Team; + let testChannel: Channel; + let user1: UserProfile; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.ts similarity index 95% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.ts index 3bbbcd5e67..44f0568ca0 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/files_spec.ts @@ -10,13 +10,16 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; import * as MESSAGES from '../../../fixtures/messages'; import {waitUntilUploadComplete, interceptFileUpload} from '../files_and_attachments/helpers'; describe('Collapsed Reply Threads', () => { - let testTeam; - let testChannel; - let user1; + let testTeam: Team; + let testChannel: Channel; + let user1: UserProfile; const files = [ { diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.ts similarity index 96% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.ts index b6987e40d8..c5e7c37694 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/following_spec.ts @@ -9,14 +9,18 @@ // Group: @channels @collapsed_reply_threads +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 {isMac} from '../../../utils'; +import {ChainableT} from '../../../types'; describe('Collapsed Reply Threads', () => { - let testTeam; - let testUser; - let otherUser; - let testChannel; + let testTeam: Team; + let testUser: UserProfile; + let otherUser: UserProfile; + let testChannel: Channel; before(() => { cy.apiUpdateConfig({ @@ -239,7 +243,7 @@ describe('Collapsed Reply Threads', () => { }); }); -function postMessageWithReply(channelId, postSender, postMessage, replySender, replyMessage) { +function postMessageWithReply(channelId, postSender, postMessage, replySender, replyMessage): ChainableT { return cy.postMessageAs({ sender: postSender, message: postMessage || 'Another interesting post.', @@ -254,7 +258,7 @@ function postMessageWithReply(channelId, postSender, postMessage, replySender, r }); } -function scrollThreadsListToEnd(maxScrolls = 1, scrolls = 0) { +function scrollThreadsListToEnd(maxScrolls = 1, scrolls = 0): ChainableT { if (scrolls === maxScrolls) { return; } @@ -271,4 +275,3 @@ function scrollThreadsListToEnd(maxScrolls = 1, scrolls = 0) { } }); } - diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.ts similarity index 97% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.ts index 5ae22687d7..438683b74c 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/global_threads_spec.ts @@ -10,15 +10,20 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; +import {PostMessageResp} from 'tests/support/task_commands'; + describe('Collapsed Reply Threads', () => { - let testTeam; - let testChannel; - let user1; - let user2; - let user3; - let rootPost; - let replyPost1; - let replyPost2; + let testTeam: Team; + let testChannel: Channel; + let user1: UserProfile; + let user2: UserProfile; + let user3: UserProfile; + let rootPost: PostMessageResp; + let replyPost1: PostMessageResp; + let replyPost2: PostMessageResp; const messages = { ROOT: 'ROOT POST', diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.ts similarity index 92% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.ts index c4d42173fb..c11b0ca0fa 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/last_viewed_spec.ts @@ -1,6 +1,9 @@ // 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 * as TIMEOUTS from '../../../fixtures/timeouts'; // *************************************************************** @@ -13,11 +16,11 @@ import * as TIMEOUTS from '../../../fixtures/timeouts'; // Group: @channels @collapsed_reply_threads describe('Collapsed Reply Threads', () => { - let userA; // Member of team A and B - let teamA; - let teamB; - let offTopicUrlA; - let testChannel; + let userA: UserProfile; // Member of team A and B + let teamA: Team; + let teamB: Team; + let offTopicUrlA: string; + let testChannel: Channel; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.ts similarity index 92% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.ts index 87c89f6112..28dd0d02bb 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_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,9 +14,9 @@ // Group: @channels @collapsed_reply_threads describe('Collapsed Reply Threads', () => { - let testTeam; - let testUser; - let otherUser; + let testTeam: Team; + let testUser: UserProfile; + let otherUser: UserProfile; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.ts similarity index 95% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.ts index ce2a044401..f12039a0e9 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/replies_spec.ts @@ -10,15 +10,19 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads +import {Channel} from '@mattermost/types/channels'; +import {Team} from '@mattermost/types/teams'; +import {UserProfile} from '@mattermost/types/users'; +import {PostMessageResp} from 'tests/support/task_commands'; import * as TIMEOUTS from '../../../fixtures/timeouts'; describe('Collapsed Reply Threads', () => { - let testTeam; - let testUser; - let otherUser; - let testChannel; - let rootPost; - let postForAvatar; + let testTeam: Team; + let testUser: UserProfile; + let otherUser: UserProfile; + let testChannel: Channel; + let rootPost: PostMessageResp; + let postForAvatar: PostMessageResp; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts similarity index 92% rename from e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.js rename to e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts index b696995c7f..40cf47e412 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts @@ -10,13 +10,16 @@ // Stage: @prod // Group: @channels @collapsed_reply_threads +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('Collapsed Reply Threads', () => { - let testTeam; - let testUser; - let otherUser; - let testChannel; + let testTeam: Team; + let testUser: UserProfile; + let otherUser: UserProfile; + let testChannel: Channel; before(() => { cy.apiUpdateConfig({ diff --git a/e2e-tests/cypress/tests/integration/channels/enterprise/accessibility/accessibility_modals_dialogs_spec.js b/e2e-tests/cypress/tests/integration/channels/enterprise/accessibility/accessibility_modals_dialogs_spec.js index 39bf1147de..6f5d89aa5c 100644 --- a/e2e-tests/cypress/tests/integration/channels/enterprise/accessibility/accessibility_modals_dialogs_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/enterprise/accessibility/accessibility_modals_dialogs_spec.js @@ -137,7 +137,7 @@ describe('Verify Accessibility Support in Modals & Dialogs', () => { it('MM-T1468 Accessibility Support in Add people to Channel Dialog screen', () => { // # Add atleast 5 users for (let i = 0; i < 5; i++) { - cy.apiCreateUser().then(({user}) => { // eslint-disable-line + cy.apiCreateUser().then(({user}) => { // eslint-disable-line cy.apiAddUserToTeam(testTeam.id, user.id); }); } diff --git a/e2e-tests/cypress/tests/integration/channels/enterprise/guest_accounts/guest_identification_ui_not_cloud_spec.ts b/e2e-tests/cypress/tests/integration/channels/enterprise/guest_accounts/guest_identification_ui_not_cloud_spec.ts index f032569362..feb693770b 100644 --- a/e2e-tests/cypress/tests/integration/channels/enterprise/guest_accounts/guest_identification_ui_not_cloud_spec.ts +++ b/e2e-tests/cypress/tests/integration/channels/enterprise/guest_accounts/guest_identification_ui_not_cloud_spec.ts @@ -55,7 +55,8 @@ describe('Verify Guest User Identification in different screens', () => { }); // # Deactivate Guest user - cy.externalActivateUser(guestUser.id, false).wait(TIMEOUTS.FIVE_SEC); + cy.externalActivateUser(guestUser.id, false); + cy.wait(TIMEOUTS.FIVE_SEC); // # Switch channels away and back to reload the header cy.get('.SidebarChannel:contains(Town Square)').click(); diff --git a/e2e-tests/cypress/tests/support/task_commands.ts b/e2e-tests/cypress/tests/support/task_commands.ts index 2e0360d096..579821fc57 100644 --- a/e2e-tests/cypress/tests/support/task_commands.ts +++ b/e2e-tests/cypress/tests/support/task_commands.ts @@ -13,7 +13,7 @@ import {ChainableT} from '../types'; * @param {Object} channelId - where a post will be posted */ -interface PostMessageResp { +export interface PostMessageResp { id: string; status: number; data: any; diff --git a/e2e-tests/cypress/tests/utils/plugins.js b/e2e-tests/cypress/tests/utils/plugins.js index d66a2d59de..30d1d152bf 100644 --- a/e2e-tests/cypress/tests/utils/plugins.js +++ b/e2e-tests/cypress/tests/utils/plugins.js @@ -70,6 +70,7 @@ export const matterpollPlugin = { id: 'com.github.matterpoll.matterpoll', version: '1.5.0', url: 'https://github.com/matterpoll/matterpoll/releases/download/v1.5.0/com.github.matterpoll.matterpoll-1.5.0.tar.gz', + filename: 'com.github.matterpoll.matterpoll-1.5.0.tar.gz', }; export const testPlugin = {