refactor: convert channel_moderation files to ts (#28482)

* refactor: convert channel_moderation files to ts

- convert js files to ts
- update data types accordingly
- fix lint issues

Fixes: #21332

* fix: update argument type for visitChannel

- update type
- fix types issues

* refactor: change return type for getAdminAccount()

- change return type to getAdminAccount as UserProfile
Этот коммит содержится в:
Angel Mendez
2024-10-08 06:12:57 -06:00
коммит произвёл GitHub
родитель f0918e1c01
Коммит 89f04af631
10 изменённых файлов: 57 добавлений и 37 удалений

Просмотреть файл

@@ -10,6 +10,9 @@
// Stage: @prod
// Group: @channels @enterprise @system_console @channel_moderation
import {Channel} from '@mattermost/types/channels';
import {Team} from '@mattermost/types/teams';
import {UserProfile} from '@mattermost/types/users';
import {checkboxesTitleToIdMap} from './constants';
import {
@@ -24,10 +27,10 @@ import {
} from './helpers';
describe('MM-23102 - Channel Moderation - Channel Mentions', () => {
let regularUser;
let guestUser;
let testTeam;
let testChannel;
let regularUser: UserProfile;
let guestUser: UserProfile;
let testTeam: Team;
let testChannel: Channel;
before(() => {
// * Check if server has license
@@ -38,7 +41,7 @@ describe('MM-23102 - Channel Moderation - Channel Mentions', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -10,6 +10,9 @@
// Stage: @prod
// Group: @channels @enterprise @system_console @channel_moderation
import {Channel} from '@mattermost/types/channels';
import {Team} from '@mattermost/types/teams';
import {UserProfile} from '@mattermost/types/users';
import {checkboxesTitleToIdMap} from './constants';
import {
@@ -21,10 +24,10 @@ import {
} from './helpers';
describe('MM-23102 - Channel Moderation - Create Posts', () => {
let regularUser;
let guestUser;
let testTeam;
let testChannel;
let regularUser: UserProfile;
let guestUser: UserProfile;
let testTeam: Team;
let testChannel: Channel;
before(() => {
// * Check if server has license
@@ -35,7 +38,7 @@ describe('MM-23102 - Channel Moderation - Create Posts', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -1,13 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Channel} from '@mattermost/types/channels';
import * as TIMEOUTS from '../../../../../fixtures/timeouts';
import {getAdminAccount} from '../../../../../support/env';
import {checkBoxes} from './constants';
import {UserProfile} from '@mattermost/types/users';
import {Team} from '@mattermost/types/teams';
// # Visits the channel configuration for a channel with channelName
export const visitChannelConfigPage = (channel) => {
export const visitChannelConfigPage = (channel: Channel) => {
cy.apiAdminLogin();
cy.visit('/admin_console/user_management/channels');
cy.get('.DataGrid_searchBar').within(() => {
@@ -31,7 +34,7 @@ export const disablePermission = (permission) => {
};
// # Saves channel config and navigates back to the channel config page if specified
export const saveConfigForChannel = (channelName = false, clickConfirmationButton = false) => {
export const saveConfigForChannel = (channelName: string = null, clickConfirmationButton = false) => {
cy.get('#saveSetting').then((btn) => {
if (btn.is(':enabled')) {
btn.click();
@@ -62,14 +65,14 @@ export const saveConfigForChannel = (channelName = false, clickConfirmationButto
};
// # Visits a channel as the member specified
export const visitChannel = (user, channel, team) => {
export const visitChannel = (user: UserProfile, channel: Channel, team: Team) => {
cy.apiLogin(user);
cy.visit(`/${team.name}/channels/${channel.name}`);
cy.get('#postListContent', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible');
};
// # Checks to see if we got a system message warning after using @all/@here/@channel
export const postChannelMentionsAndVerifySystemMessageExist = (channelName) => {
export const postChannelMentionsAndVerifySystemMessageExist = (channelName: string) => {
function getSystemMessage(text) {
return `Channel notifications are disabled in ${channelName}. The ${text} did not trigger any notifications.`;
}
@@ -115,7 +118,7 @@ export const enablePermission = (permission) => {
};
// # Checks to see if we did not get a system message warning after using @all/@here/@channel
export const postChannelMentionsAndVerifySystemMessageNotExist = (channel) => {
export const postChannelMentionsAndVerifySystemMessageNotExist = (channel: Channel) => {
function getSystemMessage(text) {
return `Channel notifications are disabled in ${channel.name}. The ${text} did not trigger any notifications.`;
}
@@ -178,7 +181,7 @@ export const goToSystemScheme = () => {
};
// # Goes to the permissions page and creates a new team override scheme with schemeName
export const goToPermissionsAndCreateTeamOverrideScheme = (schemeName, team) => {
export const goToPermissionsAndCreateTeamOverrideScheme = (schemeName: string, team: Team) => {
cy.apiAdminLogin();
cy.visit('/admin_console/user_management/permissions');
cy.findByTestId('team-override-schemes-link').click();
@@ -192,7 +195,7 @@ export const goToPermissionsAndCreateTeamOverrideScheme = (schemeName, team) =>
};
// # Goes to the permissions page and clicks edit or delete for a team override scheme
export const deleteOrEditTeamScheme = (schemeDisplayName, editOrDelete) => {
export const deleteOrEditTeamScheme = (schemeDisplayName: string, editOrDelete: string) => {
cy.apiAdminLogin();
cy.visit('/admin_console/user_management/permissions');
cy.findByTestId(`${schemeDisplayName}-${editOrDelete}`).click();
@@ -208,7 +211,7 @@ export const viewManageChannelMembersRHS = () => {
};
// # Enable (check) all the permissions in the channel moderation widget through the API
export const enableDisableAllChannelModeratedPermissionsViaAPI = (channel, enable = true) => {
export const enableDisableAllChannelModeratedPermissionsViaAPI = (channel: Channel, enable = true) => {
cy.externalRequest(
{
user: getAdminAccount(),
@@ -263,7 +266,7 @@ export const resetSystemSchemePermissionsToDefault = () => {
saveConfigForScheme();
};
export const demoteToChannelOrTeamMember = (userId, id, channelsOrTeams = 'channels') => {
export const demoteToChannelOrTeamMember = (userId: string, id: string, channelsOrTeams = 'channels') => {
cy.externalRequest({
user: getAdminAccount(),
method: 'put',
@@ -275,7 +278,7 @@ export const demoteToChannelOrTeamMember = (userId, id, channelsOrTeams = 'chann
});
};
export const promoteToChannelOrTeamAdmin = (userId, id, channelsOrTeams = 'channels') => {
export const promoteToChannelOrTeamAdmin = (userId: string, id: string, channelsOrTeams = 'channels') => {
cy.externalRequest({
user: getAdminAccount(),
method: 'put',

Просмотреть файл

@@ -49,7 +49,7 @@ describe('MM-23102 - Channel Moderation - Higher Scoped Scheme', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -10,6 +10,9 @@
// Stage: @prod
// Group: @channels @enterprise @system_console @channel_moderation
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 {getRandomId} from '../../../../../utils';
@@ -37,10 +40,10 @@ function addButtonDoesNotExists() {
}
describe('MM-23102 - Channel Moderation - Manage Members', () => {
let regularUser;
let guestUser;
let testTeam;
let testChannel;
let regularUser: UserProfile;
let guestUser: UserProfile;
let testTeam: Team;
let testChannel: Channel;
before(() => {
// * Check if server has license
@@ -55,7 +58,7 @@ describe('MM-23102 - Channel Moderation - Manage Members', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -9,6 +9,9 @@
// Group: @channels @enterprise @system_console @channel_moderation
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 {getRandomId} from '../../../../../utils';
import {getAdminAccount} from '../../../../../support/env';
@@ -28,10 +31,10 @@ import {
} from './helpers';
describe('MM-23102 - Channel Moderation - Post Reactions', () => {
let regularUser;
let guestUser;
let testTeam;
let testChannel;
let regularUser: UserProfile;
let guestUser: UserProfile;
let testTeam: Team;
let testChannel: Channel;
const admin = getAdminAccount();
before(() => {
@@ -43,7 +46,7 @@ describe('MM-23102 - Channel Moderation - Post Reactions', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -10,6 +10,9 @@
// Stage: @prod
// Group: @channels @enterprise @system_console @channel_moderation
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 {checkBoxes} from './constants';
@@ -21,9 +24,9 @@ import {
} from './helpers';
describe('Channel Moderation', () => {
let guestUser;
let testTeam;
let testChannel;
let guestUser: UserProfile;
let testTeam: Team;
let testChannel: Channel;
before(() => {
// * Check if server has license
@@ -33,7 +36,7 @@ describe('Channel Moderation', () => {
testTeam = team;
testChannel = channel;
cy.apiCreateGuestUser().then(({guest}) => {
cy.apiCreateGuestUser({}).then(({guest}) => {
guestUser = guest;
cy.apiAddUserToTeam(testTeam.id, guestUser.id).then(() => {

Просмотреть файл

@@ -1,6 +1,8 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {UserProfile} from '@mattermost/types/users';
export interface User {
username: string;
password: string;
@@ -12,7 +14,7 @@ export function getAdminAccount() {
username: Cypress.env('adminUsername'),
password: Cypress.env('adminPassword'),
email: Cypress.env('adminEmail'),
};
} as UserProfile;
}
export function getDBConfig() {

Просмотреть файл

@@ -13,7 +13,7 @@ import {getRandomId} from '../utils';
function externalActivateUser(userId: string, active = true) {
const admin = getAdminAccount();
cy.externalRequest({user: admin, method: 'PUT', path: `users/${userId}/active`, data: {active}});
return cy.externalRequest({user: admin, method: 'PUT', path: `users/${userId}/active`, data: {active}});
}
Cypress.Commands.add('externalActivateUser', externalActivateUser);