-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
26 changed files
with
372 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,9 @@ | |
justify-content: center; | ||
height: 90vh; | ||
} | ||
|
||
.lastBackup { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
} |
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
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
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
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
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,36 @@ | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { BackupService } from './backup.service'; | ||
|
||
function setup() { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule] | ||
}); | ||
const service = TestBed.inject(BackupService); | ||
const httpTestingController = TestBed.inject(HttpTestingController) | ||
return {service, httpTestingController} | ||
} | ||
|
||
describe('BackupService', () => { | ||
describe('getLastBackupTime', () => { | ||
it('should return last backup time', () => { | ||
const mockTime = new Date(); | ||
const { service, httpTestingController } = setup(); | ||
service.getLastBackupTime().subscribe(lastBackup => { | ||
expect(lastBackup).toEqual({ time: mockTime }); | ||
}) | ||
httpTestingController.expectOne('/db/last-backup-time').flush(mockTime.toISOString()) | ||
httpTestingController.verify(); | ||
}); | ||
|
||
it('should return error message if last backup was more that 1 day ago', () => { | ||
const mockTime = new Date(Date.now() - 25 * 60 * 60 * 1000 ); | ||
const { service, httpTestingController } = setup(); | ||
service.getLastBackupTime().subscribe(lastBackup => { | ||
expect(lastBackup).toEqual({ time: mockTime, errorMessage: 'No backup since 1 day' }); | ||
}) | ||
httpTestingController.expectOne('/db/last-backup-time').flush(mockTime.toISOString()) | ||
httpTestingController.verify(); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, map } from 'rxjs'; | ||
|
||
export type LastBackup = { | ||
time: Date; | ||
errorMessage?: string; | ||
}; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class BackupService { | ||
constructor(private http: HttpClient) {} | ||
|
||
getLastBackupTime(): Observable<LastBackup> { | ||
return this.http.get<Date>('/db/last-backup-time').pipe( | ||
map((date) => ({ | ||
time: new Date(date), | ||
...(new Date(date).getTime() + 24 * 60 * 60 * 1000 < Date.now() && { errorMessage: 'No backup since 1 day' }) | ||
})) | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Attribute, Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-header', | ||
templateUrl: './header.component.html', | ||
styleUrls: ['./header.component.css'], | ||
}) | ||
export class HeaderComponent { | ||
@Input() title = ''; | ||
constructor(@Attribute('title') public title = '') {} | ||
} |
15 changes: 10 additions & 5 deletions
15
client/src/app/common-components/heading/heading.component.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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { Component, HostBinding, Input } from '@angular/core'; | ||
import { Attribute, Component, HostBinding, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-heading', | ||
templateUrl: './heading.component.html', | ||
styleUrls: ['./heading.component.css'], | ||
host: { | ||
'[class]': "'level' + level", | ||
}, | ||
}) | ||
export class HeadingComponent { | ||
@Input() level = 1; | ||
constructor( | ||
@Attribute('level') public level: string, | ||
@Attribute('class') public className: string | ||
) {} | ||
|
||
@HostBinding('class') | ||
get class(): string { | ||
return [`level${this.level ?? 1}`, this.className].join(' '); | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import { RelativeTimePipe } from './relative-time.pipe'; | ||
|
||
describe('RelativeTimePipe', () => { | ||
[ | ||
{ date: new Date(), result: 'now' }, | ||
{ date: new Date(Date.now() - 999), result: '1 second ago' }, | ||
{ date: new Date(Date.now() - 1000), result: '1 second ago' }, | ||
{ date: new Date(Date.now() - 59 * 1000), result: '59 seconds ago' }, | ||
{ date: new Date(Date.now() - 60 * 1000), result: '1 minute ago' }, | ||
{ date: new Date(Date.now() - 59 * 60 * 1000), result: '59 minutes ago' }, | ||
{ date: new Date(Date.now() - 60 * 60 * 1000), result: '1 hour ago' }, | ||
{ date: new Date(Date.now() - 23 * 60 * 60 * 1000), result: '23 hours ago' }, | ||
{ date: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), result: 'yesterday' }, | ||
{ date: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), result: '2 days ago' }, | ||
{ date: new Date(Date.now() - 6 * 24 * 60 * 60 * 1000), result: '6 days ago' }, | ||
{ date: new Date(Date.now() - 1 * 7 * 24 * 60 * 60 * 1000), result: 'last week' }, | ||
{ date: new Date(Date.now() - 4 * 7 * 24 * 60 * 60 * 1000), result: '4 weeks ago' }, | ||
{ date: new Date(Date.now() - 29 * 24 * 60 * 60 * 1000), result: '4 weeks ago' }, | ||
{ date: new Date(Date.now() - 1 * 30 * 24 * 60 * 60 * 1000), result: 'last month' }, | ||
{ date: new Date(Date.now() - 12 * 30 * 24 * 60 * 60 * 1000), result: '12 months ago' }, | ||
{ date: new Date(Date.now() - 364 * 24 * 60 * 60 * 1000), result: '12 months ago' }, | ||
{ date: new Date(Date.now() - 1 * 365 * 24 * 60 * 60 * 1000), result: 'last year' }, | ||
{ date: new Date(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000), result: '5 years ago' }, | ||
].forEach(({ date, result }) => | ||
it(`formats ${date} as ${result}`, () => { | ||
const pipe = new RelativeTimePipe(); | ||
expect(pipe.transform(date)).toBe(result); | ||
}) | ||
); | ||
}); |
Oops, something went wrong.