mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
replace jasmine ajax with spy in rating tests
This commit is contained in:
@@ -19,14 +19,15 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { RatingComponent } from './rating.component';
|
import { RatingComponent } from './rating.component';
|
||||||
import { setupTestBed } from '../../core/testing';
|
import { setupTestBed } from '../../core/testing';
|
||||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
declare let jasmine: any;
|
import { RatingService } from './services/rating.service';
|
||||||
|
|
||||||
describe('Rating component', () => {
|
describe('Rating component', () => {
|
||||||
|
|
||||||
let component: any;
|
let component: any;
|
||||||
let fixture: ComponentFixture<RatingComponent>;
|
let fixture: ComponentFixture<RatingComponent>;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
|
let service: RatingService;
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [ContentTestingModule]
|
imports: [ContentTestingModule]
|
||||||
@@ -34,6 +35,7 @@ describe('Rating component', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(RatingComponent);
|
fixture = TestBed.createComponent(RatingComponent);
|
||||||
|
service = TestBed.get(RatingService);
|
||||||
|
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
@@ -48,26 +50,8 @@ describe('Rating component', () => {
|
|||||||
|
|
||||||
describe('Rendering tests', () => {
|
describe('Rendering tests', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jasmine.Ajax.install();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jasmine.Ajax.uninstall();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should rating component should be present', (done) => {
|
it('should rating component should be present', (done) => {
|
||||||
fixture.detectChanges();
|
spyOn(service, 'getRating').and.returnValue(Observable.of({
|
||||||
|
|
||||||
component.ngOnChanges().subscribe(() => {
|
|
||||||
expect(element.querySelector('#adf-rating-container')).not.toBe(null);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: {
|
|
||||||
entry: {
|
entry: {
|
||||||
id: 'fiveStar',
|
id: 'fiveStar',
|
||||||
aggregate: {
|
aggregate: {
|
||||||
@@ -75,11 +59,27 @@ describe('Rating component', () => {
|
|||||||
average: 4
|
average: 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.ngOnChanges().subscribe(() => {
|
||||||
|
expect(element.querySelector('#adf-rating-container')).not.toBe(null);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should the star rating filled with the right grey/colored star', (done) => {
|
it('should the star rating filled with the right grey/colored star', (done) => {
|
||||||
|
spyOn(service, 'getRating').and.returnValue(Observable.of({
|
||||||
|
entry: {
|
||||||
|
id: 'fiveStar',
|
||||||
|
aggregate: {
|
||||||
|
numberOfRatings: 4,
|
||||||
|
average: 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.ngOnChanges().subscribe(() => {
|
component.ngOnChanges().subscribe(() => {
|
||||||
@@ -89,23 +89,27 @@ describe('Rating component', () => {
|
|||||||
expect(element.querySelectorAll('.adf-grey-star').length).toBe(2);
|
expect(element.querySelectorAll('.adf-grey-star').length).toBe(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: {
|
|
||||||
entry: {
|
|
||||||
id: 'fiveStar',
|
|
||||||
aggregate: {
|
|
||||||
numberOfRatings: 4,
|
|
||||||
average: 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should click on a star change your vote', (done) => {
|
it('should click on a star change your vote', (done) => {
|
||||||
|
spyOn(service, 'getRating').and.returnValue(Observable.of({
|
||||||
|
'entry': {
|
||||||
|
myRating: 1,
|
||||||
|
'ratedAt': '2017-04-06T14:34:28.061+0000',
|
||||||
|
'id': 'fiveStar',
|
||||||
|
'aggregate': { 'numberOfRatings': 1, 'average': 1.0 }
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
spyOn(service, 'postRating').and.returnValue(Observable.of({
|
||||||
|
'entry': {
|
||||||
|
'myRating': 3,
|
||||||
|
'ratedAt': '2017-04-06T14:36:40.731+0000',
|
||||||
|
'id': 'fiveStar',
|
||||||
|
'aggregate': { 'numberOfRatings': 1, 'average': 3.0 }
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.ngOnChanges().subscribe(() => {
|
component.ngOnChanges().subscribe(() => {
|
||||||
@@ -123,33 +127,8 @@ describe('Rating component', () => {
|
|||||||
|
|
||||||
let starThree: any = element.querySelector('#adf-colored-star-3');
|
let starThree: any = element.querySelector('#adf-colored-star-3');
|
||||||
starThree.click();
|
starThree.click();
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: {
|
|
||||||
'entry': {
|
|
||||||
'myRating': 3,
|
|
||||||
'ratedAt': '2017-04-06T14:36:40.731+0000',
|
|
||||||
'id': 'fiveStar',
|
|
||||||
'aggregate': {'numberOfRatings': 1, 'average': 3.0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: {
|
|
||||||
'entry': {
|
|
||||||
myRating: 1,
|
|
||||||
'ratedAt': '2017-04-06T14:34:28.061+0000',
|
|
||||||
'id': 'fiveStar',
|
|
||||||
'aggregate': {'numberOfRatings': 1, 'average': 1.0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user