Migration typescript/channel sidebar.js (#25812)

* refactor: convert channel_sidebar.js to ts

- convert file to typescript

* refactor: add type for category on channel_sidebar.ts

- create interface Category into channel_sidebar.ts
- remove file with type category.d.ts

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Angel Mendez 2024-02-19 05:05:47 -06:00 committed by GitHub
parent d21236b908
commit a777e12055
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 48 deletions

View File

@ -1,44 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
/// <reference types="cypress" />
// ***************************************************************
// 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. `uiOpenFilePreviewModal`.
// ***************************************************************
declare namespace Cypress {
interface Chainable {
/**
* Create a new category
*
* @param [categoryName] category's name
*
* @example
* cy.uiCreateSidebarCategory();
*/
uiCreateSidebarCategory(categoryName?: string): Chainable;
/**
* Move a channel to a category.
* Open the channel menu, select Move to, and click either New Category or on the category.
*
* @param channelName channel's name
* @param categoryName category's name
* @param [newCategory=false] create a new category to move into
* @param [isChannelId=false] whether channelName is a channel ID
*
* @example
* cy.uiMoveChannelToCategory('Town Square', 'Favorites');
*/
uiMoveChannelToCategory(channelName: string, categoryName: string, newCategory: boolean = false, isChannelId: boolean = false): Chainable;
}
}

View File

@ -1,9 +1,18 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {ChainableT} from 'tests/types';
import {getRandomId} from '../../utils';
Cypress.Commands.add('uiCreateSidebarCategory', (categoryName = `category-${getRandomId()}`) => {
/**
* Create a new category
*
* @param [categoryName] category's name
*
* @example
* cy.uiCreateSidebarCategory();
*/
function uiCreateSidebarCategory(categoryName: string = `category-${getRandomId()}`): ChainableT<any> {
// # Click the New Category/Channel Dropdown button
cy.uiGetLHSAddChannelButton().click();
@ -21,9 +30,23 @@ Cypress.Commands.add('uiCreateSidebarCategory', (categoryName = `category-${getR
cy.contains('.SidebarChannelGroup', categoryName, {matchCase: false});
return cy.wrap({displayName: categoryName});
});
}
Cypress.Commands.add('uiMoveChannelToCategory', (channelName, categoryName, newCategory = false, isChannelId = false) => {
Cypress.Commands.add('uiCreateSidebarCategory', uiCreateSidebarCategory);
/**
* Move a channel to a category.
* Open the channel menu, select Move to, and click either New Category or on the category.
*
* @param channelName channel's name
* @param categoryName category's name
* @param [newCategory=false] create a new category to move into
* @param [isChannelId=false] whether channelName is a channel ID
*
* @example
* cy.uiMoveChannelToCategory('Town Square', 'Favorites');
*/
function uiMoveChannelToCategory(channelName: string, categoryName: string, newCategory = false, isChannelId = false): ChainableT<any> {
// # Open the channel menu, select Move to
cy.uiGetChannelSidebarMenu(channelName, isChannelId).within(() => {
cy.findByText('Move to...').should('be.visible').trigger('mouseover');
@ -48,4 +71,16 @@ Cypress.Commands.add('uiMoveChannelToCategory', (channelName, categoryName, newC
}
return cy.wrap({displayName: categoryName});
});
}
Cypress.Commands.add('uiMoveChannelToCategory', uiMoveChannelToCategory);
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
uiCreateSidebarCategory: typeof uiCreateSidebarCategory;
uiMoveChannelToCategory: typeof uiMoveChannelToCategory;
}
}
}