Skip to content

Commit

Permalink
Add tests for duration service (#2831)
Browse files Browse the repository at this point in the history
* Delete unused service

* Add tests for duration service
  • Loading branch information
luisa-beerboom authored Sep 26, 2023
1 parent 7a71c20 commit 21e5f12
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ import { RouterModule } from '@angular/router';
import { CommitteeCommonServiceModule } from '../../services/committee-common-service.module';
import { CommitteeDetailRoutingModule } from './committee-detail-routing.module';
import { CommitteeDetailComponent } from './components/committee-detail/committee-detail.component';
import { CommitteeDetailServiceModule } from './services';

@NgModule({
declarations: [CommitteeDetailComponent],
imports: [
CommonModule,
CommitteeDetailRoutingModule,
CommitteeDetailServiceModule,
CommitteeCommonServiceModule,
RouterModule
]
imports: [CommonModule, CommitteeDetailRoutingModule, CommitteeCommonServiceModule, RouterModule]
})
export class CommitteeDetailModule {}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 29 additions & 4 deletions client/src/app/site/services/duration.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@ import { TestBed } from '@angular/core/testing';

import { DurationService } from './duration.service';

xdescribe(`DurationService`, () => {
describe(`DurationService`, () => {
let service: DurationService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({ providers: [DurationService] });
service = TestBed.inject(DurationService);
});

it(`should be created`, () => {
expect(service).toBeTruthy();
it(`test stringToDuration`, () => {
expect(service.stringToDuration(`1:23h`, `h`)).toBe(83);
expect(service.stringToDuration(`1:23m`, `m`)).toBe(83);
expect(service.stringToDuration(`123m`, `m`)).toBe(123);
expect(service.stringToDuration(`1:23`, `h`)).toBe(83);
expect(service.stringToDuration(`1:23`, `m`)).toBe(83);
expect(service.stringToDuration(`123`, `m`)).toBe(123);
expect(service.stringToDuration()).toBe(0);
expect(service.stringToDuration(`1:23 h`, `h`)).toBe(83);
});

it(`test durationToStringWithHours`, () => {
expect(service.durationToStringWithHours(83)).toBe(`0:01:23 h`);
expect(service.durationToStringWithHours(7345)).toBe(`2:02:25 h`);
expect(service.durationToStringWithHours(-1)).toBe(`-0:00:01 h`);
expect(service.durationToStringWithHours(undefined)).toBe(``);
});

it(`test durationToString`, () => {
expect(service.durationToString(83, `h`)).toBe(`1:23 h`);
expect(service.durationToString(7345, `h`)).toBe(`122:25 h`);
expect(service.durationToString(-1, `h`)).toBe(`-0:01 h`);
expect(service.durationToString(undefined, `h`)).toBe(``);
expect(service.durationToString(83, `m`)).toBe(`1:23 m`);
expect(service.durationToString(7345, `m`)).toBe(`122:25 m`);
expect(service.durationToString(-1, `m`)).toBe(`-0:01 m`);
expect(service.durationToString(undefined, `m`)).toBe(``);
});
});
7 changes: 6 additions & 1 deletion client/src/app/site/services/duration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ export class DurationService {
* @returns A readable time-string.
*/
public durationToStringWithHours(duration: number): string {
let prefix = ``;
if (duration < 0) {
prefix = `-`;
duration *= -1;
}
const hours = Math.floor(duration / 3600);
const minutes = `0${Math.floor((duration % 3600) / 60)}`.slice(-2);
const seconds = `0${Math.floor(duration % 60)}`.slice(-2);
if (!isNaN(+minutes) && !isNaN(+seconds)) {
return `${hours}:${minutes}:${seconds} h`;
return `${prefix}${hours}:${minutes}:${seconds} h`;
} else {
return ``;
}
Expand Down

0 comments on commit 21e5f12

Please sign in to comment.