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

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

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

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

@@ -1,13 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import {Channel} from '@mattermost/types/channels';
import * as TIMEOUTS from '../../../../../fixtures/timeouts'; import * as TIMEOUTS from '../../../../../fixtures/timeouts';
import {getAdminAccount} from '../../../../../support/env'; import {getAdminAccount} from '../../../../../support/env';
import {checkBoxes} from './constants'; 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 // # Visits the channel configuration for a channel with channelName
export const visitChannelConfigPage = (channel) => { export const visitChannelConfigPage = (channel: Channel) => {
cy.apiAdminLogin(); cy.apiAdminLogin();
cy.visit('/admin_console/user_management/channels'); cy.visit('/admin_console/user_management/channels');
cy.get('.DataGrid_searchBar').within(() => { 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 // # 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) => { cy.get('#saveSetting').then((btn) => {
if (btn.is(':enabled')) { if (btn.is(':enabled')) {
btn.click(); btn.click();
@@ -62,14 +65,14 @@ export const saveConfigForChannel = (channelName = false, clickConfirmationButto
}; };
// # Visits a channel as the member specified // # 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.apiLogin(user);
cy.visit(`/${team.name}/channels/${channel.name}`); cy.visit(`/${team.name}/channels/${channel.name}`);
cy.get('#postListContent', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); 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 // # 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) { function getSystemMessage(text) {
return `Channel notifications are disabled in ${channelName}. The ${text} did not trigger any notifications.`; 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 // # 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) { function getSystemMessage(text) {
return `Channel notifications are disabled in ${channel.name}. The ${text} did not trigger any notifications.`; 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 // # 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.apiAdminLogin();
cy.visit('/admin_console/user_management/permissions'); cy.visit('/admin_console/user_management/permissions');
cy.findByTestId('team-override-schemes-link').click(); 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 // # 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.apiAdminLogin();
cy.visit('/admin_console/user_management/permissions'); cy.visit('/admin_console/user_management/permissions');
cy.findByTestId(`${schemeDisplayName}-${editOrDelete}`).click(); 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 // # 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( cy.externalRequest(
{ {
user: getAdminAccount(), user: getAdminAccount(),
@@ -263,7 +266,7 @@ export const resetSystemSchemePermissionsToDefault = () => {
saveConfigForScheme(); saveConfigForScheme();
}; };
export const demoteToChannelOrTeamMember = (userId, id, channelsOrTeams = 'channels') => { export const demoteToChannelOrTeamMember = (userId: string, id: string, channelsOrTeams = 'channels') => {
cy.externalRequest({ cy.externalRequest({
user: getAdminAccount(), user: getAdminAccount(),
method: 'put', 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({ cy.externalRequest({
user: getAdminAccount(), user: getAdminAccount(),
method: 'put', method: 'put',

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

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

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

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

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

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

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

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

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

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

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

@@ -13,7 +13,7 @@ import {getRandomId} from '../utils';
function externalActivateUser(userId: string, active = true) { function externalActivateUser(userId: string, active = true) {
const admin = getAdminAccount(); 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); Cypress.Commands.add('externalActivateUser', externalActivateUser);