Skip to content

Commit ad6fbab

Browse files
committed
test(Form Status): Add failing test for form status
1 parent 6a39e4a commit ad6fbab

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

cypress/helpers/data.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ export const hardcodedElementToTestElement = (item: OneListing): ListElement =>
140140
export const hardcodedElementsToTestList = (items: OneListing[]): ListElement[] =>
141141
items.map(item => hardcodedElementToTestElement(item));
142142

143-
export const extractErrors = (errors: JQuery<HTMLElement>) => cy.wrap(JSON.parse(errors.text().trim()));
143+
export const extractPre = (preTag: JQuery<HTMLElement>) => cy.wrap(JSON.parse(preTag.text().trim()));

cypress/helpers/dom.helper.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { DroidType } from '../../src/app/interfaces/droid.interface';
44
import { ListingType } from '../../src/app/interfaces/listing.interface';
55
import { VehicleType } from '../../src/app/interfaces/vehicle.interface';
6-
import { extractErrors, FormElement, ListElement } from './data.helper';
6+
import { extractPre, FormElement, ListElement } from './data.helper';
77

88
const getTextFromTag = (element: HTMLElement, tag: string): string =>
99
Cypress.$(element)
@@ -90,7 +90,17 @@ export const DOM = {
9090
return cy.get(`*[data-errors]`);
9191
},
9292
get obj() {
93-
return DOM.form.errors.cy.then(extractErrors);
93+
return DOM.form.errors.cy.then(extractPre);
94+
},
95+
};
96+
},
97+
get status() {
98+
return {
99+
get cy() {
100+
return cy.get(`*[data-status]`);
101+
},
102+
get obj() {
103+
return DOM.form.status.cy.then(extractPre);
94104
},
95105
};
96106
},

src/app/app.spec.e2e.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ context(`EJawa demo`, () => {
257257
DOM.form.noErrors.should('exist');
258258
});
259259

260+
it(`should be pristine and untouched on init when form is valid`, () => {
261+
DOM.list.elements.cy.eq(0).click();
262+
263+
DOM.form.errors.obj.should('eql', {
264+
dirty: false,
265+
pristine: true,
266+
touched: false,
267+
});
268+
});
269+
260270
it(`should recursively disable the form when disabling the top formGroup`, () => {
261271
DOM.list.elements.cy.eq(0).click();
262272

src/app/main/listing/listing-form/listing-form.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,13 @@
166166
<pre>{{ formGroupValues | json }}</pre>
167167
</mat-card-content>
168168
</mat-card>
169+
170+
<mat-card class="status">
171+
<mat-card-title>Form status</mat-card-title>
172+
173+
<mat-card-content>
174+
<pre data-status>{{
175+
{ dirty: formGroup.dirty, pristine: formGroup.pristine, touched: formGroup.touched } | json
176+
}}</pre>
177+
</mat-card-content>
178+
</mat-card>

0 commit comments

Comments
 (0)