-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23d923c
commit a3d7471
Showing
4 changed files
with
123 additions
and
2 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
73 changes: 73 additions & 0 deletions
73
teammapper-frontend/src/app/core/services/pictograms/pictogram.service.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,73 @@ | ||
import { PictogramService } from './pictogram.service'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { | ||
HttpClientTestingModule, | ||
HttpTestingController, | ||
} from '@angular/common/http/testing'; | ||
import { IPictogramResponse } from './picto-types'; | ||
|
||
const testData: IPictogramResponse = { | ||
schematic: false, | ||
sex: false, | ||
violence: false, | ||
aac: false, | ||
aacColor: false, | ||
skin: false, | ||
hair: false, | ||
downloads: 0, | ||
categories: [], | ||
synsets: [], | ||
tags: [], | ||
_id: 1, | ||
created: new Date(), | ||
lastUpdated: new Date(), | ||
keywords: [], | ||
}; | ||
|
||
describe('PictogramService', () => { | ||
let httpClient: HttpClient; | ||
let httpTestingController: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
}); | ||
|
||
// Inject the http service and test controller for each test | ||
httpClient = TestBed.inject(HttpClient); | ||
httpTestingController = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('fetches pictos', () => { | ||
new PictogramService(httpClient).getPictos('House').subscribe(data => { | ||
expect(data).toEqual([testData]); | ||
}); | ||
const httpRequest = httpTestingController.expectOne( | ||
'https://api.arasaac.org/v1/pictograms/de/bestsearch/House' | ||
); | ||
expect(httpRequest.request.method).toBe('GET'); | ||
httpRequest.flush([testData]); | ||
httpTestingController.verify(); | ||
}); | ||
|
||
it('constructs the asset url', () => { | ||
const imageUrl = new PictogramService(httpClient).getPictoImageUrl(3); | ||
expect(imageUrl).toEqual( | ||
'https://static.arasaac.org/pictograms/3/3_300.png' | ||
); | ||
}); | ||
|
||
it('gets the image', () => { | ||
const blob: Blob = new Blob(); | ||
new PictogramService(httpClient).getPictoImage(3).subscribe(data => { | ||
expect(data).toEqual(blob); | ||
}); | ||
const httpRequest = httpTestingController.expectOne( | ||
'https://static.arasaac.org/pictograms/3/3_300.png' | ||
); | ||
expect(httpRequest.request.method).toBe('GET'); | ||
httpRequest.flush(blob); | ||
httpTestingController.verify(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
.../app/modules/application/components/dialog-pictograms/dialog-pictograms.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,48 @@ | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
import { MatMenuModule } from '@angular/material/menu'; | ||
import { DialogPictogramsComponent } from './dialog-pictograms.component'; | ||
import { MmpService } from 'src/app/core/services/mmp/mmp.service'; | ||
import { UtilsService } from 'src/app/core/services/utils/utils.service'; | ||
import { PictogramService } from 'src/app/core/services/pictograms/pictogram.service'; | ||
|
||
describe('DialogPictogramsComponent', () => { | ||
let component: DialogPictogramsComponent; | ||
let fixture: ComponentFixture<DialogPictogramsComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
const mockMmpService: jasmine.SpyObj<MmpService> = jasmine.createSpyObj( | ||
MmpService, | ||
['new'] | ||
); | ||
const mockUtilsService: jasmine.SpyObj<UtilsService> = jasmine.createSpyObj( | ||
UtilsService, | ||
['new'] | ||
); | ||
const mockPictoService: jasmine.SpyObj<PictogramService> = | ||
jasmine.createSpyObj(PictogramService, ['new']); | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [DialogPictogramsComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
providers: [ | ||
{ provide: MmpService, useValue: mockMmpService }, | ||
{ provide: UtilsService, useValue: mockUtilsService }, | ||
{ provide: PictogramService, useValue: mockPictoService }, | ||
], | ||
imports: [TranslateModule.forRoot(), MatMenuModule], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DialogPictogramsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
teammapper-frontend/src/app/modules/application/components/toolbar/toolbar.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