Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/solution #2

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6eddb71
Update package-lock.json
IfreannMedia Mar 28, 2022
686d4c0
added api domain url
IfreannMedia Mar 28, 2022
c8b7fd7
renamed url
IfreannMedia Mar 28, 2022
97a7bee
created usersTableComponent
IfreannMedia Mar 28, 2022
63c7fc7
created routing service
IfreannMedia Mar 28, 2022
5a9c7e5
added create user component, updated routing
IfreannMedia Mar 28, 2022
95c99a8
updated routing
IfreannMedia Mar 28, 2022
cdfef36
deleted unused component
IfreannMedia Mar 28, 2022
7720fa0
added users service
IfreannMedia Mar 28, 2022
0716e53
added in ngx datatable
IfreannMedia Mar 29, 2022
567e886
replaced ngx table with mat table
IfreannMedia Mar 29, 2022
d352cb2
striped and resized rows
IfreannMedia Mar 29, 2022
671ac21
blocked out and styled create user component
IfreannMedia Mar 31, 2022
698a48f
added validation to fields
IfreannMedia Apr 1, 2022
b503f08
updated disabled logic for create button
IfreannMedia Apr 1, 2022
ea54ede
added in test for existing user
IfreannMedia Apr 1, 2022
72ebcf7
post user works, checking if user exists works
IfreannMedia Apr 1, 2022
b8b29a2
made table responsive
IfreannMedia Apr 1, 2022
f800fb2
created loading service with http interceptor
IfreannMedia Apr 1, 2022
f27b549
only show progress bar on laod
IfreannMedia Apr 1, 2022
b2c4165
Fixed expressionChanged error for loading
IfreannMedia Apr 1, 2022
739dbde
finished styling paginator
IfreannMedia Apr 1, 2022
d5b7a26
refactor and added snackbars
IfreannMedia Apr 2, 2022
b39eee4
Updated to run test files
IfreannMedia Apr 2, 2022
1e05512
added unit tests
IfreannMedia Apr 2, 2022
a9d3296
added matSnackBar test
IfreannMedia Apr 2, 2022
f629870
added more tests
IfreannMedia Apr 2, 2022
0d5ea2a
Update users-table.component.spec.ts
IfreannMedia Apr 2, 2022
f5d988f
updated with more tests
IfreannMedia Apr 2, 2022
2f635be
made progress bar absolute
IfreannMedia Apr 2, 2022
9f7227a
removed debugger
IfreannMedia Apr 2, 2022
0c75327
convert settimout to fakeAsync
IfreannMedia Apr 2, 2022
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
8 changes: 6 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ module.exports = function (config) {
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
random: false
}
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/fe-test-app'),
Expand All @@ -25,7 +29,7 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['Firefox'],
singleRun: false,
restartOnFileChange: true
});
Expand Down
90 changes: 90 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-firefox-launcher": "^2.1.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.6.0",
"path-browserify": "^1.0.1",
Expand Down
18 changes: 16 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';
import { CreateUserComponent } from './components/create-user/create-user.component';
import { UsersTableComponent } from './components/users-table/users-table.component';
import { APP_ROUTES } from './enums/app-routes.enum';


