[MM-48233] Migrate /support/saml_commands.js file to TypeScript (#24807)
* migrate saml_commands.js to typescript & added comments & added function used by saml_commands from common_login_commands.js to the common_login_commands.d.ts file * update(saml_commands.ts): added the TestSettings and SamlUser interface * update(cypress/tests/support/saml_commands.ts): enhance function header comments
Этот коммит содержится в:
3
e2e-tests/cypress/tests/support/common_login_commands.d.ts
поставляемый
3
e2e-tests/cypress/tests/support/common_login_commands.d.ts
поставляемый
@@ -21,5 +21,8 @@ declare namespace Cypress {
|
||||
* @returns {boolean} - true if error successfully found.
|
||||
*/
|
||||
checkForLDAPError(): Chainable;
|
||||
checkLoginPage: typeof checkLoginPage;
|
||||
checkLeftSideBar: typeof checkLeftSideBar;
|
||||
checkInvitePeoplePage: typeof checkInvitePeoplePage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import * as TIMEOUTS from '../fixtures/timeouts';
|
||||
import {stubClipboard} from '../utils';
|
||||
|
||||
Cypress.Commands.add('checkCreateTeamPage', (settings = {}) => {
|
||||
if (settings.user.userType === 'Guest' || settings.user.isGuest) {
|
||||
cy.findByText('Create a team').scrollIntoView().should('not.exist');
|
||||
} else {
|
||||
cy.findByText('Create a team').scrollIntoView().should('be.visible');
|
||||
}
|
||||
});
|
||||
|
||||
Cypress.Commands.add('doSamlLogin', (settings = {}) => {
|
||||
// # Go to login page
|
||||
cy.apiLogout();
|
||||
cy.visit('/login');
|
||||
cy.checkLoginPage(settings);
|
||||
|
||||
//click the login button
|
||||
cy.findByText(settings.loginButtonText).should('be.visible').click().wait(TIMEOUTS.ONE_SEC);
|
||||
});
|
||||
|
||||
Cypress.Commands.add('doSamlLogout', (settings = {}) => {
|
||||
cy.checkLeftSideBar(settings);
|
||||
|
||||
// # Logout then check login page
|
||||
cy.uiLogout();
|
||||
cy.checkLoginPage(settings);
|
||||
});
|
||||
|
||||
Cypress.Commands.add('getInvitePeopleLink', (settings = {}) => {
|
||||
cy.checkLeftSideBar(settings);
|
||||
|
||||
// # Open team menu and click 'Invite People'
|
||||
cy.uiOpenTeamMenu('Invite People');
|
||||
|
||||
stubClipboard().as('clipboard');
|
||||
cy.checkInvitePeoplePage();
|
||||
cy.findByTestId('InviteView__copyInviteLink').click();
|
||||
cy.get('@clipboard').its('contents').then((text) => {
|
||||
// # Close Invite People modal
|
||||
cy.uiClose();
|
||||
return cy.wrap(text);
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('setTestSettings', (loginButtonText, config) => {
|
||||
return {
|
||||
loginButtonText,
|
||||
siteName: config.TeamSettings.SiteName,
|
||||
siteUrl: config.ServiceSettings.SiteURL,
|
||||
teamName: '',
|
||||
user: null,
|
||||
};
|
||||
});
|
||||
125
e2e-tests/cypress/tests/support/saml_commands.ts
Обычный файл
125
e2e-tests/cypress/tests/support/saml_commands.ts
Обычный файл
@@ -0,0 +1,125 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {AdminConfig} from '@mattermost/types/config';
|
||||
import * as TIMEOUTS from '../fixtures/timeouts';
|
||||
import {ChainableT} from '../types';
|
||||
import {stubClipboard} from '../utils';
|
||||
|
||||
// SAMLUser interface is based on cypress/tests/fixtures/saml_users.json
|
||||
interface SAMLUser {
|
||||
username: string;
|
||||
password: string;
|
||||
email: string;
|
||||
firstname: string;
|
||||
lastname: string;
|
||||
userType: string;
|
||||
isGuest?: boolean;
|
||||
}
|
||||
|
||||
interface TestSettings {
|
||||
loginButtonText: string;
|
||||
siteName: string;
|
||||
siteUrl: string;
|
||||
teamName: string;
|
||||
user: SAMLUser | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* checkCreateTeamPage checks that the "create a team" element is visible in the page if user is not a Guest.
|
||||
* Otherwise it should not exist.
|
||||
* @param {TestSettings} settings - Settings object
|
||||
*/
|
||||
function checkCreateTeamPage(settings: TestSettings) {
|
||||
if (settings.user.userType === 'Guest' || settings.user.isGuest) {
|
||||
cy.findByText('Create a team').scrollIntoView().should('not.exist');
|
||||
} else {
|
||||
cy.findByText('Create a team').scrollIntoView().should('be.visible');
|
||||
}
|
||||
}
|
||||
|
||||
Cypress.Commands.add('checkCreateTeamPage', checkCreateTeamPage);
|
||||
|
||||
/**
|
||||
* doSamlLogin check that the login page is loaded with the correct settings (siteName) and logs in using SAML.
|
||||
* @param {TestSettings} settings - Settings object to perform SAML tests.
|
||||
*/
|
||||
function doSamlLogin(settings) {
|
||||
// # Go to login page
|
||||
cy.apiLogout();
|
||||
cy.visit('/login');
|
||||
cy.checkLoginPage(settings);
|
||||
|
||||
//click the login button
|
||||
cy.findByText(settings.loginButtonText).should('be.visible').click().wait(TIMEOUTS.ONE_SEC);
|
||||
}
|
||||
|
||||
Cypress.Commands.add('doSamlLogin', doSamlLogin);
|
||||
|
||||
/**
|
||||
* doSamlLogout logs out and checks that it reloads the login page with the correct settings (siteName).
|
||||
* @param {TestSettings} settings - Settings object to perform SAML tests.
|
||||
*/
|
||||
function doSamlLogout(settings) {
|
||||
cy.checkLeftSideBar(settings);
|
||||
|
||||
// # Logout then check login page
|
||||
cy.uiLogout();
|
||||
cy.checkLoginPage(settings);
|
||||
}
|
||||
|
||||
Cypress.Commands.add('doSamlLogout', doSamlLogout);
|
||||
|
||||
/**
|
||||
* getInvitePeopleLink gets the invite people link from the invite people modal
|
||||
* @param {TestSettings} settings - Settings object to perform SAML tests.
|
||||
* @returns {ChainableT<any>} - the invite people link wrapped in a cypress chainable
|
||||
*/
|
||||
function getInvitePeopleLink(settings: TestSettings): ChainableT<any> {
|
||||
cy.checkLeftSideBar(settings);
|
||||
|
||||
// # Open team menu and click 'Invite People'
|
||||
cy.uiOpenTeamMenu('Invite People');
|
||||
|
||||
stubClipboard().as('clipboard');
|
||||
cy.checkInvitePeoplePage();
|
||||
cy.findByTestId('InviteView__copyInviteLink').click();
|
||||
return cy.get('@clipboard').its('contents').then((text) => {
|
||||
// # Close Invite People modal
|
||||
cy.uiClose();
|
||||
return cy.wrap(text);
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('getInvitePeopleLink', getInvitePeopleLink);
|
||||
|
||||
/**
|
||||
* setTestSettings sets the test settings object based on the AdminConfig
|
||||
* @param {string} loginButtonText - The text of the login button
|
||||
* @param {AdminConfig} config - The config object
|
||||
* @returns {TestSettings} - The settings to use for SAML tests
|
||||
*/
|
||||
function setTestSettings(loginButtonText: string, config: AdminConfig): TestSettings {
|
||||
return {
|
||||
loginButtonText,
|
||||
siteName: config.TeamSettings.SiteName,
|
||||
siteUrl: config.ServiceSettings.SiteURL,
|
||||
teamName: '',
|
||||
user: null,
|
||||
};
|
||||
}
|
||||
|
||||
Cypress.Commands.add('setTestSettings', setTestSettings);
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
checkCreateTeamPage: typeof checkCreateTeamPage;
|
||||
doSamlLogin: typeof doSamlLogin;
|
||||
doSamlLogout: typeof doSamlLogout;
|
||||
getInvitePeopleLink: typeof getInvitePeopleLink;
|
||||
setTestSettings: typeof setTestSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user