freeCodeCamp/cypress/support/commands.ts
Sam Rice 8c03f0910c
refactor(cypress): convert additional specs to ts (#49143)
* convert challenge-hot-keys to ts

* rename selector object in challenge-hot-keys

* convert challenges/output to ts

* update selector and location objects in challenges/output

* convert common-components/searchBar to ts

* add missing type and fix final url assertion

* convert searchBar to kebab-case and fix URL assertion

* convert donate-page-donor to ts

* convert donation-block-completion-modal to ts

* resolve compilation errors in donation-block-completion-modal.ts

* convert intro-page to ts

* resolve compiler errors in intro-page.ts

* convert settings/certifications to ts

* add cypress testing library types to tsconfig for settings/certifications.ts

* convert settings/image-picture-check to ts

* convert settings/settings to ts

* convert settings/user-token to ts

* convert settings/username-change to ts

* resolve compiler errors in settings/username-change.ts

* convert default/top-contributor to ts

* add ES2017 to compilerOptions.lib in cypress/tsconfig

* edit custom command interface
2023-01-26 20:25:19 +00:00

76 lines
2.0 KiB
TypeScript

const login = () => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
cy.visit(`${Cypress.env('API_LOCATION')}/signin`);
cy.contains('Welcome back');
};
const preserveSession = () => {
Cypress.Cookies.preserveOnce(
'jwt_access_token',
'csrf_token',
'_csrf',
'connect.sid'
);
};
const setPrivacyTogglesToPublic = () => {
cy.get('#privacy-settings')
.find('.toggle-not-active')
.each(element => {
cy.wrap(element).click().should('have.class', 'toggle-active');
});
cy.get('[data-cy=save-privacy-settings]').click();
cy.get('#honesty-policy').find('button').click();
cy.contains('You have accepted our Academic Honesty Policy');
};
const goToSettings = () => {
cy.visit('/settings');
// Setting aliases here
cy.get('[data-cy=username-input]').as('usernameInput');
cy.get('[data-cy=username-form]').as('usernameForm');
};
const typeUsername = (username: string) => {
cy.get('@usernameInput')
.clear({ force: true })
.type(username, { force: true });
};
const resetUsername = () => {
cy.goToSettings();
cy.typeUsername('developmentuser');
cy.contains('Username is available');
cy.get('@usernameInput').type('{enter}', { force: true, release: false });
cy.contains('Account Settings for developmentuser').should('be.visible');
};
Cypress.Commands.add('login', login);
Cypress.Commands.add('preserveSession', preserveSession);
Cypress.Commands.add('setPrivacyTogglesToPublic', setPrivacyTogglesToPublic);
Cypress.Commands.add('goToSettings', goToSettings);
Cypress.Commands.add('typeUsername', typeUsername);
Cypress.Commands.add('resetUsername', resetUsername);
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
interface Chainable {
login: typeof login;
preserveSession: typeof preserveSession;
setPrivacyTogglesToPublic: typeof setPrivacyTogglesToPublic;
goToSettings: typeof goToSettings;
typeUsername(username: string): Chainable<JQuery<HTMLElement>>;
resetUsername: typeof resetUsername;
}
}