const routes: Routes = [];
const routes: Routes = [
{
path: APP_ROUTES.USERS,
component: UsersTableComponent,
},
{
path: APP_ROUTES.CREATE_USER,
component: CreateUserComponent,
pathMatch: 'full'
},
{ path: '**', redirectTo: APP_ROUTES.USERS, pathMatch: 'full' }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<router-outlet></router-outlet>
<mat-toolbar>{{'APP.TITLE'}}</mat-toolbar>
<mat-progress-bar mode="indeterminate" *ngIf="isLoading"></mat-progress-bar>
<router-outlet></router-outlet>
3 changes: 3 additions & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mat-progress-bar {
position: absolute;
}
56 changes: 54 additions & 2 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import { TestBed, async } from '@angular/core/testing';
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { MatProgressBarModule, MatToolbarModule } from '@angular/material';
import { RouterTestingModule } from '@angular/router/testing';
import { of, BehaviorSubject } from 'rxjs';
import { AppComponent } from './app.component';
import { LoadingService } from './services/loading.service';

describe('AppComponent', () => {

let _loading = new BehaviorSubject(false);
beforeEach(async(() => {
const mockLoadingService = jasmine.createSpyObj('LoadingService', ['isLoading', 'setLoading', 'loading']);

mockLoadingService.isLoading.and.callFake(function(){
return _loading;
});
mockLoadingService.setLoading.and.callFake(function(loading:boolean){
_loading.next(loading);
});
mockLoadingService.loading.and.callFake(function(){
return _loading.asObservable();
});

TestBed.configureTestingModule({
imports: [
RouterTestingModule
RouterTestingModule,
MatToolbarModule,
MatProgressBarModule
],
declarations: [
AppComponent
],
providers: [{ provide: LoadingService, useValue: mockLoadingService }]
}).compileComponents();
}));

Expand All @@ -19,4 +39,36 @@ describe('AppComponent', () => {
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});

it('should subscribe to loading events', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
app.ngOnInit();

expect(app.subscriptions).toBeTruthy();
expect(app.subscriptions.length).toBeGreaterThan(0);
expect(app.subscriptions[0].closed).toBeFalsy();
});

it('it should update loading value', (fakeAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
const service = fixture.debugElement.injector.get(LoadingService);
app.ngOnInit();

expect(app.isLoading).toBe(false);
service.setLoading(true);
tick(150);
expect(app.isLoading).toBe(true);
})));

it('it should unsubscribe on destroy', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
app.ngOnInit();

expect(app.subscriptions).toBeTruthy();
app.ngOnDestroy();
expect(app.subscriptions[0].closed).toBeTruthy();
});
});
28 changes: 26 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import { Component } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { LoadingService } from './services/loading.service';

@Component({
selector: 'exads-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent { }
export class AppComponent implements OnInit {

private subscriptions: Subscription[] = [];
public isLoading: boolean = false;
constructor(public loadingService: LoadingService) {
}
ngOnInit(): void {
this.subscriptions.push(
this.loadingService.loading().subscribe((loading) => {
// use short timeout to prevent ExpressionChangedAfterItHasBeenCheckedError
setTimeout(() => {
this.isLoading = loading;
}, 100)
})
);
}

ngOnDestroy(): void {
this.subscriptions.forEach(sub => {
sub.unsubscribe();
});
}
}
36 changes: 30 additions & 6 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
import { BrowserModule } from '@angular/platform-browser';
import { LoadingInterceptor } from './interceptors/loading.interceptor';
import { HttpClientModule, HTTP_INTERCEPTORS, HttpInterceptor } from '@angular/common/http';
import { NgModule } from '@angular/core';

import { ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule, MatInputModule, MatPaginatorIntl, MatPaginatorModule, MatProgressBarModule, MatSelectModule, MatSnackBarModule, MatTableModule, MatToolbarModule } from '@angular/material';
import { MatButtonModule } from '@angular/material/button';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CreateUserComponent } from './components/create-user/create-user.component';
import { UsersTableComponent } from './components/users-table/users-table.component';
import { CustomMatPagerIntl } from './mat-helpers/custom-mat-pager-intl';


@NgModule({
declarations: [
AppComponent
AppComponent,
UsersTableComponent,
CreateUserComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule
BrowserAnimationsModule,
HttpClientModule,
MatTableModule,
MatPaginatorModule,
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
ReactiveFormsModule,
MatToolbarModule,
MatProgressBarModule,
MatSnackBarModule
],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: LoadingInterceptor, multi: true },
{ provide: MatPaginatorIntl, useClass: CustomMatPagerIntl}
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Loading