Skip to content

Commit

Permalink
test(e2e): refactor contact page fill form method
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored and SGrueber committed May 25, 2020
1 parent 1c71b37 commit 4c8a2d3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions e2e/cypress/integration/framework/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export function fillFormField(parent: string, key: string, value: number | strin
const field = form.find(`[data-testing-id="${key}"]`);
expect(field.length).to.equal(1, `expected to find one form field "${key}" in "${parent}"`);
const tagName = field.prop('tagName');
expect(tagName).to.match(/^(INPUT|SELECT)$/);
expect(tagName).to.match(/^(INPUT|SELECT|TEXTAREA)$/);

cy.get(parent).within(() => {
if (tagName === 'INPUT') {
if (/^(INPUT|TEXTAREA)$/.test(tagName)) {
const inputField = cy.get(`[data-testing-id="${key}"]`);
inputField.clear();
if (value) {
Expand Down
25 changes: 15 additions & 10 deletions e2e/cypress/integration/pages/contact/contact.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { fillFormField } from '../../framework';
import { BreadcrumbModule } from '../breadcrumb.module';

declare interface ContactForm {
name: string;
email: string;
phone: string;
subject: string;
comment: string;
}

export class ContactPage {
readonly tag = 'ish-contact-page';
readonly breadcrumb = new BreadcrumbModule();
Expand All @@ -18,17 +27,13 @@ export class ContactPage {
return cy.get('input[data-testing-id="email"]');
}

get phoneInput() {
return cy.get('input[data-testing-id="phone"]');
}
fillForm(content: ContactForm) {
Object.keys(content)
.filter(key => content[key] !== undefined)
.forEach((key: keyof ContactForm) => {
fillFormField(this.tag, key, content[key]);
});

fillForm(name: string, email: string, phone: string, subject: string, comments: string) {
this.nameInput.clear().type(name).blur();
this.emailInput.clear().type(email).blur();
this.phoneInput.clear().type(phone).blur();
// tslint:disable-next-line:ban
cy.get('select[data-testing-id="subject"]').select(subject);
cy.get('textarea[data-testing-id="comment"]').clear().type(comments).blur();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ const _ = {
email: 'patricia@test.intershop.de',
password: '!InterShop00!',
fullName: 'Patricia Miller',
formContent: {
phone: '12345',
subject: 'Returns',
comment: "Don't fit.",
},
};

describe('Contact', () => {
it('anonymous user should send the contact successfully', () => {
ContactPage.navigateTo();
at(ContactPage, page => {
page.fillForm(_.fullName, _.email, '12345', 'Returns', "Don't fit.");
page.fillForm({ ..._.formContent, email: _.email, name: _.fullName });
page.submit();
});
at(ContactConfirmationPage, page => {
Expand Down

0 comments on commit 4c8a2d3

Please sign in to comment.