Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply typescript #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["@babel/plugin-transform-typescript"],
"presets": ["@babel/preset-typescript"]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

class CouponApplication {
export class CouponApplication {
postHeaders: { Accept: string; 'Accept-Encoding': string; 'Accept-Language': string; 'Content-Type': string; Referer: string; 'X-Csrftoken': null; 'X-Requested-With': string; };
getHeaders: { Accept: string; 'Accept-Encoding': string; 'Accept-Language': string; 'sec-fetch-mode': string; 'sec-fetch-site': string; 'sec-fetch-user': string; };
constructor() {
this.postHeaders = {
Accept: 'application/json, text/javascript, */*; q=0.01',
Expand All @@ -25,11 +27,11 @@ class CouponApplication {
cy.login_using_api(Cypress.env('LMS_USER_EMAIL'), Cypress.env('LMS_USER_PASSWORD'))
}

enableConsent(courseKey) {
enableConsent(courseKey: any) {
cy.request(`${Cypress.env('lms_url')}/courses/`)
cy.log(`${Cypress.env('lms_url')}/courses/`)
cy.getCookie('csrftoken')
.should('exist').then((csrfVal) => {
.should('exist').then((csrfVal: any) => {
this.postHeaders['X-Csrftoken'] = csrfVal.value
})
return cy.request(`${Cypress.env('lms_url')}/api/user/v1/accounts`).then((response) => {
Expand All @@ -47,7 +49,7 @@ class CouponApplication {
})
}

applyCoupon(couponId, courseSku) {
applyCoupon(couponId: any, courseSku: any) {
const applyCouponUrl = `${Cypress.env('ecommerce_url')}/coupons/redeem/?code=${couponId}&sku=${courseSku}`
return cy.request({
method: 'GET',
Expand All @@ -57,4 +59,4 @@ class CouponApplication {
}
}

export default CouponApplication
// export default CouponApplication
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
const uuidv4 = require('uuid/v4')

function getDates() {
const dates = {}
const targetDate = new Date()
targetDate.setDate(targetDate.getDate() - 3)
dates.start_date = targetDate.toISOString()
targetDate.setDate(targetDate.getDate() + 20)
dates.end_date = targetDate.toISOString()
return dates
// const dates = {};
const targetDate = new Date();
targetDate.setDate(targetDate.getDate() - 3);
// dates.start_date = targetDate.toISOString();
targetDate.setDate(targetDate.getDate() + 20);
// dates.end_date = targetDate.toISOString();
const dates = {
start_date: targetDate.toISOString(),
end_date : targetDate.toISOString()
}
return dates;
}

class EnterpriseCoupons {
export class EnterpriseCoupons {
coursesku: null;
coursekey: null;
defaultHeaders: { Accept: string; 'Accept-Encoding': string; 'Accept-Language': string; 'Content-Type': string; Referer: string; Origin: any; 'X-Csrftoken': null; 'X-Requested-With': string; };
constructor() {
this.Coursesku = null
this.Coursekey = null
this.coursesku = null
this.coursekey = null
this.defaultHeaders = {
Accept: 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br',
Expand All @@ -31,7 +38,7 @@ class EnterpriseCoupons {
cy.request(`${Cypress.env('ecommerce_url')}/coupons/`)
}

prepareCouponData(coupon) {
prepareCouponData(coupon: string | number) {
const randomString = uuidv4().substr(-11)
const couponTitle = `Test_Coupon_${randomString}`
return cy.fixture('coupon_creation_data').then((couponData) => {
Expand All @@ -45,9 +52,9 @@ class EnterpriseCoupons {
})
}

createCoupon(requestBody) {
createCoupon(requestBody: string | object | undefined) {
cy.getCookie('ecommerce_csrftoken')
.should('exist').then((csrfVal) => {
.should('exist').then((csrfVal: any) => {
this.defaultHeaders['X-Csrftoken'] = csrfVal.value
})
const createCouponUrl = `${Cypress.env('ecommerce_url')}/api/v2/enterprise/coupons/`
Expand All @@ -59,7 +66,7 @@ class EnterpriseCoupons {
})
}

fetchCouponReport(couponId) {
fetchCouponReport(couponId: any) {
const fetchCouponUrl = `${Cypress.env('ecommerce_url')}/api/v2/coupons/coupon_reports/${couponId}/`
return cy.request({
method: 'GET',
Expand All @@ -71,22 +78,22 @@ class EnterpriseCoupons {
const enterpriseCatalogUrl = `${Cypress.env('ecommerce_url')}/api/v2/enterprise/customer_catalogs/${Cypress.env('enterprise_catalog')}`
cy.request(enterpriseCatalogUrl).then((response) => {
const { results } = response.body
const skuCourse = results.filter(function (result) {
const skuCourse = results.filter(function (result: { first_enrollable_paid_seat_sku: any; }) {
return result.first_enrollable_paid_seat_sku
})[0]
this.courseSku = skuCourse.first_enrollable_paid_seat_sku
this.courseKey = skuCourse.key
this.coursesku = skuCourse.first_enrollable_paid_seat_sku
this.coursekey = skuCourse.key
})
}

deleteCoupon(couponId) {
deleteCoupon(couponId: any) {
cy.getCookie('ecommerce_csrftoken')
.should('exist').then((csrfVal) => {
.should('exist').then((csrfVal: any) => {
this.defaultHeaders['X-Csrftoken'] = csrfVal.value
})
const fetchCouponUrl = `${Cypress.env('ecommerce_url')}/api/v2/enterprise/coupons/${couponId}/`
cy.getCookie('ecommerce_csrftoken')
.should('exist').then((csrfVal) => {
.should('exist').then((csrfVal: any) => {
this.defaultHeaders['X-Csrftoken'] = csrfVal.value
this.defaultHeaders.Referer = fetchCouponUrl
})
Expand All @@ -98,4 +105,4 @@ class EnterpriseCoupons {
}
}

export default EnterpriseCoupons
// export default EnterpriseCoupons
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const uuidv4 = require('uuid/v4')

class HelperFunctions {
export class HelperFunctions {
/**
* Helper method to make a dictionary of URls and their labels inside an element
*
* @param {Object} elems Elements which contains links
*/
static getLabelAndUrlsDict(elems) {
static getLabelAndUrlsDict(elems: any) {
const names = [...elems].map(el => el.textContent.trim())
const urls = [...elems].map(el => el.getAttribute('href'))
return Object.assign({}, ...names.map((n, index) => ({ [n]: urls[index] })))
Expand All @@ -25,33 +24,29 @@ class HelperFunctions {
/**
* Helper method to extract url from email text
*
* @param {String} emailText Email body from which url needs to be searched
* @param {String} subString any substring which should ne present in the target url
*/
static extractUrlFromEmail(emailText, subString) {
static extractUrlFromEmail(emailText: { match: (arg0: RegExp) => void; }, subString: string) {
const urlRegex = new RegExp(String.raw`(https?:\/\/[^\s]+${subString}?[^\s]+)`)
const urls = emailText.match(urlRegex)
const urls:any = emailText.match(urlRegex)
return urls[0]
}

/**
* Helper method to extract access code from email text
*
* @param {String} emailText Email body from which code needs to be searched
*/
static extractAccessCodeFromEmail(emailText) {
static extractAccessCodeFromEmail(emailText: { match: (arg0: RegExp) => void; }) {
const codeRegex = new RegExp(String.raw`(?<=Access Code: )\w+`)
const code = emailText.match(codeRegex)
const code: any = emailText.match(codeRegex)
return code[0]
}

/**
* Helper method to parse report data from response
*
* @param {String} responseBody body from which data needs to be split
*/
static parseReportData(responseBody) {
const splitDataArr = responseBody.split(/[\n]/)
static parseReportData(responseBody: { split: (arg0: RegExp) => void; }) {
const splitDataArr: any = responseBody.split(/[\n]/)
const reportData = splitDataArr[1]
const dataArr = reportData.split(',')
const mapReportData = {
Expand All @@ -64,25 +59,21 @@ class HelperFunctions {

/**
* Helper method to convert date to Short From
*
* @param {Date} originalDate Date which needs to be converted into short form
*/
static convertDateToShortFormat(originalDate) {
static convertDateToShortFormat(originalDate: string | number | Date) {
const date = new Date(originalDate)
return Intl.DateTimeFormat('en-US').format(date)
}

/**
* Helper method to get coupon data from coupon report
*
* @param {String} couponReport Coupon Report from whihc we need specific data
*/
static readCouponData(couponReport) {
static readCouponData(couponReport: { match: { (arg0: RegExp): void; (arg0: RegExp): void; }; }) {
const data = {
couponName: couponReport.match(/Test_Coupon_\w+/g),
dates: couponReport.match(/\w+ \d+, \d+/g),
}
return data
}
}
export default HelperFunctions

Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
class CodeManagementPage {
getFormField(fieldName) {
export class CodeManagementPage {
getFormField(fieldName: string) {
return cy.get(`[name="${fieldName}"]`)
}

getLabels(labelName) {
const labels = { Email: 1, Company: 2, Codes: 3 }
return cy.get(`.form-group:nth-of-type(${labels[labelName]}) label`)
getLabels(labelName: string) {
interface Labels {
[key:string]: number
Email: number;
Company: number;
Codes: number;
}
const labels :Labels = { Email: 1, Company: 2, Codes: 3 }
const targetLabel = labels[labelName]
return cy.get(`.form-group:nth-of-type(${targetLabel}) label`)
}

getRequestCodesButton() {
Expand Down Expand Up @@ -36,7 +43,7 @@ class CodeManagementPage {
cy.get('.download-btn').click()
}

getCouponCode(columnNumber) {
getCouponCode(columnNumber: any) {
return cy.get(`.coupon-details-table td:nth-child(${columnNumber})`)
}

Expand Down Expand Up @@ -72,7 +79,7 @@ class CodeManagementPage {
return cy.get('.table tbody tr')
}

selectCodesForBulkAssignment(rowNumber) {
selectCodesForBulkAssignment(rowNumber: number) {
cy.get(`.table tbody tr:nth-of-type(${rowNumber}) .form-check label`).click()
}

Expand Down Expand Up @@ -109,4 +116,3 @@ class CodeManagementPage {
}
}

export default CodeManagementPage
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class EnterpriseDashboard {
getLogoAltAttributes(logoContainer, attributeName, logoType = '/') {
export class EnterpriseDashboard {
getLogoAltAttributes(logoContainer: string, attributeName: string, logoType: string = '/') {
// This function takes parent container name, logo type and attribute name
// as parameter and return attribute value
return cy.get(logoContainer).find(`a[href="${logoType}"]>img`).invoke('attr', attributeName)
Expand All @@ -9,42 +9,42 @@ class EnterpriseDashboard {
return cy.get('footer .nav-item .nav-link')
}

getCardText(cardSequenceNumber) {
getCardText(cardSequenceNumber: number) {
return cy.get(`:nth-child(${cardSequenceNumber})>.number-card .card-text`)
}

getCardTitle(cardSequenceNumber) {
getCardTitle(cardSequenceNumber: number) {
return cy.get(`:nth-child(${cardSequenceNumber})>.number-card .card-title>span:nth-child(1)`)
}

getCardQuestions(cardSequenceNumber) {
getCardQuestions(cardSequenceNumber: number) {
return cy.get(`:nth-child(${cardSequenceNumber})>.number-card .card-footer .d-flex .label`)
}

getTableTitle() {
return cy.get('.table-title')
}

getTableHeaders(tableName) {
getTableHeaders(tableName: string) {
return cy.get(`.${tableName} .table thead .btn-header>span`)
}

getEmptyTableWarning() {
return cy.get('.alert-warning .message')
}

getSpecificTableHeader(tableName, columnNumber) {
getSpecificTableHeader(tableName: string, columnNumber: number) {
return cy.get(`.${tableName} .table thead th:nth-child(${columnNumber}) .btn-header>span`)
}

openCardDetailedBreakdownArea(cardSequenceNumber) {
openCardDetailedBreakdownArea(cardSequenceNumber: number) {
cy.get(`:nth-child(${cardSequenceNumber})>.number-card .footer-title>.toggle-collapse`)
.should('have.attr', 'aria-expanded', 'false')
.click()
.should('have.attr', 'aria-expanded', 'true')
}

clickCardDetailedBreakdownQuestion(cardSequenceNumber, questionText) {
clickCardDetailedBreakdownQuestion(cardSequenceNumber: number, questionText: string | number | RegExp) {
return cy.get(`:nth-child(${cardSequenceNumber})>.number-card .card-footer .d-flex .label`)
.contains(questionText)
.click()
Expand All @@ -55,4 +55,4 @@ class EnterpriseDashboard {
}
}

export default EnterpriseDashboard
// export default EnterpriseDashboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LandingPage {
getLogoAltAttributes(logoContainer, attributeName, logoType = '/') {
export class LandingPage {
getLogoAltAttributes(logoContainer: string, attributeName: string, logoType: string = '/') {
// This function takes parent container name, logo type and attribute name
// as parameter and return attribute value
return cy.get(logoContainer).find(`a[href="${logoType}"]>img`).invoke('attr', attributeName)
Expand All @@ -21,14 +21,14 @@ class LandingPage {
return cy.get('.enterprise-list td a')
}

searchEnterprise(enterpriseName) {
searchEnterprise(enterpriseName: string) {
cy.server()
cy.route(`**search=${enterpriseName}**`).as('results')
cy.get('input[type="search"]').clear().type(`${enterpriseName}{enter}`)
cy.wait('@results')
}

goToEnterprise(enterpriseName) {
goToEnterprise(enterpriseName: string | number | RegExp) {
// Open target enterprise page
cy.get('.enterprise-list td>a').contains(enterpriseName).click()
// Wait for page to load properly by verifying that dashboard cards are visible
Expand All @@ -51,4 +51,4 @@ class LandingPage {
}
}

export default LandingPage
// export default LandingPage
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class LoginPage {
loginUser(userEmail, userPassword) {
export class LoginPage {
loginUser(userEmail: string, userPassword: string) {
cy.get('#login-email').type(userEmail)
cy.get('#login-password').type(userPassword)
cy.get('.action').should('have.text', 'Sign in').click()
}
}

export default LoginPage
Loading