Skip to content

Commit

Permalink
feat(fonts): host fonts locally (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
cayacdev authored Apr 16, 2023
1 parent 983e3ee commit b6d173c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 18 deletions.
12 changes: 12 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"@ngrx/store": "^15.4.0",
"@ngrx/store-devtools": "^15.4.0",
"chart.js": "^2.9.4",
"material-icons": "^1.13.4",
"ng2-charts": "^2.4.3",
"roboto-fontface": "^0.10.0",
"rxjs": "^6.6.7",
"tslib": "^2.3.1",
"zone.js": "~0.11.4"
Expand Down
62 changes: 62 additions & 0 deletions frontend/src/app/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { fakeAsync, TestBed, tick } from '@angular/core/testing'
import { AuthService } from './auth.service'
import { MockStore, provideMockStore } from '@ngrx/store/testing'
import * as AuthActions from './store/auth.actions'

describe('AuthService', () => {
let systemUnderTest: AuthService
let store: MockStore

beforeEach(() => {
TestBed.configureTestingModule({
providers: [AuthService, provideMockStore({ initialState: {} })],
})

systemUnderTest = TestBed.inject(AuthService)
store = TestBed.inject(MockStore)
})

it('should be created', () => {
expect(systemUnderTest).toBeTruthy()
})

describe('setLogoutTimer', () => {
it('should dispatch Logout action after the expiration duration', fakeAsync(() => {
const expirationDuration = 5000
spyOn(store, 'dispatch').and.callThrough()

systemUnderTest.setLogoutTimer(expirationDuration)

expect(systemUnderTest['tokenExpirationTimer']).toBeDefined()
expect(store.dispatch).not.toHaveBeenCalledWith(new AuthActions.Logout())

tick(5000)

expect(store.dispatch).toHaveBeenCalledWith(new AuthActions.Logout())
}))
})

describe('clearLogoutTimer', () => {
it('should clear the timer', fakeAsync(() => {
const expirationDuration = 5000
spyOn(window, 'clearTimeout').and.callThrough()

systemUnderTest.setLogoutTimer(expirationDuration)

systemUnderTest.clearLogoutTimer()

expect(window.clearTimeout).toHaveBeenCalled()
expect(systemUnderTest['tokenExpirationTimer']).toBeNull()
}))

it('should not clear the timer if it has already expired', fakeAsync(() => {
const expirationDuration = 0
spyOn(window, 'clearTimeout').and.callThrough()

systemUnderTest.clearLogoutTimer()

expect(window.clearTimeout).not.toHaveBeenCalled()
expect(systemUnderTest['tokenExpirationTimer']).toBeUndefined()
}))
})
})
18 changes: 9 additions & 9 deletions frontend/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Injectable } from '@angular/core'
import { Store } from '@ngrx/store'

import * as fromApp from '../store/app.reducer';
import * as AuthActions from './store/auth.actions';
import * as fromApp from '../store/app.reducer'
import * as AuthActions from './store/auth.actions'

@Injectable({ providedIn: 'root' })
export class AuthService {
private tokenExpirationTimer: number;
private tokenExpirationTimer

constructor(private store: Store<fromApp.AppState>) {}

setLogoutTimer(expirationDuration: number): void {
this.tokenExpirationTimer = setTimeout(() => {
this.store.dispatch(new AuthActions.Logout());
}, expirationDuration);
this.store.dispatch(new AuthActions.Logout())
}, expirationDuration)
}

clearLogoutTimer(): void {
if (this.tokenExpirationTimer) {
clearTimeout(this.tokenExpirationTimer);
this.tokenExpirationTimer = null;
clearTimeout(this.tokenExpirationTimer)
this.tokenExpirationTimer = null
}
}
}
16 changes: 7 additions & 9 deletions frontend/src/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<!doctype html>
<html lang="en">
<html lang='en'>
<head>
<meta charset="utf-8">
<meta charset='utf-8'>
<title>CashboxFrontend</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="manifest" href="manifest.webmanifest">
<meta name="theme-color" content="#fafafa">
<base href='/'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='icon' type='image/x-icon' href='favicon.ico'>
<link rel='manifest' href='manifest.webmanifest'>
<meta name='theme-color' content='#fafafa'>
</head>
<body>
<app-root></app-root>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* You can add global styles to this file, and also import other style files */

$roboto-font-path: "~roboto-fontface/fonts" !default;
@import "roboto-fontface/css/roboto/sass/roboto-fontface";

$material-icons-font-path: '~material-icons/iconfont/';
@import 'material-icons/iconfont/material-icons.scss';

html, body {
height: 100%;
}
Expand Down

0 comments on commit b6d173c

Please sign in to comment.