Skip to content

Commit

Permalink
test(Form Status): Add failing test for form status
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-cloudnc committed Mar 3, 2020
1 parent 6a39e4a commit f8b40d9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cypress/helpers/data.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ export const hardcodedElementToTestElement = (item: OneListing): ListElement =>
export const hardcodedElementsToTestList = (items: OneListing[]): ListElement[] =>
items.map(item => hardcodedElementToTestElement(item));

export const extractErrors = (errors: JQuery<HTMLElement>) => cy.wrap(JSON.parse(errors.text().trim()));
export const extractPre = (preTag: JQuery<HTMLElement>) => cy.wrap(JSON.parse(preTag.text().trim()));
14 changes: 12 additions & 2 deletions cypress/helpers/dom.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { DroidType } from '../../src/app/interfaces/droid.interface';
import { ListingType } from '../../src/app/interfaces/listing.interface';
import { VehicleType } from '../../src/app/interfaces/vehicle.interface';
import { extractErrors, FormElement, ListElement } from './data.helper';
import { extractPre, FormElement, ListElement } from './data.helper';

const getTextFromTag = (element: HTMLElement, tag: string): string =>
Cypress.$(element)
Expand Down Expand Up @@ -90,7 +90,17 @@ export const DOM = {
return cy.get(`*[data-errors]`);
},
get obj() {
return DOM.form.errors.cy.then(extractErrors);
return DOM.form.errors.cy.then(extractPre);
},
};
},
get status() {
return {
get cy() {
return cy.get(`*[data-status]`);
},
get obj() {
return DOM.form.status.cy.then(extractPre);
},
};
},
Expand Down
10 changes: 10 additions & 0 deletions src/app/app.spec.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ context(`EJawa demo`, () => {
DOM.form.noErrors.should('exist');
});

it(`should be pristine and untouched on init when form is valid`, () => {
DOM.list.elements.cy.eq(0).click();

DOM.form.status.obj.should('eql', {
dirty: false,
pristine: true,
touched: false,
});
});

it(`should recursively disable the form when disabling the top formGroup`, () => {
DOM.list.elements.cy.eq(0).click();

Expand Down
10 changes: 10 additions & 0 deletions src/app/main/listing/listing-form/listing-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@
<pre>{{ formGroupValues | json }}</pre>
</mat-card-content>
</mat-card>

<mat-card class="status">
<mat-card-title>Form status</mat-card-title>

<mat-card-content>
<pre data-status>{{
{ dirty: formGroup.dirty, pristine: formGroup.pristine, touched: formGroup.touched } | json
}}</pre>
</mat-card-content>
</mat-card>

0 comments on commit f8b40d9

Please sign in to comment.