Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Jan 22, 2024
1 parent 23d923c commit a3d7471
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type IPictogramResponse = {
keyword: string;
type: number;
plural: string;
hasLocution: boolean;
hasLocation: boolean;
}[];
created: Date;
lastUpdated: Date;
Expand Down
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();
});
});
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();
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatLegacyMenuModule as MatMenuModule } from '@angular/material/legacy-menu';
import { TranslateModule } from '@ngx-translate/core';
import { DialogService } from 'src/app/core/services/dialog/dialog.service';
import { MmpService } from 'src/app/core/services/mmp/mmp.service';

import { ToolbarComponent } from './toolbar.component';
import { MatMenuModule } from '@angular/material/menu';

describe('ToolbarComponent', () => {
let component: ToolbarComponent;
Expand Down

0 comments on commit a3d7471

Please sign in to comment.