|
| 1 | +// *********************************************** |
| 2 | +// This example namespace declaration will help |
| 3 | +// with Intellisense and code completion in your |
| 4 | +// IDE or Text Editor. |
| 5 | +// *********************************************** |
| 6 | +declare namespace Cypress { |
| 7 | + interface Chainable<Subject = any> { |
| 8 | + selectCash(): Chainable<Subject>; |
| 9 | + |
| 10 | + selectCreditCard(param: { |
| 11 | + cardNumber: string; |
| 12 | + expiryDate: string; |
| 13 | + cvv: string; |
| 14 | + }): Chainable<Subject>; |
| 15 | + |
| 16 | + selectDebit(param: { |
| 17 | + accountHolder: string; |
| 18 | + iban: string; |
| 19 | + bic: string; |
| 20 | + }): Chainable<Subject>; |
| 21 | + |
| 22 | + shouldShowSubmittedCash(param: { |
| 23 | + name: string; |
| 24 | + }): Chainable<Subject>; |
| 25 | + |
| 26 | + shouldShowSubmittedCreditCard(param: { |
| 27 | + name: string; |
| 28 | + cardNumber: string; |
| 29 | + expiryDate: string; |
| 30 | + cvv: string; |
| 31 | + }): Chainable<Subject>; |
| 32 | + |
| 33 | + shouldShowSubmittedDebit(param: { |
| 34 | + name: string; |
| 35 | + accountHolder: string; |
| 36 | + iban: string; |
| 37 | + bic: string; |
| 38 | + }): Chainable<Subject>; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +Cypress.Commands.add('selectCash', () => { |
| 43 | + return cy |
| 44 | + .then(() => cy |
| 45 | + .get('.payment-form--payment-method').click() |
| 46 | + .get('mat-option').contains('Cash').click() |
| 47 | + ) |
| 48 | +}) |
| 49 | + |
| 50 | +Cypress.Commands.add('selectCreditCard', (params) => { |
| 51 | + return cy |
| 52 | + .then(() => cy |
| 53 | + .get('.payment-form--payment-method').click() |
| 54 | + .get('mat-option').contains('Credit Card').click() |
| 55 | + ) |
| 56 | + |
| 57 | + .then(() => cy |
| 58 | + .get('.creditcard-form-input--cardnumber') |
| 59 | + .focus() |
| 60 | + .type(params.cardNumber) |
| 61 | + ) |
| 62 | + |
| 63 | + .then(() => cy |
| 64 | + .get('.creditcard-form-input--expiryDate') |
| 65 | + .focus() |
| 66 | + .type(params.expiryDate) |
| 67 | + ) |
| 68 | + |
| 69 | + .then(() => cy |
| 70 | + .get('.creditcard-form-input--cvv') |
| 71 | + .focus() |
| 72 | + .type(params.cvv) |
| 73 | + ) |
| 74 | +}) |
| 75 | + |
| 76 | +Cypress.Commands.add('selectDebit', (params) => { |
| 77 | + return cy |
| 78 | + .then(() => cy |
| 79 | + .get('.payment-form--payment-method').click() |
| 80 | + .get('mat-option').contains('Debit').click() |
| 81 | + ) |
| 82 | + |
| 83 | + .then(() => cy |
| 84 | + .get('.debit-form-input--accountHolder') |
| 85 | + .focus() |
| 86 | + .type(params.accountHolder) |
| 87 | + ) |
| 88 | + |
| 89 | + .then(() => cy |
| 90 | + .get('.debit-form-input--iban') |
| 91 | + .focus() |
| 92 | + .type(params.iban) |
| 93 | + ) |
| 94 | + |
| 95 | + .then(() => cy |
| 96 | + .get('.debit-form-input--bic') |
| 97 | + .focus() |
| 98 | + .type(params.bic) |
| 99 | + ) |
| 100 | +}) |
| 101 | + |
| 102 | +Cypress.Commands.add('shouldShowSubmittedCash', (param) => { |
| 103 | + return cy.get('div.submitted-value-container') |
| 104 | + .should( |
| 105 | + 'contain.text', |
| 106 | + `{\n "name": "${param.name}",\n "payments": [\n {\n "paymentMethod": "cash",\n "paymentDetails": null\n }\n ]\n}` |
| 107 | + ) |
| 108 | +}); |
| 109 | + |
| 110 | +Cypress.Commands.add('shouldShowSubmittedCreditCard', (param) => { |
| 111 | + return cy.get('div.submitted-value-container') |
| 112 | + .should( |
| 113 | + 'contain.text', |
| 114 | + `{\n "name": "${param.name}",\n "payments": [\n {\n "paymentMethod": "creditCard",\n "paymentDetails": {\n "cardNumber": "${param.cardNumber}",\n "expiryDate": "${param.expiryDate}",\n "cvv": "${param.cvv}"\n }\n }\n ]\n}` |
| 115 | + ) |
| 116 | +}); |
| 117 | + |
| 118 | +Cypress.Commands.add('shouldShowSubmittedDebit', (param) => { |
| 119 | + return cy.get('div.submitted-value-container') |
| 120 | + .should( |
| 121 | + 'contain.text', |
| 122 | + `{\n "name": "${param.name}",\n "payments": [\n {\n "paymentMethod": "debit",\n "paymentDetails": {\n "accountHolder": "${param.accountHolder}",\n "iban": "${param.iban}",\n "bic": "${param.bic}"\n }\n }\n ]\n}` |
| 123 | + ) |
| 124 | +}); |
0 commit comments