-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add review creation dialog, display the current user's review s…
…eparately
- Loading branch information
Showing
31 changed files
with
1,180 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
e2e/cypress/integration/pages/shopping/product-review.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { fillFormField, waitLoadingEnd } from '../../framework'; | ||
|
||
declare interface ProductReviewForm { | ||
rating: number; | ||
title: string; | ||
content: string; | ||
} | ||
|
||
export class ProductReviewModule { | ||
// product rating&reviews | ||
get productReviewList() { | ||
return cy.get('[data-testing-id=product-review-list]'); | ||
} | ||
|
||
get reviewLoginLink() { | ||
return cy.get('ish-product-reviews').find('[data-testing-id=login-link]'); | ||
} | ||
|
||
get reviewOpenDialogLink() { | ||
return cy.get('ish-product-reviews').find('[data-testing-id=open-review-dialog]'); | ||
} | ||
|
||
get reviewCreationForm() { | ||
return cy.get('#createProductReviewForm'); | ||
} | ||
|
||
get ownProductReview() { | ||
return cy.get('[data-testing-id=own-product-review'); | ||
} | ||
|
||
get deleteReviewLink() { | ||
return cy.get('[data-testing-id=delete-review]'); | ||
} | ||
|
||
gotoLoginBeforeOpenReviewDialog() { | ||
this.reviewLoginLink.click(); | ||
} | ||
|
||
fillReviewForm(data: ProductReviewForm) { | ||
this.reviewCreationForm.find(`[data-testing-id=rating-stars-field] :nth-child(${data.rating})`).click(); | ||
|
||
Object.keys(data) | ||
.filter(key => data[key] !== undefined && key !== 'rating') | ||
.forEach((key: keyof ProductReviewForm) => { | ||
fillFormField('#createProductReviewForm', key, data[key]); | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
submitReviewCreationForm() { | ||
cy.get('button[form=createProductReviewForm]').click(); | ||
} | ||
|
||
deleteOwnReview() { | ||
this.deleteReviewLink.click(); | ||
cy.get('[data-testing-id="confirm"]', { timeout: 1000 }).click(); | ||
waitLoadingEnd(1000); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
e2e/cypress/integration/specs/shopping/product-reviews.b2b.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { at } from '../../framework'; | ||
import { createB2BUserViaREST } from '../../framework/b2b-user'; | ||
import { LoginPage } from '../../pages/account/login.page'; | ||
import { sensibleDefaults } from '../../pages/account/registration.page'; | ||
import { ProductDetailPage } from '../../pages/shopping/product-detail.page'; | ||
|
||
const _ = { | ||
user: { | ||
login: `test${new Date().getTime()}@testcity.de`, | ||
...sensibleDefaults, | ||
}, | ||
product: { | ||
sku: '6997041', | ||
}, | ||
}; | ||
|
||
describe('Product Reviews', () => { | ||
before(() => { | ||
createB2BUserViaREST(_.user); | ||
ProductDetailPage.navigateTo(_.product.sku); | ||
}); | ||
|
||
it('anonymous user should see a product review on product review tab', () => { | ||
at(ProductDetailPage, page => { | ||
page.infoNav('Reviews').should('be.visible'); | ||
page.infoNav('Reviews').click(); | ||
page.reviewTab.productReviewList.should('be.visible'); | ||
page.reviewTab.deleteReviewLink.should('not.exist'); | ||
}); | ||
}); | ||
|
||
it('user should log in before he can write a review', () => { | ||
at(ProductDetailPage, page => { | ||
page.reviewTab.reviewOpenDialogLink.should('not.exist'); | ||
page.reviewTab.ownProductReview.should('not.exist'); | ||
page.reviewTab.gotoLoginBeforeOpenReviewDialog(); | ||
}); | ||
at(LoginPage, page => { | ||
page.fillForm(_.user.login, _.user.password); | ||
page.submit().its('response.statusCode').should('equal', 200); | ||
}); | ||
at(ProductDetailPage, page => { | ||
page.reviewTab.reviewOpenDialogLink.should('be.visible'); | ||
}); | ||
}); | ||
|
||
it('user should be able to write a review', () => { | ||
at(ProductDetailPage, page => { | ||
page.reviewTab.reviewOpenDialogLink.click(); | ||
page.reviewTab.reviewCreationForm.should('be.visible'); | ||
|
||
page.reviewTab.fillReviewForm({ rating: 2, title: 'Disappointment', content: 'Bad quality' }); | ||
page.reviewTab.submitReviewCreationForm(); | ||
|
||
page.infoText.should('contain', 'needs to be reviewed'); | ||
page.reviewTab.ownProductReview.should('exist'); | ||
page.reviewTab.ownProductReview.should('contain', 'Disappointment'); | ||
}); | ||
}); | ||
|
||
it('user should be able to delete his/her review', () => { | ||
at(ProductDetailPage, page => { | ||
page.reviewTab.deleteReviewLink.should('be.visible'); | ||
page.reviewTab.deleteOwnReview(); | ||
|
||
page.reviewTab.deleteReviewLink.should('not.exist'); | ||
page.reviewTab.reviewOpenDialogLink.should('be.visible'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/app/extensions/rating/formly/rating-stars-field/rating-stars-field.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="pt-1" data-testing-id="rating-stars-field"> | ||
<ng-container *ngFor="let fill of stars; index as i"> | ||
<a [title]="'product.review.rating.tooltip' | translate: { '0': i + 1 }" class="text-muted mt-4" | ||
><ish-product-rating-star [filled]="fill" (click)="setStars(i + 1)"></ish-product-rating-star | ||
></a> | ||
</ng-container> | ||
</div> |
72 changes: 72 additions & 0 deletions
72
src/app/extensions/rating/formly/rating-stars-field/rating-stars-field.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { FormGroup } from '@angular/forms'; | ||
import { FormlyFieldConfig, FormlyModule } from '@ngx-formly/core'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
|
||
import { FormlyTestingComponentsModule } from 'ish-shared/formly/dev/testing/formly-testing-components.module'; | ||
import { FormlyTestingContainerComponent } from 'ish-shared/formly/dev/testing/formly-testing-container/formly-testing-container.component'; | ||
|
||
import { ProductRatingStarComponent } from '../../shared/product-rating-star/product-rating-star.component'; | ||
|
||
import { RatingStarsFieldComponent } from './rating-stars-field.component'; | ||
|
||
describe('Rating Stars Field Component', () => { | ||
let component: FormlyTestingContainerComponent; | ||
let fixture: ComponentFixture<FormlyTestingContainerComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
FormlyModule.forRoot({ | ||
types: [ | ||
{ | ||
name: 'ish-rating-stars-field', | ||
component: RatingStarsFieldComponent, | ||
}, | ||
], | ||
}), | ||
FormlyTestingComponentsModule, | ||
TranslateModule.forRoot(), | ||
], | ||
declarations: [MockComponent(ProductRatingStarComponent), RatingStarsFieldComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
const testComponentInputs = { | ||
fields: [ | ||
{ | ||
key: 'input', | ||
type: 'ish-rating-stars-field', | ||
templateOptions: { | ||
label: 'test label', | ||
required: true, | ||
}, | ||
} as FormlyFieldConfig, | ||
], | ||
form: new FormGroup({}), | ||
model: { | ||
input: '', | ||
}, | ||
}; | ||
|
||
fixture = TestBed.createComponent(FormlyTestingContainerComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
|
||
component.testComponentInputs = testComponentInputs; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should be rendered after creation', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelectorAll('a')).toHaveLength(5); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/app/extensions/rating/formly/rating-stars-field/rating-stars-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; | ||
import { range } from 'lodash-es'; | ||
|
||
import { RatingFilledType } from '../../shared/product-rating-star/product-rating-star.component'; | ||
|
||
/** | ||
* Type that will render 5 stars to rate a product. | ||
*/ | ||
@Component({ | ||
selector: 'ish-rating-stars-field', | ||
templateUrl: './rating-stars-field.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RatingStarsFieldComponent extends FieldType<FieldTypeConfig> { | ||
get stars(): RatingFilledType[] { | ||
return range(1, 6).map(index => (index <= this.field?.formControl.value ? 'full' : 'empty')); | ||
} | ||
|
||
setStars(stars: number) { | ||
this.field.formControl.setValue(stars); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.