qe-fe-automation
Version:
FE test automation framework using cypress
153 lines (139 loc) • 6.53 kB
text/typescript
import { LoginPage } from '@admin-lib/login';
import { SignupPage } from '@onboarding-lib/signup/signup';
import { CreateAccountPage } from '@onboarding-lib/signup/create_account';
import { Utility } from '@utility-lib/utility';
import { Random } from '@utility-lib/random';
import { GroupTravelSettings } from '@admin-lib/settings/overview/group-travel_settings';
import { TravelerModal } from '@profile-lib/traveler-info';
import { GuestInfoShort } from '@guest-invite-lib/interface';
import { guestInfoData } from '@fixtures/admin/guest_data';
const PersonalTravelSelector = {
personalNotSupportedModal: '.type-not-supported-modal',
dateOfBirthInput: '[data-testid="traveler-required-field-dob"]',
phoneNumberInput: '[data-testid="traveler-required-field-phone"]',
selectGender: '[data-testid="traveler-required-field-gender"]',
saveRequiredFieldData: '[data-testid="traveler-required-save"]',
homePagePromoModal: '[data-testid="modal-header-close-button"]',
adminFlagForPassport: '[data-qa-id="SETTINGS_TOGGLE_PASSPORT_DATA_REQUIRED"]',
clearPassportInfo: '.ta-button__content',
passPortRequiredModalShown: '.traveler-require-data__passport',
issuingCountry: '.ta-country-select',
clickSearchBox: '.ta-search',
disableToggle: '[class="cell-content"]',
dropDownList: '.ta-select-option__label',
requiredFieldMatchesCheckbox:
'[data-testid="traveler-required-field-matches-government-issued-id"]',
removeTravelerAtSearch: '.traveler-pill__remove',
addTravelerAtSearch: '[class*="traveler-pill traveler-pill__add-traveler"]',
searchTraveler: '.ta-search',
emptySearchText: '.ta-user-search-v3__empty',
travelerEmail: '.ta-user-search-v3__item-email'
};
const email = 'user' + '_' + Random.randomString() + '@passport.com';
const newUserCredentials = Cypress.env('newUser').NEW_USER_PASSWORD;
export class PersonalTravel {
static personalNotSupportedModalShown(): void {
cy.allure().logStep('verify personal travel tab is shown');
cy.get(PersonalTravelSelector.personalNotSupportedModal).should('be.visible');
}
static bookPersonalTravelItemShown(): void {
cy.allure().logStep(
'verify book personal travel item is shown in global nav dropdown'
);
cy.get(PersonalTravelSelector.personalNotSupportedModal).should('be.visible');
}
static closeHomePagePromoModal(): void {
cy.allure().logStep('close home page promo modal');
cy.get(PersonalTravelSelector.homePagePromoModal).click();
}
static createUserUnifiedOnboarding(): void {
cy.allure().logStep('create user in unified onboarding');
LoginPage.visitTALoginPage();
LoginPage.initiateSignUpFlow(email);
SignupPage.verifySignupEmailInInitiateSignupScreen(email);
SignupPage.initiateSignup();
SignupPage.verifySignupTriggerMessage(email);
CreateAccountPage.completeUnfiedOnboardingCreateAccount(email, newUserCredentials);
Utility.verifyPageTitle('Navan - Book a Trip');
}
static fillDob(): void {
cy.allure().logStep('add date of birth at checkout');
cy.get(PersonalTravelSelector.dateOfBirthInput).type('01011990');
}
static fillPhoneNumber(): void {
cy.allure().logStep('add phone number at checkout');
cy.get(PersonalTravelSelector.phoneNumberInput).type('408-579-9825');
}
static saveRequiredInfo(): void {
cy.allure().logStep('save required info at checkout');
cy.get(PersonalTravelSelector.saveRequiredFieldData).click();
}
static updateAdminPassportRequiredFlag(): void {
cy.allure().logStep('update admin passport required flag');
GroupTravelSettings.visitOverviewPage();
cy.get(PersonalTravelSelector.adminFlagForPassport).click();
}
static clearUserPassportInfoIfExist(): void {
cy.allure().logStep('clear user passport info in profile if exist');
TravelerModal.visitPage();
cy.get(PersonalTravelSelector.clearPassportInfo).contains('Clear').click();
cy.get(PersonalTravelSelector.clearPassportInfo).contains(' Save changes ').click();
}
static PassportInfoRequiredAtCheckout(): void {
cy.allure().logStep('verify passport info modal is shown at checkout');
cy.get(PersonalTravelSelector.passPortRequiredModalShown).should('be.visible');
}
static visitUsersPage(): void {
cy.allure().logStep('navigate to company users page');
cy.visit('app/company/users');
}
static fillUserEmail(firstname: string): void {
cy.allure().logStep('fill user email to disable');
cy.get(PersonalTravelSelector.clickSearchBox).type(firstname);
}
static disableUser(): void {
cy.allure().logStep('disable user');
cy.get(PersonalTravelSelector.disableToggle).contains('Enabled').click();
}
static fillGuestInfoFromCachedUser() {
cy.task('getDataFromCache', 'userInfo').then((userInfo: any) => {
const guestInfo: GuestInfoShort = {
firstName: userInfo.given_name,
lastName: userInfo.family_name,
email: userInfo.email,
costCenter: guestInfoData.guestCostCenter,
department: guestInfoData.guestDepartment
};
this.fillUserEmail(guestInfo.firstName);
});
}
static updateGenderAtCheckout(gender: string): void {
cy.allure().logStep('verify gender is required shown at checkout');
cy.get(PersonalTravelSelector.selectGender).click();
cy.get(PersonalTravelSelector.dropDownList).contains(gender).click();
cy.get(PersonalTravelSelector.requiredFieldMatchesCheckbox).click();
cy.get(PersonalTravelSelector.saveRequiredFieldData).click();
}
static removeTravelerFromSearch(): void {
cy.allure().logStep('remove traveler from search');
cy.get(PersonalTravelSelector.removeTravelerAtSearch).click();
}
static getDataFromCachedAdminUserAndSearch() {
cy.task('getDataFromCache', 'userResponse').then((response: any) => {
this.changeTravelerAtSearch(response.fullName);
});
}
static changeTravelerAtSearch(userFullName: string): void {
cy.allure().logStep('add traveler from search');
cy.get(PersonalTravelSelector.addTravelerAtSearch).click();
cy.get(PersonalTravelSelector.searchTraveler).type(userFullName);
}
static verifyNoTravelerInSearch(travelerText: string): void {
cy.allure().logStep('verify no traveler is shown in search');
cy.get(PersonalTravelSelector.emptySearchText).contains(travelerText);
}
static verifyTravelerInSearch(email: string): void {
cy.allure().logStep('verify no traveler is shown in search');
cy.get(PersonalTravelSelector.travelerEmail).contains(email);
}
}