Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions projects/common/src/time/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ describe('Time', () => {
test('can get ISO String from time', () => {
expect(mockedTime.toISOString()).toBe('08:30:00.000Z');
});

test('can compare two times', () => {
expect(mockedTime.equals(new Time(8, 30))).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, trying to think if there's any way to test the UTC vs local comparison, given that the tests already run in UTC. I think there are some complicated ways, but it's not worth it... The complexity is due to limitations in our Time class, which would likely be easier to fix rather than figure out how to test.

(sorry, just rambling thoughts here, nothing to do)

expect(mockedTime.equals(new Time(9, 30))).toBeFalsy();
});
});
4 changes: 4 additions & 0 deletions projects/common/src/time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ export class Time {
public toISOString(): string {
return this.date.toISOString().substring(11);
}

public equals(other?: Time): boolean {
return this.toISOString() === other?.toISOString();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fakeAsync } from '@angular/core/testing';
import { NavigationService, Time } from '@hypertrace/common';
import { MemoizeModule, NavigationService, Time } from '@hypertrace/common';
import { createHostFactory, mockProvider, SpectatorHost } from '@ngneat/spectator/jest';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
Expand All @@ -14,7 +14,7 @@ describe('Time Picker Component', () => {
const createHost = createHostFactory({
component: TimePickerComponent,
shallow: true,
imports: [PopoverModule],
imports: [PopoverModule, MemoizeModule],
providers: [
mockProvider(PredefinedTimeService, {
getPredefinedTimes: jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { PredefinedTimeService } from '../time-range/predefined-time.service';
*ngFor="let predefinedTime of this.predefinedTimes"
(click)="this.onTimeChange(predefinedTime)"
[ngClass]="{
selected: predefinedTime.hours === this.time?.hours && predefinedTime.minutes === this.time?.minutes
selected: this.time && (this.areEqualTimes | htMemoize: this.time:predefinedTime)
}"
>
<span>{{ predefinedTime.label }}</span>
Expand Down Expand Up @@ -81,6 +81,8 @@ export class TimePickerComponent {
this.time = time;
this.timeChange.emit(time);
}

public areEqualTimes = (time: Time, predefinedTime: Time) => time.equals(predefinedTime);
}

export const enum TimePickerDisplayMode {
Expand Down
3 changes: 2 additions & 1 deletion projects/components/src/time-picker/time-picker.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MemoizeModule } from '@hypertrace/common';
import { IconModule } from '../icon/icon.module';
import { InputModule } from '../input/input.module';
import { LabelModule } from '../label/label.module';
import { PopoverModule } from '../popover/popover.module';
import { TimePickerComponent } from './time-picker.component';

@NgModule({
imports: [CommonModule, FormsModule, IconModule, LabelModule, InputModule, PopoverModule],
imports: [CommonModule, FormsModule, IconModule, LabelModule, MemoizeModule, InputModule, PopoverModule],
declarations: [TimePickerComponent],
exports: [TimePickerComponent]
})
Expand Down