├── src ├── assets │ ├── .gitkeep │ └── db.json ├── app │ ├── app.component.css │ ├── bookmark │ │ ├── bookmark.component.css │ │ ├── bookmark-interface.ts │ │ ├── bookmark.component.html │ │ ├── bookmark.component.ts │ │ └── bookmark.component.spec.ts │ ├── add-bookmark │ │ ├── add-bookmark.component.css │ │ ├── add-bookmark.component.html │ │ ├── add-bookmark.component.ts │ │ └── add-bookmark.component.spec.ts │ ├── store │ │ ├── bookmark.selectors.spec.ts │ │ ├── bookmark.selectors.ts │ │ ├── bookmark.actions.spec.ts │ │ ├── bookmark.actions.ts │ │ ├── bookmark.reducer.ts │ │ ├── bookmark.effects.ts │ │ └── bookmark.reducer.spec.ts │ ├── shared │ │ └── constant.ts │ ├── app.component.html │ ├── app.component.ts │ ├── home │ │ ├── home.component.css │ │ ├── home.component.ts │ │ ├── home.component.html │ │ └── home.component.spec.ts │ ├── reducers │ │ └── index.ts │ ├── app-routing.module.ts │ ├── service │ │ ├── bookmark.service.ts │ │ └── bookmark.service.spec.ts │ ├── app.module.ts │ └── app.component.spec.ts ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── styles.css ├── main.ts ├── index.html ├── test.ts └── polyfills.ts ├── .prettierignore ├── screenshots ├── add_bookmark.PNG ├── health_group.PNG ├── travel_group.png ├── work_group.PNG ├── personal_group.PNG └── enabled_add_button.PNG ├── debug.log ├── .prettierrc ├── tsconfig.spec.json ├── e2e ├── tsconfig.json ├── src │ ├── app.po.ts │ └── app.e2e-spec.ts └── protractor.conf.js ├── tsconfig.app.json ├── .editorconfig ├── browserslist ├── tsconfig.json ├── .gitignore ├── karma.conf.js ├── tslint.json ├── package.json ├── README.md └── angular.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/bookmark/bookmark.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/add-bookmark/add-bookmark.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | package-lock.json 3 | yarn.lock 4 | dist 5 | e2e 6 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/src/favicon.ico -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | }; 4 | -------------------------------------------------------------------------------- /screenshots/add_bookmark.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/add_bookmark.PNG -------------------------------------------------------------------------------- /screenshots/health_group.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/health_group.PNG -------------------------------------------------------------------------------- /screenshots/travel_group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/travel_group.png -------------------------------------------------------------------------------- /screenshots/work_group.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/work_group.PNG -------------------------------------------------------------------------------- /screenshots/personal_group.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/personal_group.PNG -------------------------------------------------------------------------------- /debug.log: -------------------------------------------------------------------------------- 1 | [0210/114713.066:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3) 2 | -------------------------------------------------------------------------------- /screenshots/enabled_add_button.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajeshkumarbehura/bookmark/main/screenshots/enabled_add_button.PNG -------------------------------------------------------------------------------- /src/app/bookmark/bookmark-interface.ts: -------------------------------------------------------------------------------- 1 | export interface Bookmark { 2 | id; 3 | name: string; 4 | url: string; 5 | group: string; 6 | } 7 | -------------------------------------------------------------------------------- /src/app/store/bookmark.selectors.spec.ts: -------------------------------------------------------------------------------- 1 | describe('Bookmark Selectors', () => { 2 | it('should select the feature state', () => {}); 3 | }); 4 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import '@angular/material/prebuilt-themes/indigo-pink.css'; 3 | -------------------------------------------------------------------------------- /src/app/shared/constant.ts: -------------------------------------------------------------------------------- 1 | export const REST_API = 'http://localhost:3000/bookmarks'; 2 | export const BOOKMARK_GROUPS = ['Travel', 'Health', 'Work', 'Personal']; 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": true, 3 | "semi": true, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "printWidth": 150, 7 | "endOfLine": "lf", 8 | "proseWrap": "always" 9 | } 10 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | My Bookmarks 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'], 7 | }) 8 | export class AppComponent { 9 | title = 'bookmarks-app'; 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": ["jasmine", "node"] 6 | }, 7 | "files": ["src/test.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.spec.ts", "src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": ["src/main.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.ts"], 9 | "exclude": ["src/test.ts", "src/**/*.spec.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/app/home/home.component.css: -------------------------------------------------------------------------------- 1 | .main-container { 2 | position: absolute; 3 | top: 72px; 4 | bottom: 0; 5 | left: 10px; 6 | right: 10px; 7 | } 8 | 9 | .side-container { 10 | width: 300px; 11 | text-align: center; 12 | top: 10px; 13 | } 14 | 15 | .region-container { 16 | text-align: center; 17 | top: 10px; 18 | } 19 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic() 12 | .bootstrapModule(AppModule) 13 | .catch((err) => console.error(err)); 14 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BookmarksApp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/app/bookmark/bookmark.component.html: -------------------------------------------------------------------------------- 1 | Content 2 | 3 |
4 |
5 |
{{ item.name }}
6 | {{ item.url }} 7 |
8 | 9 |
10 |
11 | -------------------------------------------------------------------------------- /src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { BookmarkService } from '../service/bookmark.service'; 3 | import { BOOKMARK_GROUPS } from '../shared/constant'; 4 | 5 | @Component({ 6 | selector: 'app-home', 7 | templateUrl: './home.component.html', 8 | styleUrls: ['./home.component.css'], 9 | }) 10 | export class HomeComponent implements OnInit { 11 | constructor(private service: BookmarkService) {} 12 | 13 | groups = BOOKMARK_GROUPS; 14 | groupName = this.groups[0]; 15 | 16 | ngOnInit() {} 17 | } 18 | -------------------------------------------------------------------------------- /src/app/reducers/index.ts: -------------------------------------------------------------------------------- 1 | import { ActionReducerMap, MetaReducer } from '@ngrx/store'; 2 | import { environment } from '../../environments/environment'; 3 | import * as fromBm from '../store/bookmark.reducer'; 4 | 5 | export const stateFeatureKey = 'state'; 6 | 7 | export interface State { 8 | [fromBm.bookmarkFeatureKey]: fromBm.State; 9 | } 10 | 11 | export const reducers: ActionReducerMap = { 12 | [fromBm.bookmarkFeatureKey]: fromBm.reducer, 13 | }; 14 | 15 | export const metaReducers: MetaReducer[] = !environment.production ? [] : []; 16 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { AddBookmarkComponent } from './add-bookmark/add-bookmark.component'; 4 | import { HomeComponent } from './home/home.component'; 5 | 6 | export const routes: Routes = [ 7 | { path: '', component: HomeComponent }, 8 | { path: 'add', component: AddBookmarkComponent }, 9 | ]; 10 | 11 | @NgModule({ 12 | imports: [RouterModule.forRoot(routes)], 13 | exports: [RouterModule], 14 | }) 15 | export class AppRoutingModule {} 16 | -------------------------------------------------------------------------------- /src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
Groups
4 |
5 | 6 | {{ item }} 7 | 8 |
9 | 10 | 11 | 12 |
13 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": ["node_modules/@types"], 15 | "lib": ["es2018", "dom"] 16 | }, 17 | "angularCompilerOptions": { 18 | "fullTemplateTypeCheck": true, 19 | "strictInjectionParameters": true 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/store/bookmark.selectors.ts: -------------------------------------------------------------------------------- 1 | import { createFeatureSelector, createSelector } from '@ngrx/store'; 2 | 3 | import { State } from './bookmark.reducer'; 4 | 5 | const getFeatureState = createFeatureSelector('bookmark'); 6 | 7 | export const getBookmarks = createSelector(getFeatureState, (state) => state.bookmark); 8 | 9 | export const getError = createSelector(getFeatureState, (state) => state.error); 10 | 11 | export const deleteBookmark = createSelector(getFeatureState, (state) => state.bookmark); 12 | 13 | export const createBookmark = createSelector(getFeatureState, (state) => state.bookmark); 14 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 6 | 7 | declare const require: any; 8 | 9 | // First, initialize the Angular testing environment. 10 | getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); 11 | // Then we find all the tests. 12 | const context = require.context('./', true, /\.spec\.ts$/); 13 | // And load the modules. 14 | context.keys().map(context); 15 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('bookmarks-app app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /src/app/service/bookmark.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | import { Bookmark } from '../bookmark/bookmark-interface'; 5 | import { REST_API } from '../shared/constant'; 6 | 7 | @Injectable({ 8 | providedIn: 'root', 9 | }) 10 | export class BookmarkService { 11 | constructor(private http: HttpClient) {} 12 | 13 | getBookmarks(): Observable { 14 | return this.http.get(REST_API); 15 | } 16 | 17 | deleteBookmark(bookmarkId): Observable { 18 | return this.http.delete(REST_API + '/' + bookmarkId); 19 | } 20 | 21 | createBookmark(bookmark: Bookmark): Observable { 22 | return this.http.post(REST_API, bookmark); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /src/app/store/bookmark.actions.spec.ts: -------------------------------------------------------------------------------- 1 | import * as BookmarkActions from './bookmark.actions'; 2 | 3 | describe('BookmarkAction', () => { 4 | it('should create an instance of LoadBookmarks', () => { 5 | expect(new BookmarkActions.LoadBookmarks()).toBeTruthy(); 6 | }); 7 | 8 | it('should create an instance of LoadBookmarksSuccess', () => { 9 | expect(new BookmarkActions.LoadBookmarksSuccess({ data: null })).toBeTruthy(); 10 | }); 11 | 12 | it('should create an instance of LoadBookmarksFailure', () => { 13 | expect(new BookmarkActions.LoadBookmarksFailure({ error: null })).toBeTruthy(); 14 | }); 15 | 16 | it('should create an instance of DeleteBookmarks', () => { 17 | expect(new BookmarkActions.DeleteBookmarks(null)).toBeTruthy(); 18 | }); 19 | 20 | it('should create an instance of CreateBookmark', () => { 21 | expect(new BookmarkActions.CreateBookmark(null)).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/bookmarks-app'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /src/app/add-bookmark/add-bookmark.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | You must enter a name 5 | 6 | 7 | 8 | You must enter a url 9 | 10 | 11 | 12 | 13 | {{ item }} 14 | 15 | 16 | You must select a group 17 | 18 |
19 |
20 | 28 | 29 |
30 |
31 | -------------------------------------------------------------------------------- /src/app/service/bookmark.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { BookmarkService } from './bookmark.service'; 4 | import { HttpClientTestingModule } from '@angular/common/http/testing'; 5 | import { HttpClient } from '@angular/common/http'; 6 | 7 | describe('BookmarkService', () => { 8 | let httpClient: HttpClient; 9 | let service: BookmarkService; 10 | 11 | beforeEach(() => { 12 | TestBed.configureTestingModule({ 13 | imports: [HttpClientTestingModule], 14 | }); 15 | service = TestBed.get(BookmarkService); 16 | httpClient = TestBed.get(HttpClient); 17 | }); 18 | 19 | it('should be created', async () => { 20 | spyOn(httpClient, 'post').and.callThrough(); 21 | await service.createBookmark(null); 22 | expect(service).toBeTruthy(); 23 | expect(httpClient.post).toHaveBeenCalled(); 24 | }); 25 | 26 | it('should be deleted', async () => { 27 | spyOn(httpClient, 'delete').and.callThrough(); 28 | await service.deleteBookmark('12'); 29 | expect(service).toBeTruthy(); 30 | expect(httpClient.delete).toHaveBeenCalled(); 31 | }); 32 | 33 | it('should be fetched', async () => { 34 | spyOn(httpClient, 'get').and.callThrough(); 35 | await service.getBookmarks(); 36 | expect(service).toBeTruthy(); 37 | expect(httpClient.get).toHaveBeenCalled(); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/app/add-bookmark/add-bookmark.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { Store } from '@ngrx/store'; 4 | import { Bookmark } from '../bookmark/bookmark-interface'; 5 | import { BookmarkService } from '../service/bookmark.service'; 6 | import * as BookmarkActions from '../store/bookmark.actions'; 7 | import { FormControl, Validators } from '@angular/forms'; 8 | import { BOOKMARK_GROUPS } from '../shared/constant'; 9 | 10 | @Component({ 11 | selector: 'app-add-bookmark', 12 | templateUrl: './add-bookmark.component.html', 13 | styleUrls: ['./add-bookmark.component.css'], 14 | }) 15 | export class AddBookmarkComponent implements OnInit { 16 | bookmarkName = new FormControl('', [Validators.required]); 17 | bookmarkUrl = new FormControl('', [Validators.required]); 18 | bookmarkGroup = new FormControl('', [Validators.required]); 19 | 20 | constructor(private store: Store, private router: Router) {} 21 | ngOnInit() {} 22 | 23 | createBookmark() { 24 | const newBookmark: Bookmark = { id: '', name: '', url: '', group: '' }; 25 | newBookmark.name = this.bookmarkName.value; 26 | newBookmark.url = this.bookmarkUrl.value; 27 | newBookmark.group = this.bookmarkGroup.value; 28 | 29 | this.store.dispatch(new BookmarkActions.CreateBookmark(newBookmark)); 30 | this.router.navigate(['/']); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/app/store/bookmark.actions.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | import { Bookmark } from '../bookmark/bookmark-interface'; 3 | 4 | export enum BookmarkActionTypes { 5 | LoadBookmarks = '[Bookmark] Load Bookmarks', 6 | LoadBookmarksSuccess = '[Bookmark] Load Bookmarks Success', 7 | LoadBookmarksFailure = '[Bookmark] Load Bookmarks Failure', 8 | DeleteBookmarks = '[Bookmark] Delete Bookmark', 9 | CreateBookmark = '[Bookmark] create Bookmark', 10 | } 11 | 12 | export class LoadBookmarks implements Action { 13 | readonly type = BookmarkActionTypes.LoadBookmarks; 14 | } 15 | 16 | export class LoadBookmarksSuccess implements Action { 17 | readonly type = BookmarkActionTypes.LoadBookmarksSuccess; 18 | constructor(public payload: { data: Bookmark[] }) {} 19 | } 20 | 21 | export class LoadBookmarksFailure implements Action { 22 | readonly type = BookmarkActionTypes.LoadBookmarksFailure; 23 | constructor(public payload: { error: any }) {} 24 | } 25 | 26 | export class DeleteBookmarks implements Action { 27 | readonly type = BookmarkActionTypes.DeleteBookmarks; 28 | constructor(public payload: string) {} 29 | } 30 | 31 | export class CreateBookmark implements Action { 32 | readonly type = BookmarkActionTypes.CreateBookmark; 33 | constructor(public payload: Bookmark) {} 34 | } 35 | 36 | export type BookmarkActions = LoadBookmarks | LoadBookmarksSuccess | LoadBookmarksFailure | DeleteBookmarks | CreateBookmark; 37 | -------------------------------------------------------------------------------- /src/app/store/bookmark.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | import { Bookmark } from '../bookmark/bookmark-interface'; 3 | import { BookmarkActions, BookmarkActionTypes } from './bookmark.actions'; 4 | 5 | export const bookmarkFeatureKey = 'bookmark'; 6 | 7 | export interface State { 8 | bookmark: Bookmark[]; 9 | error: string; 10 | } 11 | 12 | export const initialState: State = { 13 | bookmark: [], 14 | error: '', 15 | }; 16 | 17 | export function reducer(state = initialState, action: BookmarkActions): State { 18 | switch (action.type) { 19 | case BookmarkActionTypes.LoadBookmarks: 20 | return { 21 | ...state, 22 | }; 23 | 24 | case BookmarkActionTypes.LoadBookmarksSuccess: 25 | return { 26 | ...state, 27 | bookmark: action.payload.data, 28 | error: '', 29 | }; 30 | 31 | case BookmarkActionTypes.LoadBookmarksFailure: 32 | return { 33 | ...state, 34 | bookmark: [], 35 | error: action.payload.error, 36 | }; 37 | 38 | case BookmarkActionTypes.CreateBookmark: 39 | return { 40 | ...state, 41 | bookmark: [action.payload], 42 | error: '', 43 | }; 44 | 45 | case BookmarkActionTypes.DeleteBookmarks: 46 | return { 47 | ...state, 48 | bookmark: state.bookmark.filter((item) => item.id !== action.payload), 49 | error: '', 50 | }; 51 | default: 52 | return state; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/app/bookmark/bookmark.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, OnChanges, OnInit } from '@angular/core'; 2 | import { select } from '@ngrx/store'; 3 | import { Store } from '@ngrx/store'; 4 | import { Bookmark } from './bookmark-interface'; 5 | import * as BookmarkActions from '../store/bookmark.actions'; 6 | import * as BookmarkSelector from '../store/bookmark.selectors'; 7 | import { BookmarkService } from '../service/bookmark.service'; 8 | 9 | @Component({ 10 | selector: 'app-bookmark', 11 | templateUrl: './bookmark.component.html', 12 | styleUrls: ['./bookmark.component.css'], 13 | }) 14 | export class BookmarkComponent implements OnChanges { 15 | filteredBookmarks: Bookmark[]; 16 | errorMessage = ''; 17 | @Input() groupName: string; 18 | 19 | constructor(private store: Store, private service: BookmarkService) {} 20 | 21 | ngOnChanges() { 22 | this.getBookmarks(); 23 | } 24 | 25 | getBookmarks() { 26 | /* this.service.getBookmarks().subscribe(data=>{ 27 | let bookmarks=data; 28 | this.filteredBookmarks = bookmarks.filter(ele=>ele.group==this.groupName) 29 | }) */ 30 | 31 | this.store.dispatch(new BookmarkActions.LoadBookmarks()); // action dispatch 32 | 33 | this.store.pipe(select(BookmarkSelector.getBookmarks)).subscribe((ele) => { 34 | const bookmarks = ele; 35 | this.filteredBookmarks = bookmarks.filter((data) => data.group === this.groupName); 36 | }); 37 | 38 | this.store.pipe(select(BookmarkSelector.getError)).subscribe((err) => { 39 | this.errorMessage = err; 40 | }); 41 | } 42 | 43 | deleteBookmark(bookmarkId) { 44 | this.store.dispatch(new BookmarkActions.DeleteBookmarks(bookmarkId)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/store/bookmark.effects.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {Actions, Effect, ofType} from '@ngrx/effects'; 3 | import {Action} from '@ngrx/store'; 4 | import * as BookmarkActions from './bookmark.actions'; 5 | import {CreateBookmark, DeleteBookmarks} from './bookmark.actions'; 6 | import {Observable, of} from 'rxjs'; 7 | import {catchError, map, mergeMap, switchMap} from 'rxjs/operators'; 8 | import {BookmarkService} from '../service/bookmark.service'; 9 | 10 | @Injectable() 11 | export class BookmarkEffects { 12 | constructor(private actions$: Actions, private bookmarkService: BookmarkService) {} 13 | 14 | @Effect() 15 | loadBookmarks$: Observable = this.actions$.pipe( 16 | ofType(BookmarkActions.BookmarkActionTypes.LoadBookmarks), 17 | mergeMap((action) => 18 | this.bookmarkService.getBookmarks().pipe( 19 | map((ele) => new BookmarkActions.LoadBookmarksSuccess({ data: ele })), 20 | catchError((err) => of(new BookmarkActions.LoadBookmarksFailure({ error: err }))) 21 | ) 22 | ) 23 | ); 24 | 25 | @Effect({ dispatch: false }) 26 | deleteBookmarks$ = this.actions$.pipe( 27 | ofType(BookmarkActions.BookmarkActionTypes.DeleteBookmarks), 28 | switchMap((action) => this.bookmarkService.deleteBookmark(action.payload)) 29 | ); 30 | 31 | @Effect() 32 | postBookmarkData$ = this.actions$.pipe( 33 | ofType(BookmarkActions.BookmarkActionTypes.CreateBookmark), 34 | mergeMap((action) => { 35 | return this.bookmarkService.createBookmark(action.payload).pipe( 36 | map((data) => { 37 | return new BookmarkActions.LoadBookmarks(); 38 | }) 39 | ); 40 | }) 41 | ); 42 | } 43 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:recommended", "tslint-config-prettier"], 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [true, "attribute", "app", "camelCase"], 13 | "component-selector": [true, "element", "app", "kebab-case"], 14 | "import-blacklist": [true, "rxjs/Rx"], 15 | "interface-name": false, 16 | "max-classes-per-file": false, 17 | "max-line-length": [true, 140], 18 | "member-access": false, 19 | "member-ordering": [ 20 | true, 21 | { 22 | "order": ["static-field", "instance-field", "static-method", "instance-method"] 23 | } 24 | ], 25 | "no-consecutive-blank-lines": false, 26 | "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], 27 | "no-empty": false, 28 | "no-inferrable-types": [true, "ignore-params"], 29 | "no-non-null-assertion": true, 30 | "no-redundant-jsdoc": true, 31 | "no-switch-case-fall-through": true, 32 | "no-var-requires": false, 33 | "object-literal-key-quotes": [true, "as-needed"], 34 | "object-literal-sort-keys": false, 35 | "ordered-imports": false, 36 | "quotemark": [true, "single"], 37 | "trailing-comma": false, 38 | "no-conflicting-lifecycle": true, 39 | "no-host-metadata-property": true, 40 | "no-input-rename": true, 41 | "no-inputs-metadata-property": true, 42 | "no-output-native": true, 43 | "no-output-on-prefix": true, 44 | "no-output-rename": true, 45 | "no-outputs-metadata-property": true, 46 | "template-banana-in-box": true, 47 | "template-no-negated-async": true, 48 | "use-lifecycle-interface": true, 49 | "use-pipe-transform-interface": true 50 | }, 51 | "rulesDirectory": ["codelyzer"] 52 | } 53 | -------------------------------------------------------------------------------- /src/app/store/bookmark.reducer.spec.ts: -------------------------------------------------------------------------------- 1 | import { initialState, reducer } from './bookmark.reducer'; 2 | import { CreateBookmark, DeleteBookmarks, LoadBookmarks, LoadBookmarksFailure, LoadBookmarksSuccess } from './bookmark.actions'; 3 | 4 | describe('Bookmark Reducer', () => { 5 | describe('an unknown action', () => { 6 | it('should return the previous state', () => { 7 | const action = {} as any; 8 | const result = reducer(initialState, action); 9 | expect(result).toBe(initialState); 10 | }); 11 | }); 12 | 13 | describe('known action', () => { 14 | const mockBookmark = { 15 | id: '', 16 | name: 'travel tour', 17 | url: 'travel.com', 18 | group: 'travel', 19 | }; 20 | 21 | it('should return the previous state for LoadBookmarks', () => { 22 | const result = reducer({ bookmark: [mockBookmark], error: null }, new LoadBookmarks()); 23 | expect(result.bookmark[0]).toEqual(mockBookmark); 24 | }); 25 | 26 | it('should return the previous state for LoadBookmarksSuccess', () => { 27 | const result = reducer({ bookmark: [], error: null }, new LoadBookmarksSuccess({ data: [mockBookmark] })); 28 | expect(result.bookmark[0]).toEqual(mockBookmark); 29 | }); 30 | 31 | it('should return the previous state for LoadBookmarksFailure', () => { 32 | const result = reducer({ bookmark: [], error: null }, new LoadBookmarksFailure({ error: 'error' })); 33 | expect(result.error).toEqual('error'); 34 | }); 35 | 36 | it('should return the previous state for CreateBookmark', () => { 37 | const result = reducer({ bookmark: [], error: null }, new CreateBookmark(mockBookmark)); 38 | expect(result.bookmark[0]).toEqual(mockBookmark); 39 | }); 40 | 41 | it('should return the previous state for DeleteBookmarks', () => { 42 | const result = reducer({ bookmark: [], error: null }, new DeleteBookmarks('Id123')); 43 | expect(result.bookmark.length).toEqual(0); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bookmarks-app", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "json:server": "json-server --watch src/assets/db.json", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "prettier:format": "prettier --write \"{,src/**/}*.{md,json,ts,css,scss,yml,html}\"" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/animations": "~8.2.9", 17 | "@angular/cdk": "^8.2.3", 18 | "@angular/cli": "^8.3.8", 19 | "@angular/common": "~8.2.9", 20 | "@angular/compiler": "~8.2.9", 21 | "@angular/core": "~8.2.9", 22 | "@angular/flex-layout": "^8.0.0-beta.26", 23 | "@angular/forms": "~8.2.9", 24 | "@angular/material": "^8.2.3", 25 | "@angular/platform-browser": "~8.2.9", 26 | "@angular/platform-browser-dynamic": "~8.2.9", 27 | "@angular/router": "~8.2.9", 28 | "@ngrx/effects": "^10.1.2", 29 | "@ngrx/entity": "^10.1.2", 30 | "@ngrx/schematics": "^10.1.2", 31 | "@ngrx/store": "^10.1.2", 32 | "@ngrx/store-devtools": "^10.1.2", 33 | "json-server": "^0.16.3", 34 | "prettier": "^2.2.1", 35 | "rxjs": "~6.4.0", 36 | "tslib": "^1.10.0", 37 | "tslint-config-prettier": "^1.18.0", 38 | "v8": "^0.1.0", 39 | "zone.js": "~0.9.1" 40 | }, 41 | "devDependencies": { 42 | "@angular-devkit/build-angular": "~0.803.8", 43 | "@angular/compiler-cli": "~8.2.9", 44 | "@angular/language-service": "~8.2.9", 45 | "@types/jasmine": "~3.3.8", 46 | "@types/jasminewd2": "~2.0.3", 47 | "@types/node": "~8.9.4", 48 | "codelyzer": "^5.0.0", 49 | "jasmine-core": "~3.4.0", 50 | "jasmine-spec-reporter": "~4.2.1", 51 | "karma": "^6.1.0", 52 | "karma-chrome-launcher": "~2.2.0", 53 | "karma-coverage-istanbul-reporter": "~2.0.1", 54 | "karma-jasmine": "~2.0.1", 55 | "karma-jasmine-html-reporter": "^1.4.0", 56 | "protractor": "^7.0.0", 57 | "ts-node": "~7.0.0", 58 | "tslint": "~5.15.0", 59 | "typescript": "~3.5.3" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { AppRoutingModule } from './app-routing.module'; 4 | import { AppComponent } from './app.component'; 5 | import { StoreModule } from '@ngrx/store'; 6 | import * as fromState from './reducers'; 7 | import { EffectsModule } from '@ngrx/effects'; 8 | import { BookmarkEffects } from './store/bookmark.effects'; 9 | import { BookmarkComponent } from './bookmark/bookmark.component'; 10 | import { HttpClientModule } from '@angular/common/http'; 11 | import { reducers, metaReducers } from './reducers'; 12 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 13 | import { 14 | MatButtonModule, 15 | MatCardModule, 16 | MatFormFieldModule, 17 | MatIconModule, 18 | MatInputModule, 19 | MatRadioModule, 20 | MatSelectModule, 21 | MatSidenavModule, 22 | MatToolbarModule, 23 | } from '@angular/material'; 24 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 25 | import { FlexLayoutModule } from '@angular/flex-layout'; 26 | import { AddBookmarkComponent } from './add-bookmark/add-bookmark.component'; 27 | import { RouterModule } from '@angular/router'; 28 | import { HomeComponent } from './home/home.component'; 29 | 30 | @NgModule({ 31 | declarations: [AppComponent, BookmarkComponent, AddBookmarkComponent, HomeComponent], 32 | imports: [ 33 | BrowserModule, 34 | AppRoutingModule, 35 | HttpClientModule, 36 | MatSidenavModule, 37 | MatToolbarModule, 38 | MatCardModule, 39 | BrowserAnimationsModule, 40 | FlexLayoutModule, 41 | MatRadioModule, 42 | MatIconModule, 43 | MatButtonModule, 44 | MatFormFieldModule, 45 | MatInputModule, 46 | MatSelectModule, 47 | RouterModule, 48 | StoreModule.forRoot(reducers, { 49 | metaReducers, 50 | runtimeChecks: { 51 | strictStateImmutability: true, 52 | strictActionImmutability: true, 53 | }, 54 | }), 55 | EffectsModule.forRoot([BookmarkEffects]), 56 | FormsModule, 57 | ReactiveFormsModule, 58 | ], 59 | providers: [], 60 | bootstrap: [AppComponent], 61 | }) 62 | export class AppModule {} 63 | -------------------------------------------------------------------------------- /src/app/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | import { RouterTestingModule } from '@angular/router/testing'; 5 | import { BrowserModule } from '@angular/platform-browser'; 6 | import { AppRoutingModule } from '../app-routing.module'; 7 | import { HttpClientModule } from '@angular/common/http'; 8 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 9 | import { FlexLayoutModule } from '@angular/flex-layout'; 10 | import { RouterModule } from '@angular/router'; 11 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 12 | import { HttpClientTestingModule } from '@angular/common/http/testing'; 13 | import { StoreModule } from '@ngrx/store'; 14 | import { reducers } from '../reducers'; 15 | import { EffectsModule } from '@ngrx/effects'; 16 | import { BookmarkEffects } from '../store/bookmark.effects'; 17 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 18 | import { 19 | MatButtonModule, 20 | MatCardModule, 21 | MatFormFieldModule, 22 | MatIconModule, 23 | MatInputModule, 24 | MatRadioModule, 25 | MatSelectModule, 26 | MatSidenavModule, 27 | MatToolbarModule, 28 | } from '@angular/material'; 29 | import { AddBookmarkComponent } from '../add-bookmark/add-bookmark.component'; 30 | import { BookmarkComponent } from '../bookmark/bookmark.component'; 31 | 32 | describe('HomeComponent', () => { 33 | let component: HomeComponent; 34 | let fixture: ComponentFixture; 35 | 36 | beforeEach(async(() => { 37 | TestBed.configureTestingModule({ 38 | imports: [ 39 | RouterTestingModule, 40 | BrowserModule, 41 | AppRoutingModule, 42 | HttpClientModule, 43 | MatSidenavModule, 44 | MatToolbarModule, 45 | MatCardModule, 46 | BrowserAnimationsModule, 47 | FlexLayoutModule, 48 | MatRadioModule, 49 | MatIconModule, 50 | MatButtonModule, 51 | MatFormFieldModule, 52 | MatInputModule, 53 | MatSelectModule, 54 | RouterModule, 55 | ReactiveFormsModule, 56 | FormsModule, 57 | HttpClientTestingModule, 58 | StoreModule.forRoot({ ...reducers }), 59 | EffectsModule.forRoot([BookmarkEffects]), 60 | ], 61 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 62 | declarations: [HomeComponent, AddBookmarkComponent, BookmarkComponent], 63 | }).compileComponents(); 64 | })); 65 | 66 | beforeEach(() => { 67 | fixture = TestBed.createComponent(HomeComponent); 68 | component = fixture.componentInstance; 69 | fixture.detectChanges(); 70 | }); 71 | 72 | it('should create', () => { 73 | expect(component).toBeTruthy(); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Description of the solution 2 | 3 | Feature Implemented: 4 | 1. Add Bookmark by group 5 | 2. View Bookmark by group 6 | 3. Delete Bookmark by group 7 | 8 | Used HTTP GET method for displaying the bookmarks. Bookmarks are then filterd on the basis of groups. Used HTTP POST method for creating bookmarks. 9 | Used HTTP Delete method for deleting the bookmarks. 10 | 11 | Used Json server to simulate a backend REST service to deliver data in JSON format. 12 | 13 | ## Instructions to run the application 14 | 15 | Step 1 : To install all package and library, use below command. 16 | ```` 17 | yarn install 18 | ```` 19 | 20 | Step 2: Run Json Server 21 | 22 | To run the json server, use below command & it will start 23 | running on localhost:3000. Use this as url for REST APIs. 24 | 25 | ```` 26 | yarn json:server 27 | ```` 28 | 29 | Step 3: Run the application 30 | 31 | ``` 32 | yarn start 33 | ``` 34 | Next, to run the user interface, open a new cmd window and run "npm start". It will start running on localhost:4200 35 | 36 | ## Screenshots 37 | 38 | Please find 'screenshots' folder in the repository. 39 | 40 | ## Development server 41 | 42 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 43 | 44 | ## Code scaffolding 45 | 46 | Run `ng generate component component-name` to generate a new component. You can also use 47 | `ng generate directive|pipe|service|class|guard|interface|enum|module`. 48 | 49 | ## Build 50 | 51 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 52 | 53 | ## Running unit tests 54 | This applicaiton use Karma to run test cases. 55 | Below command helps to run test cases & also produces code coverage report 56 | 57 | ``` 58 | yarn test 59 | ``` 60 | 61 | Code coverage report : 62 | ```` 63 | Coverage summary 64 | Statements : 93.27% ( 97/104 ) 65 | Branches : 90.91% ( 10/11 ) 66 | Functions : 80.56% ( 29/36 ) 67 | Lines : 95.35% ( 82/86 ) 68 | ```` 69 | 70 | ## Code Format and Clean before pushing to Git 71 | 72 | Clean and format using lint & prettfier. This feature later can hookup with git, so that any push command fire, it must go through formatting code 73 | ``` 74 | yarn prettier:format 75 | yarn lint 76 | ``` 77 | 78 | ## Running end-to-end tests 79 | 80 | Not implemented at this stage due to lack of time, But application must build integration test cases. 81 | 82 | ## Review & Thoughts 83 | 1. Project needs to be more structured based on folder structure. Good folder architecture helps to understand code and maintain it. 84 | 2. Every feature must implement with Module style, which helps to build efficient testing mechanism and plug&play style of coding. 85 | 3. Code formatting must be step to cleanup. 86 | 4. Error log tracking must be done using elastic search, log rocket. 87 | 5. Every API fired must attached with requestID. 88 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async, fakeAsync, tick } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | import { RouterModule } from '@angular/router'; 5 | import { 6 | MatButtonModule, 7 | MatCardModule, 8 | MatFormFieldModule, 9 | MatIconModule, 10 | MatInputModule, 11 | MatRadioModule, 12 | MatSelectModule, 13 | MatSidenavModule, 14 | MatToolbarModule, 15 | } from '@angular/material'; 16 | import { BrowserModule, By } from '@angular/platform-browser'; 17 | import { AppRoutingModule } from './app-routing.module'; 18 | import { HttpClientModule } from '@angular/common/http'; 19 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 20 | import { FlexLayoutModule } from '@angular/flex-layout'; 21 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 22 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 23 | import { HomeComponent } from './home/home.component'; 24 | import { BookmarkComponent } from './bookmark/bookmark.component'; 25 | import { AddBookmarkComponent } from './add-bookmark/add-bookmark.component'; 26 | 27 | describe('AppComponent', () => { 28 | beforeEach(fakeAsync(() => { 29 | TestBed.configureTestingModule({ 30 | imports: [ 31 | RouterTestingModule, 32 | BrowserModule, 33 | AppRoutingModule, 34 | HttpClientModule, 35 | MatSidenavModule, 36 | MatToolbarModule, 37 | MatCardModule, 38 | BrowserAnimationsModule, 39 | FlexLayoutModule, 40 | MatRadioModule, 41 | MatIconModule, 42 | MatButtonModule, 43 | MatFormFieldModule, 44 | MatInputModule, 45 | MatSelectModule, 46 | RouterModule, 47 | ReactiveFormsModule, 48 | FormsModule, 49 | ], 50 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 51 | declarations: [HomeComponent, AppComponent, BookmarkComponent, AddBookmarkComponent], 52 | }).compileComponents(); 53 | tick(); 54 | })); 55 | 56 | it('should create the app', () => { 57 | const fixture = TestBed.createComponent(AppComponent); 58 | const app = fixture.debugElement.componentInstance; 59 | expect(app).toBeTruthy(); 60 | }); 61 | 62 | it(`should have as title 'bookmarks-app'`, () => { 63 | const fixture = TestBed.createComponent(AppComponent); 64 | const app = fixture.debugElement.componentInstance; 65 | expect(app.title).toEqual('bookmarks-app'); 66 | }); 67 | 68 | it('should render Add Bookmark button', fakeAsync(() => { 69 | const fixture = TestBed.createComponent(AppComponent); 70 | fixture.detectChanges(); 71 | const buttonSelector = fixture.nativeElement.querySelector('button'); 72 | 73 | // validate Add Bookmark for Button 74 | expect(buttonSelector.textContent).toContain('Add bookmark'); 75 | })); 76 | 77 | it('should render My Bookmark Heading', () => { 78 | const fixture = TestBed.createComponent(AppComponent); 79 | fixture.detectChanges(); 80 | const heading = fixture.nativeElement.querySelector('span'); 81 | 82 | // validate Home page Heading 83 | expect(heading.textContent).toContain('My Bookmarks'); 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /src/assets/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "bookmarks": [ 3 | { 4 | "id": 1, 5 | "name": "Tripadvisor", 6 | "url": "https://www.tripadvisor.in/", 7 | "group": "travel" 8 | }, 9 | { 10 | "id": 2, 11 | "name": "Trivago", 12 | "url": "https://www.trivago.in/", 13 | "group": "travel" 14 | }, 15 | { 16 | "id": 3, 17 | "name": "Angular docs", 18 | "url": "https://angular.io/docs", 19 | "group": "work" 20 | }, 21 | { 22 | "id": 4, 23 | "name": "About Firebase", 24 | "url": "https://medium.com/firebase-developers/what-is-firebase-the-complete-story-abridged-bcc730c5f2c0", 25 | "group": "work" 26 | }, 27 | { 28 | "id": 5, 29 | "name": "Balance exercise", 30 | "url": "https://www.healthifyme.com/blog/all-about-balance-exercise-and-the-different-ways-to-practice-it/", 31 | "group": "health" 32 | }, 33 | { 34 | "id": 6 35 | }, 36 | { 37 | "id": 7, 38 | "name": "vcv" 39 | }, 40 | { 41 | "id": 9 42 | }, 43 | { 44 | "id": 11, 45 | "name": "instagram", 46 | "url": "https://www.raywenderlich.com/3-firebase-tutorial-getting-started", 47 | "group": "leisure" 48 | }, 49 | { 50 | "id": 136, 51 | "name": "yoga benefits", 52 | "url": "https://www.webmd.com/balance/guide/the-health-benefits-of-yoga", 53 | "group": "health" 54 | }, 55 | { 56 | "id": 137, 57 | "name": "cardio exercises", 58 | "url": "https://www.verywellfit.com/best-home-cardio-exercises-1231273", 59 | "group": "health" 60 | }, 61 | { 62 | "id": 138, 63 | "name": "Yoga", 64 | "url": "https://www.artofliving.org/in-en/yoga", 65 | "group": "Health" 66 | }, 67 | { 68 | "id": 140, 69 | "name": "Ionic guide", 70 | "url": "https://ionicframework.com/#", 71 | "group": "Work" 72 | }, 73 | { 74 | "id": 142, 75 | "name": "", 76 | "url": "", 77 | "group": "" 78 | }, 79 | { 80 | "id": 143, 81 | "name": "", 82 | "url": "", 83 | "group": "" 84 | }, 85 | { 86 | "id": 144, 87 | "name": "", 88 | "url": "", 89 | "group": "" 90 | }, 91 | { 92 | "id": 145, 93 | "name": "", 94 | "url": "", 95 | "group": "" 96 | }, 97 | { 98 | "id": 146, 99 | "name": "", 100 | "url": "", 101 | "group": "" 102 | }, 103 | { 104 | "id": 147, 105 | "name": "youtube", 106 | "url": "https://youtube.com/", 107 | "group": "Personal" 108 | }, 109 | { 110 | "id": 151, 111 | "name": "Cardio exercises", 112 | "url": "https://www.verywellfit.com/best-home-cardio-exercises-1231273", 113 | "group": "Health" 114 | }, 115 | { 116 | "id": 152, 117 | "name": "Google Map", 118 | "url": "https://www.google.com/maps/", 119 | "group": "Personal" 120 | }, 121 | { 122 | "id": 153, 123 | "name": "Gitlab", 124 | "url": "https://about.gitlab.com/", 125 | "group": "Work" 126 | }, 127 | { 128 | "id": 154, 129 | "name": "Jira", 130 | "url": "https://www.atlassian.com/software/jira", 131 | "group": "Work" 132 | } 133 | ] 134 | } -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "bookmarks-app": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/bookmarks-app", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": false, 22 | "assets": ["src/favicon.ico", "src/assets"], 23 | "styles": ["src/styles.css"], 24 | "scripts": [] 25 | }, 26 | "configurations": { 27 | "production": { 28 | "fileReplacements": [ 29 | { 30 | "replace": "src/environments/environment.ts", 31 | "with": "src/environments/environment.prod.ts" 32 | } 33 | ], 34 | "optimization": true, 35 | "outputHashing": "all", 36 | "sourceMap": false, 37 | "extractCss": true, 38 | "namedChunks": false, 39 | "aot": true, 40 | "extractLicenses": true, 41 | "vendorChunk": false, 42 | "buildOptimizer": true, 43 | "budgets": [ 44 | { 45 | "type": "initial", 46 | "maximumWarning": "2mb", 47 | "maximumError": "5mb" 48 | }, 49 | { 50 | "type": "anyComponentStyle", 51 | "maximumWarning": "6kb", 52 | "maximumError": "10kb" 53 | } 54 | ] 55 | } 56 | } 57 | }, 58 | "serve": { 59 | "builder": "@angular-devkit/build-angular:dev-server", 60 | "options": { 61 | "browserTarget": "bookmarks-app:build" 62 | }, 63 | "configurations": { 64 | "production": { 65 | "browserTarget": "bookmarks-app:build:production" 66 | } 67 | } 68 | }, 69 | "extract-i18n": { 70 | "builder": "@angular-devkit/build-angular:extract-i18n", 71 | "options": { 72 | "browserTarget": "bookmarks-app:build" 73 | } 74 | }, 75 | "test": { 76 | "builder": "@angular-devkit/build-angular:karma", 77 | "options": { 78 | "main": "src/test.ts", 79 | "polyfills": "src/polyfills.ts", 80 | "tsConfig": "tsconfig.spec.json", 81 | "karmaConfig": "karma.conf.js", 82 | "assets": ["src/favicon.ico", "src/assets"], 83 | "styles": ["src/styles.css"], 84 | "scripts": [], 85 | "codeCoverage": true 86 | } 87 | }, 88 | "lint": { 89 | "builder": "@angular-devkit/build-angular:tslint", 90 | "options": { 91 | "tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"], 92 | "exclude": ["**/node_modules/**"] 93 | } 94 | }, 95 | "e2e": { 96 | "builder": "@angular-devkit/build-angular:protractor", 97 | "options": { 98 | "protractorConfig": "e2e/protractor.conf.js", 99 | "devServerTarget": "bookmarks-app:serve" 100 | }, 101 | "configurations": { 102 | "production": { 103 | "devServerTarget": "bookmarks-app:serve:production" 104 | } 105 | } 106 | } 107 | } 108 | } 109 | }, 110 | "defaultProject": "bookmarks-app", 111 | "cli": { 112 | "defaultCollection": "@ngrx/schematics" 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/app/bookmark/bookmark.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; 2 | 3 | import { BookmarkComponent } from './bookmark.component'; 4 | import { RouterTestingModule } from '@angular/router/testing'; 5 | import { BrowserModule } from '@angular/platform-browser'; 6 | import { AppRoutingModule } from '../app-routing.module'; 7 | import { HttpClient, HttpClientModule } from '@angular/common/http'; 8 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 9 | import { FlexLayoutModule } from '@angular/flex-layout'; 10 | import { RouterModule } from '@angular/router'; 11 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 12 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 13 | import { 14 | MatButtonModule, 15 | MatCardModule, 16 | MatFormFieldModule, 17 | MatIconModule, 18 | MatInputModule, 19 | MatRadioModule, 20 | MatSelectModule, 21 | MatSidenavModule, 22 | MatToolbarModule, 23 | } from '@angular/material'; 24 | import { HomeComponent } from '../home/home.component'; 25 | import { AddBookmarkComponent } from '../add-bookmark/add-bookmark.component'; 26 | import { HttpClientTestingModule } from '@angular/common/http/testing'; 27 | import { StoreModule } from '@ngrx/store'; 28 | import { reducers } from '../reducers'; 29 | import { EffectsModule } from '@ngrx/effects'; 30 | import { BookmarkEffects } from '../store/bookmark.effects'; 31 | import { REST_API } from '../shared/constant'; 32 | 33 | describe('BookmarkComponent', () => { 34 | let component: BookmarkComponent; 35 | let fixture: ComponentFixture; 36 | let httpClient: HttpClient; 37 | 38 | beforeEach(async(() => { 39 | TestBed.configureTestingModule({ 40 | imports: [ 41 | RouterTestingModule, 42 | BrowserModule, 43 | AppRoutingModule, 44 | HttpClientModule, 45 | MatSidenavModule, 46 | MatToolbarModule, 47 | MatCardModule, 48 | BrowserAnimationsModule, 49 | FlexLayoutModule, 50 | MatRadioModule, 51 | MatIconModule, 52 | MatButtonModule, 53 | MatFormFieldModule, 54 | MatInputModule, 55 | MatSelectModule, 56 | RouterModule, 57 | ReactiveFormsModule, 58 | FormsModule, 59 | HttpClientTestingModule, 60 | StoreModule.forRoot({ ...reducers }), 61 | EffectsModule.forRoot([BookmarkEffects]), 62 | ], 63 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 64 | declarations: [HomeComponent, AddBookmarkComponent, BookmarkComponent], 65 | }).compileComponents(); 66 | })); 67 | 68 | beforeEach(() => { 69 | httpClient = TestBed.get(HttpClient); 70 | fixture = TestBed.createComponent(BookmarkComponent); 71 | component = fixture.componentInstance; 72 | fixture.detectChanges(); 73 | }); 74 | 75 | it('should create', () => { 76 | expect(component).toBeTruthy(); 77 | }); 78 | 79 | // Click on Delete Button, trigger the Delete Rest API, using state,action, effect 80 | it('should delete trigger Rest Delete API', fakeAsync(() => { 81 | // spy on http delete method to validate how it is being called 82 | spyOn(httpClient, 'delete').and.callThrough(); 83 | 84 | // test data prepare 85 | const mockBookmark = { 86 | id: '123', 87 | name: 'travel tour', 88 | url: 'travel.com', 89 | group: 'travel', 90 | }; 91 | component.filteredBookmarks = [mockBookmark]; 92 | fixture.detectChanges(); 93 | 94 | const deleteButton = fixture.nativeElement.querySelector('button'); 95 | // trigger delete action 96 | deleteButton.click(); 97 | tick(); 98 | expect(component).toBeTruthy(); 99 | 100 | // validate http delete method is called or not 101 | expect(httpClient.delete).toHaveBeenCalled(); 102 | expect(httpClient.delete).toHaveBeenCalledWith(REST_API + '/' + mockBookmark.id); 103 | })); 104 | 105 | it('should show array of bookmark ', fakeAsync(() => { 106 | // test data prepare 107 | const mockBookmark = { 108 | id: '123', 109 | name: 'travel tour', 110 | url: 'travel.com', 111 | group: 'travel', 112 | }; 113 | component.filteredBookmarks = [mockBookmark, mockBookmark]; 114 | fixture.detectChanges(); 115 | 116 | const deleteButtons = fixture.nativeElement.querySelectorAll('button'); 117 | 118 | // total no of records on Tables must match with Array of data 119 | expect(deleteButtons.length).toEqual(component.filteredBookmarks.length); 120 | })); 121 | }); 122 | -------------------------------------------------------------------------------- /src/app/add-bookmark/add-bookmark.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; 2 | 3 | import { AddBookmarkComponent } from './add-bookmark.component'; 4 | import { 5 | MatButtonModule, 6 | MatCardModule, 7 | MatFormFieldModule, 8 | MatIconModule, 9 | MatInputModule, 10 | MatRadioModule, 11 | MatSelectModule, 12 | MatSidenavModule, 13 | MatToolbarModule, 14 | } from '@angular/material'; 15 | import { BrowserModule } from '@angular/platform-browser'; 16 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 17 | import { FlexLayoutModule } from '@angular/flex-layout'; 18 | import { MatOptionModule } from '@angular/material/core'; 19 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 20 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 21 | import { MockStore } from '@ngrx/store/testing'; 22 | import { HttpClientTestingModule } from '@angular/common/http/testing'; 23 | import { RouterTestingModule } from '@angular/router/testing'; 24 | import { Location } from '@angular/common'; 25 | import { Router } from '@angular/router'; 26 | import { routes } from '../app-routing.module'; 27 | import { HomeComponent } from '../home/home.component'; 28 | import { Store, StoreModule } from '@ngrx/store'; 29 | import * as fromBm from '../store/bookmark.reducer'; 30 | import { reducers } from '../reducers'; 31 | import { EffectsModule } from '@ngrx/effects'; 32 | import { BookmarkEffects } from '../store/bookmark.effects'; 33 | import { BookmarkService } from '../service/bookmark.service'; 34 | import { HttpClient } from '@angular/common/http'; 35 | import { REST_API } from '../shared/constant'; 36 | 37 | describe('AddBookmarkComponent', () => { 38 | let addBookmarkComponent: AddBookmarkComponent; 39 | let fixture: ComponentFixture; 40 | let location: Location; 41 | let router: Router; 42 | let store: MockStore; 43 | let bookmarkService: BookmarkService; 44 | let httpClient: HttpClient; 45 | 46 | beforeEach(fakeAsync(() => { 47 | TestBed.configureTestingModule({ 48 | imports: [ 49 | BrowserModule, 50 | MatSidenavModule, 51 | RouterTestingModule.withRoutes(routes), 52 | MatToolbarModule, 53 | MatCardModule, 54 | BrowserAnimationsModule, 55 | FlexLayoutModule, 56 | MatRadioModule, 57 | MatIconModule, 58 | MatButtonModule, 59 | MatFormFieldModule, 60 | MatInputModule, 61 | MatOptionModule, 62 | MatSelectModule, 63 | ReactiveFormsModule, 64 | FormsModule, 65 | HttpClientTestingModule, 66 | StoreModule.forRoot({ ...reducers }), 67 | EffectsModule.forRoot([BookmarkEffects]), 68 | ], 69 | schemas: [CUSTOM_ELEMENTS_SCHEMA], 70 | declarations: [HomeComponent, AddBookmarkComponent], 71 | providers: [BookmarkService], 72 | }).compileComponents(); 73 | 74 | bookmarkService = TestBed.get(BookmarkService); 75 | httpClient = TestBed.get(HttpClient); 76 | router = TestBed.get(Router); 77 | location = TestBed.get(Location); 78 | store = TestBed.get(Store); 79 | 80 | fixture = TestBed.createComponent(AddBookmarkComponent); 81 | router.initialNavigation(); 82 | addBookmarkComponent = fixture.componentInstance; 83 | 84 | fixture.detectChanges(); 85 | 86 | // spying on methods 87 | spyOn(httpClient, 'post').and.callThrough(); 88 | spyOn(bookmarkService, 'createBookmark').and.callThrough(); 89 | 90 | tick(); 91 | })); 92 | 93 | /** 94 | * It process the from frontend till http post method is called. Pass thru all stages like Action,State,Service 95 | * This case makes sure that, when an action is trigger on Frontend button, it goes thru all steps and call Http Post method 96 | */ 97 | it(`Should have called http Post method with valid data`, fakeAsync(() => { 98 | fixture.ngZone.run(() => {}); 99 | 100 | const mockBookmark = { 101 | id: '', 102 | name: 'travel story', 103 | url: 'www.travel.com', 104 | group: 'travel', 105 | }; 106 | // set the for component fields 107 | addBookmarkComponent.bookmarkName.patchValue(mockBookmark.name); 108 | addBookmarkComponent.bookmarkUrl.patchValue(mockBookmark.url); 109 | addBookmarkComponent.bookmarkGroup.patchValue(mockBookmark.group); 110 | 111 | // trigger the Event/operation 112 | addBookmarkComponent.createBookmark(); 113 | tick(); 114 | 115 | // validate that bookmarkService method is called as expected with valid data 116 | expect(bookmarkService.createBookmark).toHaveBeenCalled(); 117 | expect(bookmarkService.createBookmark).toHaveBeenCalledWith(mockBookmark); 118 | 119 | // validate that http post method is called as expected with valid data 120 | expect(httpClient.post).toHaveBeenCalled(); 121 | expect(httpClient.post).toHaveBeenCalledWith(REST_API, mockBookmark); 122 | 123 | expect(location.path()).toBe('/'); 124 | })); 125 | }); 126 | --------------------------------------------------------------------------------