├── src ├── assets │ ├── .gitkeep │ ├── imgs │ │ ├── heme.jpg │ │ ├── logo.png │ │ ├── plates-header.jpg │ │ ├── mashiko-yaki-saucer.jpg │ │ ├── blue-stripe-stoneware-plate.jpg │ │ ├── hand-painted-blue-flat-dish.jpg │ │ ├── mashiko-yaki-green-small-plate.jpg │ │ └── mashiko-yaki-indigo-small-plate.jpg │ ├── mock-data │ │ └── products.json │ └── css │ │ └── styles.css ├── app │ ├── app.component.css │ ├── app.component.html │ ├── model │ │ ├── cart.ts │ │ └── product.ts │ ├── app.component.ts │ ├── pages │ │ ├── cart │ │ │ ├── cart-page.routes.ts │ │ │ ├── cart-page.module.ts │ │ │ ├── cart-page.component.ts │ │ │ ├── cart-base.component.ts │ │ │ ├── cart-popup │ │ │ │ ├── cart-popup.component.ts │ │ │ │ ├── cart-popup.component.html │ │ │ │ └── cart-popup.component.css │ │ │ ├── cart.component.spec.ts │ │ │ ├── cart-page.component.html │ │ │ └── cart-page.component.css │ │ ├── product │ │ │ ├── product.routes.ts │ │ │ ├── product.module.ts │ │ │ ├── product.component.html │ │ │ ├── product.component.ts │ │ │ ├── product.component.css │ │ │ └── product.component.spec.ts │ │ └── category │ │ │ ├── category.routes.ts │ │ │ ├── category.module.ts │ │ │ ├── category.component.ts │ │ │ ├── category.component.html │ │ │ ├── category.component.spec.ts │ │ │ └── category.component.css │ ├── services │ │ ├── products.service.ts │ │ └── cart.service.ts │ ├── shared │ │ └── shared.module.ts │ ├── app.routes.ts │ ├── components │ │ ├── topbar │ │ │ ├── top-bar.component.css │ │ │ └── topbar.component.ts │ │ └── quantity-control │ │ │ └── quantity-control.component.ts │ └── app.module.ts ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── typings.d.ts ├── tsconfig.app.json ├── index.html ├── main.ts ├── tsconfig.spec.json ├── test.ts └── polyfills.ts ├── screenshot.png ├── .editorconfig ├── e2e ├── tsconfig.e2e.json ├── app.po.ts └── app.e2e-spec.ts ├── tsconfig.json ├── .gitignore ├── protractor.conf.js ├── karma.conf.js ├── package.json ├── .angular-cli.json ├── README.md └── tslint.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/screenshot.png -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/assets/imgs/heme.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/heme.jpg -------------------------------------------------------------------------------- /src/assets/imgs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/logo.png -------------------------------------------------------------------------------- /src/assets/imgs/plates-header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/plates-header.jpg -------------------------------------------------------------------------------- /src/assets/imgs/mashiko-yaki-saucer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/mashiko-yaki-saucer.jpg -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/assets/imgs/blue-stripe-stoneware-plate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/blue-stripe-stoneware-plate.jpg -------------------------------------------------------------------------------- /src/assets/imgs/hand-painted-blue-flat-dish.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/hand-painted-blue-flat-dish.jpg -------------------------------------------------------------------------------- /src/assets/imgs/mashiko-yaki-green-small-plate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/mashiko-yaki-green-small-plate.jpg -------------------------------------------------------------------------------- /src/assets/imgs/mashiko-yaki-indigo-small-plate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-yangy/online-store/HEAD/src/assets/imgs/mashiko-yaki-indigo-small-plate.jpg -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 |
-------------------------------------------------------------------------------- /src/app/model/cart.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Andrew on 7/30/2017. 3 | */ 4 | import {Product} from "./product"; 5 | 6 | export class Cart { 7 | product:Product; 8 | quantity:number; 9 | } -------------------------------------------------------------------------------- /src/app/model/product.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | export class Product { 5 | title: string; 6 | brand?: string; 7 | price?: number; 8 | description?: string; 9 | image?: string 10 | } -------------------------------------------------------------------------------- /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 | } 10 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-page.routes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | import {CartPageComponent} from "./cart-page.component"; 5 | 6 | export const cartPageRoutes=[ 7 | { 8 | path:'', 9 | component:CartPageComponent 10 | }, 11 | ]; -------------------------------------------------------------------------------- /src/app/pages/product/product.routes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | import {ProductComponent} from "./product.component"; 5 | 6 | export const productRoutes=[ 7 | { 8 | path:':id', 9 | component:ProductComponent 10 | }, 11 | ]; -------------------------------------------------------------------------------- /src/app/pages/category/category.routes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | import {CategoryComponent} from "./category.component"; 5 | 6 | export const categoryRoutes=[ 7 | { 8 | path:'', 9 | component:CategoryComponent 10 | }, 11 | ]; -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | OnlineStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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().bootstrapModule(AppModule); 12 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class OnlineStorePage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | navigateToProduct() { 8 | return browser.get('/product/1'); 9 | } 10 | navigateToCart() { 11 | return browser.get('/cart'); 12 | } 13 | getParagraphText() { 14 | return element(by.css('app-root h1')).getText(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2016", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/app/services/products.service.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | 5 | import {Injectable} from "@angular/core"; 6 | import {Http,Response} from "@angular/http"; 7 | import {Observable} from "rxjs"; 8 | 9 | @Injectable() 10 | export class ProductService { 11 | 12 | constructor(public http: Http) { } 13 | 14 | public getProducts(dataURL:string){ 15 | return this.http.get(dataURL) 16 | .map((res:Response) => res.json()) 17 | .catch((error:any) => Observable.throw(error || 'Server error')); 18 | } 19 | } -------------------------------------------------------------------------------- /src/app/pages/category/category.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | import {NgModule} from "@angular/core"; 5 | import {RouterModule} from "@angular/router"; 6 | import {categoryRoutes} from "./category.routes"; 7 | import {SharedModule} from "../../shared/shared.module"; 8 | import {CategoryComponent} from "./category.component"; 9 | @NgModule({ 10 | imports: [ 11 | SharedModule, 12 | RouterModule.forChild(categoryRoutes) 13 | ], 14 | declarations: [ 15 | CategoryComponent 16 | ] 17 | }) 18 | export class CategoryModule { } -------------------------------------------------------------------------------- /src/app/pages/product/product.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | import {NgModule} from "@angular/core"; 5 | import {RouterModule} from "@angular/router"; 6 | import { productRoutes} from "./product.routes"; 7 | import {SharedModule} from "../../shared/shared.module"; 8 | import {ProductComponent} from "./product.component"; 9 | 10 | @NgModule({ 11 | imports: [ 12 | SharedModule, 13 | RouterModule.forChild(productRoutes) 14 | ], 15 | declarations: [ 16 | ProductComponent 17 | ] 18 | }) 19 | export class ProductModule { } -------------------------------------------------------------------------------- /src/app/pages/cart/cart-page.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/31/2017. 3 | */ 4 | 5 | import {NgModule} from "@angular/core"; 6 | import {SharedModule} from "../../shared/shared.module"; 7 | import {RouterModule} from "@angular/router"; 8 | import {CartPageComponent} from "./cart-page.component"; 9 | import {cartPageRoutes} from "./cart-page.routes"; 10 | @NgModule({ 11 | imports: [ 12 | SharedModule, 13 | RouterModule.forChild(cartPageRoutes) 14 | ], 15 | declarations: [ 16 | CartPageComponent 17 | ] 18 | }) 19 | export class CartPageModule { } -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | 5 | import {NgModule} from "@angular/core"; 6 | import {CommonModule} from "@angular/common"; 7 | import {FormsModule} from "@angular/forms"; 8 | import {QuantityControlComponent} from "../components/quantity-control/quantity-control.component"; 9 | @NgModule({ 10 | imports:[ 11 | CommonModule, 12 | FormsModule, 13 | ], 14 | declarations:[ 15 | QuantityControlComponent 16 | ], 17 | exports:[ 18 | CommonModule, 19 | FormsModule, 20 | QuantityControlComponent 21 | ] 22 | }) 23 | 24 | export class SharedModule { 25 | 26 | } -------------------------------------------------------------------------------- /src/app/app.routes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/27/2017. 3 | */ 4 | export const appRoutes=[ 5 | { 6 | path:'', 7 | redirectTo:'category', 8 | pathMatch:'full' 9 | }, 10 | { 11 | path:'category', 12 | loadChildren:'./pages/category/category.module#CategoryModule' 13 | }, 14 | { 15 | path:'product', 16 | loadChildren:'./pages/product/product.module#ProductModule' 17 | }, 18 | { 19 | path:'cart', 20 | loadChildren:'./pages/cart/cart-page.module#CartPageModule' 21 | }, 22 | { 23 | path:'**', 24 | loadChildren:'./pages/category/category.module#CategoryModule' 25 | } 26 | ]; -------------------------------------------------------------------------------- /.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 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-page.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/31/2017. 3 | */ 4 | import { Component } from '@angular/core'; 5 | import {CartBaseComponent} from "./cart-base.component"; 6 | import {CartService} from "../../services/cart.service"; 7 | 8 | @Component({ 9 | selector: 'app-cart-page', 10 | styleUrls: ["cart-page.component.css"], 11 | templateUrl: 'cart-page.component.html' 12 | }) 13 | export class CartPageComponent extends CartBaseComponent{ 14 | constructor(protected cartService: CartService,) { 15 | super(cartService); 16 | } 17 | 18 | ngOnInit() { 19 | 20 | } 21 | changeQuantity = (cart,quantity) => { 22 | cart.quantity = quantity; 23 | this.cartService.reloadCart(this.cartList); 24 | } 25 | } -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-base.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Andrew on 7/30/2017. 3 | */ 4 | import {CartService} from "../../services/cart.service"; 5 | import {Cart} from "../../model/cart"; 6 | export class CartBaseComponent{ 7 | public cartList:Cart[]; 8 | public totalPrice: number; 9 | constructor(protected cartService: CartService) { 10 | this.loadCart(); 11 | } 12 | loadCart = () => { 13 | this.cartService.cartListSubject 14 | .subscribe(res => { 15 | this.cartList = res; 16 | let total = 0; 17 | for(let cart of this.cartList) { 18 | total += cart.product.price * cart.quantity; 19 | } 20 | this.totalPrice = total; 21 | }) 22 | }; 23 | removeFromCart = index => { 24 | this.cartService.removeCart(index); 25 | }; 26 | } -------------------------------------------------------------------------------- /src/app/components/topbar/top-bar.component.css: -------------------------------------------------------------------------------- 1 | @media screen and (min-width: 768px) { 2 | .compare-bar-content { 3 | text-align: center 4 | } 5 | .header-logo-wrapper { 6 | text-align: left 7 | } 8 | .header-mobile-nav-wrapper { 9 | display: none 10 | } 11 | .mobil-shopping-cart { 12 | display: none 13 | } 14 | } 15 | @media screen and (max-width: 767px) { 16 | .header-nav-wrapper { 17 | display: none 18 | } 19 | .mobile-header-nav li { 20 | display: block; 21 | line-height: 30px; 22 | } 23 | .header-logo-wrapper { 24 | display: table-cell; 25 | text-align: center; 26 | vertical-align: top; 27 | } 28 | .header-mobile-nav-wrapper { 29 | display: table-cell; 30 | float:left; 31 | } 32 | .header-cart-item { 33 | display: none 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 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/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { AppComponent } from './app.component'; 4 | import {HttpModule} from "@angular/http"; 5 | import {FormsModule} from "@angular/forms"; 6 | import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; 7 | import {RouterModule} from "@angular/router"; 8 | import {appRoutes} from "./app.routes"; 9 | import {TopbarComponent} from "./components/topbar/topbar.component"; 10 | import {CartService} from "./services/cart.service"; 11 | import {CartPopupComponent} from "./pages/cart/cart-popup/cart-popup.component"; 12 | import {ProductService} from "./services/products.service"; 13 | 14 | @NgModule({ 15 | declarations: [ 16 | AppComponent, 17 | TopbarComponent, 18 | CartPopupComponent 19 | ], 20 | imports: [ 21 | BrowserAnimationsModule, 22 | BrowserModule, 23 | FormsModule, 24 | HttpModule, 25 | RouterModule.forRoot(appRoutes) 26 | ], 27 | providers: [CartService,ProductService], 28 | bootstrap: [AppComponent] 29 | }) 30 | export class AppModule { } 31 | -------------------------------------------------------------------------------- /src/app/services/cart.service.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/28/2017. 3 | */ 4 | import { Injectable } from '@angular/core'; 5 | import {BehaviorSubject} from "rxjs"; 6 | import {Product} from "../model/product"; 7 | import {Cart} from "../model/cart"; 8 | 9 | @Injectable() 10 | export class CartService { 11 | 12 | public cartListSubject = new BehaviorSubject([]); 13 | public toggleCartSubject = new BehaviorSubject(false); 14 | 15 | toggleCart = () => { 16 | this.toggleCartSubject.next(!this.toggleCartSubject.getValue()); 17 | }; 18 | addToCart = (cart:Cart) => { 19 | let current = this.cartListSubject.getValue(); 20 | let dup = current.find(c=>c.product.title === cart.product.title); 21 | if(dup) dup.quantity += cart.quantity; 22 | else current.push(cart); 23 | this.cartListSubject.next(current); 24 | }; 25 | reloadCart = (cartList) => { 26 | this.cartListSubject.next(cartList); 27 | }; 28 | removeCart = index => { 29 | let current = this.cartListSubject.getValue(); 30 | current.splice(index,1); 31 | this.cartListSubject.next(current); 32 | }; 33 | } -------------------------------------------------------------------------------- /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/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /src/app/pages/category/category.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import {ProductService} from "../../services/products.service"; 3 | import {Product} from "../../model/product"; 4 | import {CartService} from "../../services/cart.service"; 5 | import {Router} from "@angular/router"; 6 | 7 | @Component({ 8 | selector: 'app-category', 9 | templateUrl: './category.component.html', 10 | styleUrls: ['./category.component.css'] 11 | }) 12 | export class CategoryComponent implements OnInit { 13 | public products:Array; 14 | private sub; 15 | constructor( 16 | private productService:ProductService, 17 | private cartService:CartService, 18 | private router: Router 19 | ) { } 20 | 21 | ngOnInit() { 22 | this.load(); 23 | } 24 | load = () => { 25 | this.sub = this.productService.getProducts('./assets/mock-data/products.json') 26 | .subscribe(res => { 27 | this.products = res; 28 | }) 29 | }; 30 | addToCart = (product) => { 31 | this.cartService.addToCart({product,quantity:1}) 32 | }; 33 | ngOnDestroy() { 34 | this.sub.unsubscribe(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-popup/cart-popup.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/28/2017. 3 | */ 4 | 5 | import {Component, HostBinding, ElementRef} from "@angular/core"; 6 | import {CartService} from "../../../services/cart.service"; 7 | import {CartBaseComponent} from "../cart-base.component"; 8 | 9 | @Component({ 10 | selector: 'cart-popup', 11 | styleUrls: ["cart-popup.component.css"], 12 | templateUrl: 'cart-popup.component.html', 13 | host: { 14 | '(document:click)': 'onPageClick($event)', 15 | } 16 | }) 17 | export class CartPopupComponent extends CartBaseComponent{ 18 | @HostBinding("class.visible") isVisible:boolean = false; 19 | 20 | constructor( 21 | protected cartService: CartService, 22 | private eleref: ElementRef 23 | ) { 24 | super(cartService); 25 | } 26 | ngOnInit() { 27 | this.cartService.toggleCartSubject.subscribe(res => { 28 | this.isVisible = res; 29 | }); 30 | } 31 | onPageClick = (event) => { 32 | if (this.isVisible && !this.eleref.nativeElement.contains(event.target) && event.target.className !== 'cart-remove'){ 33 | this.cartService.toggleCart(); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/app/pages/product/product.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
    4 | 5 | 6 | 7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
{{product.brand}}
15 |

{{product.title}}

16 |
{{product.price | currency :'USD':true }}
17 |
{{product.description}}
18 |
19 |
20 | 21 |
Add to cart
22 |
23 |
24 |
25 |
26 |
-------------------------------------------------------------------------------- /src/app/pages/product/product.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import {ActivatedRoute} from "@angular/router"; 3 | import {ProductService} from "../../services/products.service"; 4 | import {Product} from "../../model/product"; 5 | import {CartService} from "../../services/cart.service"; 6 | 7 | @Component({ 8 | selector: 'app-product', 9 | templateUrl: './product.component.html', 10 | styleUrls: ['./product.component.css'] 11 | }) 12 | export class ProductComponent implements OnInit { 13 | private sub; 14 | public product:Product; 15 | quantity: number = 1; 16 | constructor(private route: ActivatedRoute, 17 | private productService:ProductService, 18 | private cartService:CartService 19 | ) { } 20 | 21 | ngOnInit() { 22 | this.route.params 23 | .subscribe(res => { 24 | this.getProduct(res.id); 25 | }) 26 | } 27 | getProduct = (id) => { 28 | this.sub = this.productService.getProducts('./assets/mock-data/products.json') 29 | .subscribe(res => { 30 | this.product = res[id-1]; 31 | }) 32 | }; 33 | changeQuantity = (newQuantity:number) => { 34 | this.quantity = newQuantity; 35 | }; 36 | addToCart = (product) => { 37 | if(this.quantity) this.cartService.addToCart({product,quantity:this.quantity}) 38 | }; 39 | ngOnDestroy() { 40 | this.sub.unsubscribe(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/app/pages/category/category.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
Plates
5 |

6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras nec mollis sem. Etiam id luctus libero. 7 | Vivamus vulputate urna eget velit iaculis, et interdum elit pellentesque. Duis porta nunc neque, nec volutpat erat lacinia a. 8 |

9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
View Details
19 |
Add To Cart
20 |
21 |
22 |
23 |
{{product.brand}}
24 |
{{product.title}}
25 |
{{product.price | currency :'USD':true }}
26 |
27 |
28 |
29 |
-------------------------------------------------------------------------------- /src/app/pages/product/product.component.css: -------------------------------------------------------------------------------- 1 | .product-page { 2 | width: 100%; 3 | } 4 | .product-page-container { 5 | max-width: 1140px; 6 | text-align: center; 7 | padding: 0 30px; 8 | margin: auto; 9 | } 10 | .product-breadcrumbs { 11 | padding: 30px 0; 12 | } 13 | .product-breadcrumbs li{ 14 | display: inline-block; 15 | letter-spacing: .1em; 16 | font-weight: 700; 17 | text-transform: uppercase; 18 | font-size: .85em; 19 | } 20 | .product-breadcrumbs li a { 21 | color: #4a4a4a; 22 | } 23 | .product-breadcrumbs li:last-child{ 24 | opacity: 0.5; 25 | } 26 | 27 | .product-details-image { 28 | width: 95%; 29 | padding-top: 63.3%; 30 | background-position: 50% 50%; 31 | background-repeat: no-repeat; 32 | background-size: cover; 33 | } 34 | 35 | @media screen and (max-width: 992px) { 36 | .product-details-image { 37 | width: 100%; 38 | padding-top: 66.6%; 39 | } 40 | } 41 | .product-brand { 42 | color: #7d7d7d; 43 | } 44 | .product-title { 45 | margin:15px 0; 46 | font-size:2.5em; 47 | font-weight: 400; 48 | font-family: "Playfair Display"; 49 | } 50 | .product-price { 51 | color:#9f9f9f; 52 | font-family: "Playfair Display"; 53 | font-size:20px; 54 | } 55 | .product-description { 56 | color: #7d7d7d; 57 | margin:10px 0 30px 0; 58 | } 59 | .product-details-button { 60 | padding:25px 0; 61 | border-top: 1px solid #e4e4e4; 62 | text-align: center; 63 | } 64 | .product-cart-button { 65 | vertical-align: top; 66 | margin-left:5px 67 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "online-store", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^4.0.0", 16 | "@angular/common": "^4.0.0", 17 | "@angular/compiler": "^4.0.0", 18 | "@angular/core": "^4.0.0", 19 | "@angular/forms": "^4.0.0", 20 | "@angular/http": "^4.0.0", 21 | "@angular/platform-browser": "^4.0.0", 22 | "@angular/platform-browser-dynamic": "^4.0.0", 23 | "@angular/router": "^4.0.0", 24 | "bootstrap": "^3.3.7", 25 | "core-js": "^2.4.1", 26 | "font-awesome": "^4.7.0", 27 | "rxjs": "^5.4.1", 28 | "zone.js": "^0.8.14" 29 | }, 30 | "devDependencies": { 31 | "@angular/cli": "1.2.5", 32 | "@angular/compiler-cli": "^4.0.0", 33 | "@angular/language-service": "^4.0.0", 34 | "@types/jasmine": "~2.5.53", 35 | "@types/jasminewd2": "~2.0.2", 36 | "@types/node": "~6.0.60", 37 | "codelyzer": "~3.0.1", 38 | "jasmine-core": "~2.6.2", 39 | "jasmine-spec-reporter": "~4.1.0", 40 | "karma": "~1.7.0", 41 | "karma-chrome-launcher": "~2.1.1", 42 | "karma-cli": "~1.0.1", 43 | "karma-coverage-istanbul-reporter": "^1.2.1", 44 | "karma-jasmine": "~1.1.0", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.1.2", 47 | "ts-node": "~3.0.4", 48 | "tslint": "~5.3.2", 49 | "typescript": "~2.3.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "online-store" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "../node_modules/bootstrap/dist/css/bootstrap.min.css", 23 | "../node_modules/font-awesome/css/font-awesome.min.css", 24 | "assets/css/styles.css" 25 | ], 26 | "scripts": [], 27 | "environmentSource": "environments/environment.ts", 28 | "environments": { 29 | "dev": "environments/environment.ts", 30 | "prod": "environments/environment.prod.ts" 31 | } 32 | } 33 | ], 34 | "e2e": { 35 | "protractor": { 36 | "config": "./protractor.conf.js" 37 | } 38 | }, 39 | "lint": [ 40 | { 41 | "project": "src/tsconfig.app.json", 42 | "exclude": "**/node_modules/**" 43 | }, 44 | { 45 | "project": "src/tsconfig.spec.json", 46 | "exclude": "**/node_modules/**" 47 | }, 48 | { 49 | "project": "e2e/tsconfig.e2e.json", 50 | "exclude": "**/node_modules/**" 51 | } 52 | ], 53 | "test": { 54 | "karma": { 55 | "config": "./karma.conf.js" 56 | } 57 | }, 58 | "defaults": { 59 | "styleExt": "css", 60 | "component": {} 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-popup/cart-popup.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 5 | 6 |
7 |
8 |

9 | {{cart.product.title}} × {{cart.quantity}} 10 |

11 | 12 | {{cart.product.brand}} 13 | 14 | 15 | {{cart.product.price | currency :'USD':true }} 16 | 17 |
18 |
19 | X 20 |
21 |
22 |
23 |
24 |
25 | 26 | Total 27 | 28 | 29 | {{totalPrice | currency :'USD':true }} 30 | 31 |
32 |
33 |
34 | 37 | 38 | 41 |
42 |
43 |
44 | Your cart is empty 45 |
46 | 47 | -------------------------------------------------------------------------------- /src/assets/mock-data/products.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "title": "Blue Stripe Stoneware Plate", 4 | "brand": "Kiriko", 5 | "price": 40, 6 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget.", 7 | "image": "blue-stripe-stoneware-plate.jpg" 8 | }, 9 | { 10 | "title": "Hand Painted Blue Flat Dish", 11 | "brand": "Kiriko", 12 | "price": 28, 13 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget arcu. Curabitur ac pharetra nisl, sit amet mattis dolor.", 14 | "image": "hand-painted-blue-flat-dish.jpg" 15 | }, 16 | { 17 | "title": "Heme", 18 | "brand": "Dust & Form", 19 | "price": 52, 20 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget arcu. Curabitur ac pharetra nisl, sit amet mattis dolor.", 21 | "image": "heme.jpg" 22 | }, 23 | { 24 | "title": "Mashiko-Yaki Green Small Plate", 25 | "brand": "Kiriko", 26 | "price": 28, 27 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget.", 28 | "image": "mashiko-yaki-green-small-plate.jpg" 29 | }, 30 | { 31 | "title": "Mashiko-Yaki Indigo Small Plate", 32 | "brand": "Kiriko", 33 | "price": 28, 34 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget.", 35 | "image": "mashiko-yaki-indigo-small-plate.jpg" 36 | }, 37 | { 38 | "title": "Mashiko-Yaki Saucer", 39 | "brand": "Kiriko", 40 | "price": 18, 41 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at purus pulvinar, placerat turpis ac, interdum metus. In eget massa sed enim hendrerit auctor a eget.", 42 | "image": "mashiko-yaki-saucer.jpg" 43 | } 44 | ] 45 | -------------------------------------------------------------------------------- /src/app/components/quantity-control/quantity-control.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/31/2017. 3 | */ 4 | import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; 5 | 6 | @Component({ 7 | selector: 'quantity-control', 8 | styles: [` 9 | :host { 10 | height: 58px; 11 | display: inline-block; 12 | } 13 | .number, 14 | .actions { 15 | height: 58px; 16 | width: 50px; 17 | float: left; 18 | } 19 | .input-style { 20 | text-align: center; 21 | width:50px; 22 | line-height: 58px; 23 | background: #eee; 24 | color:#7b7b7b; 25 | border: 0; 26 | } 27 | .actions { 28 | margin-left: 2px; 29 | width: 29px; 30 | } 31 | .actions div { 32 | height: 29px; 33 | width: 29px; 34 | line-height: 29px; 35 | background: #dadada; 36 | font-weight: bold; 37 | color: #7d7d7d; 38 | text-align: center; 39 | } 40 | .actions div:first-child { 41 | margin-bottom: 2px; 42 | } 43 | .actions div:hover { 44 | cursor: pointer; 45 | background: #333; 46 | color: white; 47 | } 48 | .noselect { 49 | -webkit-touch-callout: none; 50 | -webkit-user-select: none; 51 | -khtml-user-select: none; 52 | -moz-user-select: none; 53 | -ms-user-select: none; 54 | user-select: none; 55 | } 56 | input[type=number]::-webkit-inner-spin-button, 57 | input[type=number]::-webkit-outer-spin-button { 58 | -webkit-appearance: none; 59 | margin: 0; 60 | } 61 | `], 62 | template: ` 63 |
64 | 65 |
66 |
67 |
+
68 |
-
69 |
70 | ` 71 | }) 72 | export class QuantityControlComponent implements OnInit { 73 | @Input() quantity: number; 74 | @Output() onChange = new EventEmitter(); 75 | constructor() { } 76 | 77 | ngOnInit() { } 78 | plusOne = () =>{ 79 | if (this.quantity < 1000){ 80 | this.quantity++; 81 | this.onChange.emit(this.quantity); 82 | } 83 | }; 84 | minusOne = () => { 85 | if (this.quantity > 1){ 86 | this.quantity--; 87 | this.onChange.emit(this.quantity); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/assets/css/styles.css: -------------------------------------------------------------------------------- 1 | @import url('//fonts.googleapis.com/css?family=Roboto:400,400italic,500,700|Playfair+Display:400,400italic,700,700italic|Montserrat:400|Karla:400'); 2 | body { 3 | font-family: Roboto; 4 | font-size: 14px; 5 | line-height: 1.666; 6 | padding-top:70px; 7 | } 8 | .main-header { 9 | color: #1d1d20; 10 | vertical-align: middle; 11 | display: table; 12 | width: 100%; 13 | background-color: #fff; 14 | } 15 | .main-header .header-menu { 16 | display: table; 17 | width: 100%; 18 | padding: 0 15px; 19 | border-top: 1px solid #fff; 20 | border-bottom: 1px solid #fff; 21 | box-sizing: border-box; 22 | table-layout: fixed; 23 | border-bottom-color: #e4e4e4; 24 | } 25 | .header-nav-wrapper, 26 | .header-cart-wrapper { 27 | display: table-cell; 28 | font-weight: 700; 29 | vertical-align: middle; 30 | } 31 | .header-nav { 32 | display: block; 33 | margin: 0; 34 | text-align: center; 35 | } 36 | .header-nav-item:first-child { 37 | margin-left: 0; 38 | } 39 | .header-cart-item a, 40 | .header-nav-item a { 41 | color:#1d1d20; 42 | font-family: Roboto; 43 | } 44 | .header-nav-item { 45 | display: inline-block; 46 | margin-left: 30px; 47 | position: inherit; 48 | } 49 | .header-cart-item .fa, 50 | .header-nav-item .fa { 51 | margin-top: 1px; 52 | margin-left: 6px; 53 | } 54 | .header-cart { 55 | text-align:right; 56 | margin-right:30px; 57 | } 58 | 59 | .button { 60 | display: inline-block; 61 | padding: 0 30px; 62 | color: white; 63 | text-align: center; 64 | font-size: 0.85em; 65 | font-weight: 600; 66 | letter-spacing: .15rem; 67 | text-transform: uppercase; 68 | text-decoration: none; 69 | white-space: nowrap; 70 | background-color: transparent; 71 | border: 1px solid #3b3d38; 72 | cursor: pointer; 73 | box-sizing: border-box; 74 | } 75 | .button.button-primary { 76 | color: #fff; 77 | background-color: #3b3d38; 78 | border-color: #3b3d38; 79 | } 80 | .button.button-primary:hover { 81 | color: #fff; 82 | background-color: #52525b; 83 | border-color: #52525b; 84 | } 85 | .button.button-secondary { 86 | color: #1d1d20; 87 | background-color: #fff; 88 | border-color: #1d1d20; 89 | } 90 | .button.button-secondary:hover { 91 | color: #fff; 92 | background-color: #8e8e90; 93 | border-color: #8e8e90; 94 | } 95 | .button.button-wide { 96 | width: 100%; 97 | } 98 | .button.button-large { 99 | padding: 19px 22px; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import {Product} from "../../model/product"; 4 | import {SharedModule} from "../../shared/shared.module"; 5 | import {CartService} from "../../services/cart.service"; 6 | import {ProductService} from "../../services/products.service"; 7 | import {BrowserModule} from "@angular/platform-browser"; 8 | import {FormsModule} from "@angular/forms"; 9 | import {RouterTestingModule} from "@angular/router/testing"; 10 | import {HttpModule} from "@angular/http"; 11 | import {CartPageComponent} from "./cart-page.component"; 12 | 13 | describe('Cart Page', () => { 14 | let component: CartPageComponent; 15 | let fixture: ComponentFixture; 16 | let products: Product[]; 17 | 18 | beforeEach(async(() => { 19 | TestBed.configureTestingModule({ 20 | imports: [ 21 | BrowserModule, 22 | FormsModule, 23 | HttpModule, 24 | SharedModule, 25 | RouterTestingModule 26 | ], 27 | declarations: [ 28 | CartPageComponent 29 | ], 30 | providers: [CartService,ProductService], 31 | }) 32 | .compileComponents(); 33 | })); 34 | 35 | beforeEach(() => { 36 | fixture = TestBed.createComponent(CartPageComponent); 37 | component = fixture.componentInstance; 38 | fixture.detectChanges(); 39 | products = [ 40 | { 41 | "title": "1", 42 | "price": 40 43 | }, 44 | { 45 | "title": "2", 46 | "price": 28 47 | } 48 | ]; 49 | }); 50 | 51 | it('change quantity.', () => { 52 | component.cartList = [{product:products[0],quantity:1},{product:products[1],quantity:2}]; 53 | component.changeQuantity(component.cartList[0],2); 54 | expect(component.cartList).toEqual([{product:products[0],quantity:2},{product:products[1],quantity:2}]); 55 | expect(component.totalPrice).toEqual(136); 56 | }); 57 | it('change quantity.', () => { 58 | component.cartList = [{product:products[0],quantity:5},{product:products[1],quantity:2}]; 59 | component.changeQuantity(component.cartList[1],1); 60 | expect(component.cartList).toEqual([{product:products[0],quantity:5},{product:products[1],quantity:1}]); 61 | expect(component.totalPrice).toEqual(228); 62 | }); 63 | it('remove item.', () => { 64 | component.cartList = [{product:products[0],quantity:2},{product:products[1],quantity:2}]; 65 | component.changeQuantity(component.cartList[1],3); 66 | component.removeFromCart(1); 67 | expect(component.cartList).toEqual([{product:products[0],quantity:2}]); 68 | expect(component.totalPrice).toEqual(80); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /src/app/pages/category/category.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryComponent } from './category.component'; 4 | import {Product} from "../../model/product"; 5 | import {Cart} from "../../model/cart"; 6 | import {CartPageComponent} from "../cart/cart-page.component"; 7 | import {SharedModule} from "../../shared/shared.module"; 8 | import {RouterModule} from "@angular/router"; 9 | import {categoryRoutes} from "./category.routes"; 10 | import {CartService} from "../../services/cart.service"; 11 | import {ProductService} from "../../services/products.service"; 12 | import {BrowserModule} from "@angular/platform-browser"; 13 | import {FormsModule} from "@angular/forms"; 14 | import {RouterTestingModule} from "@angular/router/testing"; 15 | import {HttpModule} from "@angular/http"; 16 | 17 | describe('Category Page', () => { 18 | let component: CategoryComponent; 19 | let fixture: ComponentFixture; 20 | let cartPageComponent: CartPageComponent; 21 | let products: Product[]; 22 | 23 | beforeEach(async(() => { 24 | TestBed.configureTestingModule({ 25 | imports: [ 26 | BrowserModule, 27 | FormsModule, 28 | HttpModule, 29 | SharedModule, 30 | RouterTestingModule 31 | ], 32 | declarations: [ 33 | CategoryComponent,CartPageComponent 34 | ], 35 | providers: [CartService,ProductService], 36 | }) 37 | .compileComponents(); 38 | })); 39 | 40 | beforeEach(() => { 41 | fixture = TestBed.createComponent(CategoryComponent); 42 | component = fixture.componentInstance; 43 | fixture.detectChanges(); 44 | let f = TestBed.createComponent(CartPageComponent); 45 | cartPageComponent = f.componentInstance; 46 | f.detectChanges(); 47 | products = [ 48 | { 49 | "title": "1", 50 | "price": 40 51 | }, 52 | { 53 | "title": "2", 54 | "price": 28 55 | } 56 | ]; 57 | }); 58 | 59 | it('test shopping cart, add a duplicate item should increment the quantity for that item.', () => { 60 | component.addToCart(products[0]); 61 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:1}]); 62 | expect(cartPageComponent.totalPrice).toEqual(40); 63 | component.addToCart(products[0]); 64 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:2}]); 65 | expect(cartPageComponent.totalPrice).toEqual(80); 66 | component.addToCart(products[1]); 67 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:2},{product:products[1],quantity:1}]); 68 | expect(cartPageComponent.totalPrice).toEqual(108); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /src/app/pages/category/category.component.css: -------------------------------------------------------------------------------- 1 | .header-image { 2 | height: 400px; 3 | background: url("../../../assets/imgs/plates-header.jpg") no-repeat; 4 | background-size:cover; 5 | background-position: center center; 6 | } 7 | .header-block { 8 | height: 100%; 9 | background-color: #3A3A35; 10 | color:white; 11 | width: 50%; 12 | margin:auto; 13 | border-color:white; 14 | border-style:solid; 15 | border-width: 0 15px; 16 | display:table; 17 | } 18 | .header-text { 19 | text-align: center; 20 | vertical-align: middle; 21 | display: table-cell; 22 | } 23 | .header-text-title { 24 | display: inline-block; 25 | font-size: 30px; 26 | font-weight: 500; 27 | padding-bottom:10px; 28 | border-bottom: 1px solid white; 29 | } 30 | .header-text p { 31 | padding:10px 40px 32 | } 33 | .layout-container { 34 | max-width: 1140px; 35 | padding-right: 30px; 36 | padding-left: 30px; 37 | margin-right: auto; 38 | margin-left: auto; 39 | } 40 | .product-grid { 41 | padding-top: 5%; 42 | padding-bottom: 5%; 43 | } 44 | .product-image { 45 | width: 100%; 46 | height: 0; 47 | padding-bottom: 66.66667%; 48 | background-position: 50% 50%; 49 | background-repeat: no-repeat; 50 | background-size: cover; 51 | } 52 | .image-container { 53 | position: relative; 54 | } 55 | .image-container:hover .product-image{ 56 | opacity: 0.3; 57 | background-size:120%; 58 | } 59 | .image-container:hover .overlay{ 60 | opacity: 1; 61 | } 62 | .overlay { 63 | transition: .5s ease; 64 | opacity: 0; 65 | position: absolute; 66 | top: 50%; 67 | left: 50%; 68 | text-align: center; 69 | transform: translate(-50%, -50%); 70 | -ms-transform: translate(-50%, -50%) 71 | } 72 | .overlay .button { 73 | width: 160px; 74 | line-height: 38px; 75 | } 76 | .overlay .button:first-child { 77 | margin-bottom: 2em; 78 | } 79 | .product-details { 80 | padding-top: 15px; 81 | text-align: center; 82 | margin-bottom: 40px; 83 | } 84 | .product-brand { 85 | display: block; 86 | margin: .5em 0; 87 | color: #7d7d7d; 88 | } 89 | .product-title { 90 | text-transform: uppercase; 91 | letter-spacing: .05em; 92 | margin-top: 0; 93 | margin-bottom: .5em; 94 | font-size: 1em; 95 | line-height: 1.2; 96 | font-weight: 400; 97 | font-family: Roboto; 98 | } 99 | .product-price { 100 | font-size: 1.14286em; 101 | color: #9f9f9f; 102 | font-family: Playfair Display; 103 | } 104 | @media screen and (max-width: 767px) { 105 | .header-block { 106 | width: 100%; 107 | } 108 | } -------------------------------------------------------------------------------- /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/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** Evergreen browsers require these. **/ 41 | import 'core-js/es6/reflect'; 42 | import 'core-js/es7/reflect'; 43 | 44 | 45 | /** 46 | * Required to support Web Animations `@angular/animation`. 47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 48 | **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | /** 70 | * Need to import at least one locale-data with intl. 71 | */ 72 | // import 'intl/locale-data/jsonp/en'; 73 | -------------------------------------------------------------------------------- /src/app/pages/product/product.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ProductComponent } from './product.component'; 4 | import {SharedModule} from "../../shared/shared.module"; 5 | import {ProductService} from "../../services/products.service"; 6 | import {CartService} from "../../services/cart.service"; 7 | import {HttpModule} from "@angular/http"; 8 | import {FormsModule} from "@angular/forms"; 9 | import {BrowserModule} from "@angular/platform-browser"; 10 | import {RouterTestingModule} from "@angular/router/testing"; 11 | import {CartPageComponent} from "../cart/cart-page.component"; 12 | import {Product} from "../../model/product"; 13 | 14 | describe('Product Page, test add to cart button', () => { 15 | let component: ProductComponent; 16 | let fixture: ComponentFixture; 17 | let cartPageComponent: CartPageComponent; 18 | let products: Product[]; 19 | 20 | beforeEach(async(() => { 21 | TestBed.configureTestingModule({ 22 | imports: [ 23 | BrowserModule, 24 | FormsModule, 25 | HttpModule, 26 | SharedModule, 27 | RouterTestingModule 28 | ], 29 | declarations: [ 30 | ProductComponent,CartPageComponent 31 | ], 32 | providers: [CartService,ProductService], 33 | }) 34 | .compileComponents(); 35 | })); 36 | 37 | beforeEach(() => { 38 | fixture = TestBed.createComponent(ProductComponent); 39 | component = fixture.componentInstance; 40 | fixture.detectChanges(); 41 | let f = TestBed.createComponent(CartPageComponent); 42 | cartPageComponent = f.componentInstance; 43 | f.detectChanges(); 44 | products = [ 45 | { 46 | "title": "1", 47 | "price": 40 48 | }, 49 | { 50 | "title": "2", 51 | "price": 28 52 | } 53 | ]; 54 | }); 55 | 56 | it('Add 1 first item.', () => { 57 | component.addToCart(products[0]); 58 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:1}]); 59 | expect(cartPageComponent.totalPrice).toEqual(40); 60 | }); 61 | it('When quantity is null.', () => { 62 | component.quantity = null; 63 | component.addToCart(products[0]); 64 | expect(cartPageComponent.cartList).toEqual([]); 65 | expect(cartPageComponent.totalPrice).toEqual(0); 66 | }); 67 | it('Add duplicate item.', () => { 68 | component.quantity = 2; 69 | component.addToCart(products[0]); 70 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:2}]); 71 | expect(cartPageComponent.totalPrice).toEqual(80); 72 | component.quantity = 3; 73 | component.addToCart(products[0]); 74 | expect(cartPageComponent.cartList).toEqual([{product:products[0],quantity:5}]); 75 | expect(cartPageComponent.totalPrice).toEqual(200); 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OnlineStore 2 | 3 | This is a online store app implemented using Angular 4. 4 | 5 | ## Demo 6 | 7 | Sky Blue 8 | 9 | Live Demo 10 | 11 | ## How to start 12 | 13 | You will need to clone the source code of online-store GitHub repository. 14 | 15 | `git clone https://github.com/ddvkid/online-store.git` 16 | 17 | After the repository is cloned, go inside of the repository directory and install dependencies: 18 | 19 | ``` 20 | cd online-store 21 | npm install 22 | ``` 23 | 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. 24 | 25 | ## Build 26 | 27 | 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. 28 | 29 | ## Running unit tests 30 | 31 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 32 | #### Units to be tested 33 | 1. Category Page 34 | * test shopping cart, add a duplicate item should increment the quantity for that item. 35 | 2. Product Page, test add to cart button 36 | * Add 1 first item. 37 | * When quantity is null. 38 | * Add duplicate item. 39 | 3. Cart Page 40 | * change quantity. 41 | * remove item. 42 | ## Running end-to-end tests 43 | 44 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 45 | Before running the tests make sure you are serving the app via `ng serve`. 46 | #### Scenarios to be tested 47 | * should display 6 products. 48 | * should display cart popup. 49 | * should be able to add product to cart from image hover button. 50 | * should be able to navigate to product page from image hover button. 51 | * should be able to remove product from cart popup. 52 | * should be able to navigate to cart page from cart popup. 53 | * should be able to add product to cart from product page. 54 | * should be able to remove product from cart page. 55 | 56 | ## Notes 57 | #### Why Angular? 58 | Angular is a complete solution for rapid front-end development, get started with Angular using angular cli is easy. And Angular is much easier and faster than AngularJs. 59 | React and Vue can be good options too. 60 | #### Why not redux or mobx? 61 | Actually I think redux and mobx would be better choices when it comes to shopping cart case, however as it is a very simple shopping cart without any backend code, 62 | redux or mobx might make things more complex and reduce the code readability. In the real world project of shopping cart, I would use them to manage data flow. 63 | #### Why not store shopping cart data? 64 | As storing shopping cart information could be complicated and depends on the login system and backend database. 65 | With not signed users, we have to save this data on web storage(Cookie, Session and Local Storage), and with signed users, we need update this 66 | to database. I am not able to implement that without having further information. 67 | #### Why Protractor and Karma 68 | They are in the Angular package, so why not :grin: 69 | -------------------------------------------------------------------------------- /src/app/components/topbar/topbar.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by andrew.yang on 7/28/2017. 3 | */ 4 | import { Component, OnInit } from '@angular/core'; 5 | import {CartService} from "../../services/cart.service"; 6 | 7 | @Component({ 8 | selector: 'top-bar', 9 | styleUrls: ['./top-bar.component.css'], 10 | template: ` 11 | 64 | ` 65 | }) 66 | export class TopbarComponent implements OnInit { 67 | public collapse: boolean = false; 68 | public cart_num:number; 69 | constructor( 70 | private cartService: CartService 71 | ) { } 72 | 73 | ngOnInit() { 74 | this.cartService.cartListSubject 75 | .subscribe(res => { 76 | this.cart_num = res.length; 77 | }) 78 | } 79 | toggleCartPopup = (event) => { 80 | event.preventDefault(); 81 | event.stopPropagation(); 82 | this.cartService.toggleCart() 83 | } 84 | } -------------------------------------------------------------------------------- /src/app/pages/cart/cart-popup/cart-popup.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | width: 400px; 4 | position: absolute; 5 | right: 0; 6 | text-transform: uppercase; 7 | -webkit-box-shadow: 0 2px 3px rgba(128,128,128,.25); 8 | -moz-box-shadow:0 2px 3px rgba(128,128,128,.25); 9 | box-shadow: 0 2px 3px rgba(128,128,128,.25); 10 | background: white; 11 | transition: all .5s cubic-bezier(.25,.46,.45,.94); 12 | top: -1000px; 13 | opacity: 0; 14 | max-height: calc(100vh - 120px); 15 | overflow-y: auto; 16 | } 17 | 18 | :host.visible { 19 | top: 100%; 20 | opacity: 1; 21 | } 22 | .cart-empty { 23 | float:right; 24 | margin-right: 20px; 25 | } 26 | .quick-cart-footer, 27 | .pop-cart-item { 28 | display: table; 29 | border-spacing: 15px 15px; 30 | border-collapse: separate; 31 | box-sizing: border-box; 32 | table-layout: fixed; 33 | width: 100%; 34 | } 35 | .pop-cart-item-image-wrapper { 36 | width: 80px; 37 | display: table-cell; 38 | vertical-align: top; 39 | } 40 | .pop-cart-item-image { 41 | color: #1d1d20; 42 | vertical-align: middle; 43 | display: block; 44 | width: 80px; 45 | height: 80px; 46 | background-position: 50% 50%; 47 | background-repeat: no-repeat; 48 | background-size: cover; 49 | } 50 | .pop-cart-item-details { 51 | display: table-cell; 52 | vertical-align: top; 53 | } 54 | .pop-cart-item-title { 55 | margin: 0; 56 | font-size: 13px; 57 | line-height: 1.2; 58 | text-transform: uppercase; 59 | font-weight: 700; 60 | font-family: Roboto; 61 | } 62 | .pop-cart-item-title a { 63 | color: black; 64 | letter-spacing: .1em; 65 | text-decoration: none; 66 | } 67 | .pop-cart-item-title a:hover { 68 | color: #99999b; 69 | } 70 | .pop-cart-item-quantity { 71 | display: inline-block; 72 | margin-left: 5px; 73 | font-size: .76923em; 74 | font-weight: 400; 75 | } 76 | .pop-cart-item-brand { 77 | display: block; 78 | margin-top: 4px; 79 | margin-bottom: 2px; 80 | font-size: .76923em; 81 | line-height: 1.3; 82 | font-family: Roboto; 83 | letter-spacing: .05em; 84 | color: #9f9f9f; 85 | text-transform: uppercase; 86 | font-weight: 700; 87 | } 88 | .pop-cart-item-price { 89 | display: block; 90 | font-size: .92857em; 91 | font-weight: 700; 92 | } 93 | .pop-cart-remove-wrapper { 94 | width: 18px; 95 | height: 20px; 96 | text-align: center; 97 | display: table-cell; 98 | vertical-align: top; 99 | } 100 | .pop-cart-remove-wrapper span{ 101 | cursor: pointer; 102 | } 103 | .cart-total { 104 | padding: 0 15px; 105 | } 106 | .cart-total-item { 107 | padding-top: 15px; 108 | border-top: 1px solid #e4e4e4; 109 | max-width: 1140px; 110 | margin-left: auto; 111 | margin-right: auto; 112 | font-size: .85714em; 113 | color: #9f9f9f; 114 | font-weight: 400; 115 | letter-spacing: .1em; 116 | } 117 | .cart-total-label { 118 | float: left; 119 | } 120 | .cart-total-value { 121 | float: right; 122 | } 123 | .quick-cart-footer { 124 | display: table; 125 | width: 100%; 126 | border-bottom: 1px solid #e4e4e4; 127 | } 128 | .quick-cart-footer-cell { 129 | display: table-cell; 130 | } -------------------------------------------------------------------------------- /src/app/pages/cart/cart-page.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Shopping Cart

4 |
5 |
6 |
7 |
Product
8 |
Quantity
9 |
Total
10 |
Action
11 |
12 |
13 |
14 |
15 |
16 |
17 |
{{cart.product.brand}}
18 |
{{cart.product.title}}
19 |
20 |
21 |
22 | 23 |
24 |
25 |
26 | {{cart.quantity*cart.product.price | currency :'USD':true }} 27 |
28 |
29 |
30 |
X
31 |
32 |
33 |
34 |
35 |
36 |
37 | Cart overview 38 |
39 |
40 |
41 |
42 |
43 | subtotal 44 |
45 |
46 | {{totalPrice | currency :'USD':true}} 47 |
48 |
49 |
50 |
51 | total 52 |
53 |
54 | {{totalPrice | currency :'USD':true}} AUD 55 |
56 |
57 |
58 |
59 |
60 | 61 |
Checkout ({{totalPrice | currency :'USD':true}})
62 |
63 |
64 |
65 |

Your cart is empty.

66 | Go shopping 67 |
68 |
-------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { OnlineStorePage } from './app.po'; 2 | import {browser, by, element, protractor} from 'protractor'; 3 | let origFn = browser.driver.controlFlow().execute; 4 | 5 | browser.driver.controlFlow().execute = function() { 6 | let args = arguments; 7 | origFn.call(browser.driver.controlFlow(), function() { 8 | return protractor.promise.delayed(100); 9 | }); 10 | return origFn.apply(browser.driver.controlFlow(), args); 11 | }; 12 | describe('online-store App', () => { 13 | let page: OnlineStorePage; 14 | 15 | beforeEach(() => { 16 | page = new OnlineStorePage(); 17 | }); 18 | 19 | it('should display 6 products.', () => { 20 | page.navigateTo(); 21 | let products = element.all(by.css(".image-container")); 22 | expect(products.count()).toEqual(6); 23 | }); 24 | it('should display cart popup.', () => { 25 | page.navigateTo(); 26 | let cartMenu = element(by.css('.header-cart')); 27 | let cartPopup = element(by.tagName("cart-popup")); 28 | cartMenu.click(); 29 | expect(cartPopup.isDisplayed()); 30 | }); 31 | it('should be able to add product to cart from image hover button.', () => { 32 | page.navigateTo(); 33 | let cartButton = element.all(by.cssContainingText('.button','Add To Cart')).first(); 34 | let cartMenu = element(by.css('.header-cart')); 35 | cartButton.click(); 36 | cartMenu.click(); 37 | let cartPopup = element.all(by.css(".pop-cart-item")); 38 | expect(cartPopup.count()).toEqual(1); 39 | }); 40 | it('should be able to navigate to product page from image hover button.', () => { 41 | page.navigateTo(); 42 | let productButton = element.all(by.cssContainingText('.button','View Details')).first(); 43 | productButton.click(); 44 | expect(browser.getCurrentUrl()).toBe('http://localhost:49152/product/1'); 45 | }); 46 | it('should be able to remove product from cart popup.', () => { 47 | page.navigateTo(); 48 | let cartButton = element.all(by.cssContainingText('.button','Add To Cart')).first(); 49 | let cartMenu = element(by.css('.header-cart')); 50 | cartButton.click(); 51 | cartMenu.click(); 52 | let removeButton = element.all(by.css('.cart-remove')); 53 | removeButton.click(); 54 | let cartPopup = element.all(by.css(".pop-cart-item")); 55 | expect(cartPopup.count()).toEqual(0); 56 | }); 57 | it('should be able to navigate to cart page from cart popup.', () => { 58 | page.navigateTo(); 59 | let cartButton = element.all(by.cssContainingText('.button','Add To Cart')).first(); 60 | let cartMenu = element(by.css('.header-cart')); 61 | cartButton.click(); 62 | cartMenu.click(); 63 | let goCartButton = element.all(by.cssContainingText('.button','View Cart')).first(); 64 | goCartButton.click(); 65 | expect(browser.getCurrentUrl()).toEqual('http://localhost:49152/cart'); 66 | }); 67 | it('should be able to add product to cart from product page.', () => { 68 | page.navigateToProduct(); 69 | let cartButton = element(by.cssContainingText('.product-cart-button','Add to cart')); 70 | cartButton.click(); 71 | let cartMenu = element(by.css('.header-cart')); 72 | cartMenu.click(); 73 | let cartPopup = element.all(by.css(".pop-cart-item")); 74 | expect(cartPopup.count()).toEqual(1); 75 | }); 76 | it('should be able to remove product from cart page.', () => { 77 | page.navigateToProduct(); 78 | element(by.cssContainingText('.product-cart-button','Add to cart')).click(); 79 | page.navigateToCart(); 80 | let removeButton = element.all(by.css('.item-remove')); 81 | removeButton.click(); 82 | let cartText = element(by.css(".cart-page-content h4")); 83 | expect(cartText.getText()).toEqual('Your cart is empty.'); 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs" 19 | ], 20 | "import-spacing": true, 21 | "indent": [ 22 | true, 23 | "spaces" 24 | ], 25 | "interface-over-type-literal": true, 26 | "label-position": true, 27 | "max-line-length": [ 28 | true, 29 | 140 30 | ], 31 | "member-access": false, 32 | "member-ordering": [ 33 | true, 34 | { 35 | "order": [ 36 | "static-field", 37 | "instance-field", 38 | "static-method", 39 | "instance-method" 40 | ] 41 | } 42 | ], 43 | "no-arg": true, 44 | "no-bitwise": true, 45 | "no-console": [ 46 | true, 47 | "debug", 48 | "info", 49 | "time", 50 | "timeEnd", 51 | "trace" 52 | ], 53 | "no-construct": true, 54 | "no-debugger": true, 55 | "no-duplicate-super": true, 56 | "no-empty": false, 57 | "no-empty-interface": true, 58 | "no-eval": true, 59 | "no-inferrable-types": [ 60 | true, 61 | "ignore-params" 62 | ], 63 | "no-misused-new": true, 64 | "no-non-null-assertion": true, 65 | "no-shadowed-variable": true, 66 | "no-string-literal": false, 67 | "no-string-throw": true, 68 | "no-switch-case-fall-through": true, 69 | "no-trailing-whitespace": true, 70 | "no-unnecessary-initializer": true, 71 | "no-unused-expression": true, 72 | "no-use-before-declare": true, 73 | "no-var-keyword": true, 74 | "object-literal-sort-keys": false, 75 | "one-line": [ 76 | true, 77 | "check-open-brace", 78 | "check-catch", 79 | "check-else", 80 | "check-whitespace" 81 | ], 82 | "prefer-const": true, 83 | "quotemark": [ 84 | true, 85 | "single" 86 | ], 87 | "radix": true, 88 | "semicolon": [ 89 | true, 90 | "always" 91 | ], 92 | "triple-equals": [ 93 | true, 94 | "allow-null-check" 95 | ], 96 | "typedef-whitespace": [ 97 | true, 98 | { 99 | "call-signature": "nospace", 100 | "index-signature": "nospace", 101 | "parameter": "nospace", 102 | "property-declaration": "nospace", 103 | "variable-declaration": "nospace" 104 | } 105 | ], 106 | "typeof-compare": true, 107 | "unified-signatures": true, 108 | "variable-name": false, 109 | "whitespace": [ 110 | true, 111 | "check-branch", 112 | "check-decl", 113 | "check-operator", 114 | "check-separator", 115 | "check-type" 116 | ], 117 | "directive-selector": [ 118 | true, 119 | "attribute", 120 | "app", 121 | "camelCase" 122 | ], 123 | "component-selector": [ 124 | true, 125 | "element", 126 | "app", 127 | "kebab-case" 128 | ], 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "component-class-suffix": true, 137 | "directive-class-suffix": true, 138 | "no-access-missing-member": true, 139 | "templates-use-public": true, 140 | "invoke-injectable": true 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/app/pages/cart/cart-page.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | position: fixed; 3 | width: 100%; 4 | height: 100%; 5 | overflow: auto; 6 | background-color: #f6f6f6; 7 | padding-bottom: 70px; 8 | } 9 | .cart-page-container { 10 | max-width: 1140px; 11 | text-align: center; 12 | padding: 0 30px; 13 | margin: auto; 14 | } 15 | .cart-page-header h1 { 16 | font-size:50px; 17 | font-family: "Playfair Display"; 18 | margin: 80px 0; 19 | } 20 | .cart-page-content { 21 | max-width:940px; 22 | margin:30px 70px; 23 | background-color: white; 24 | padding:60px; 25 | } 26 | .cart-item-cell { 27 | width: 100%; 28 | } 29 | .cart-total, 30 | .cart-item-row { 31 | border-bottom: 1px solid #e4e4e4; 32 | } 33 | .cart-item-header .cart-item-cell:first-of-type { 34 | text-align: left; 35 | } 36 | .cart-item-header .cart-item-cell { 37 | text-transform: uppercase; 38 | font-size: 12px; 39 | letter-spacing: .15em; 40 | color: #9f9f9f; 41 | text-align: right; 42 | } 43 | .cart-item-thumbnail { 44 | float: left; 45 | width: 120px; 46 | height: 90px; 47 | margin-right: 15px; 48 | vertical-align: middle; 49 | background-position: 50% 50%; 50 | background-repeat: no-repeat; 51 | background-size: cover; 52 | } 53 | .cart-item-info { 54 | float: left; 55 | } 56 | .cart-item-brand { 57 | display: block; 58 | margin-bottom: 5px; 59 | font-size: 12px; 60 | text-transform: uppercase; 61 | text-align: left; 62 | letter-spacing: .05em; 63 | color: #9f9f9f; 64 | } 65 | .cart-item-title { 66 | color: #1d1d20; 67 | max-width: 100%; 68 | text-transform: uppercase; 69 | letter-spacing: .1em; 70 | text-align: left; 71 | } 72 | .item-price { 73 | color: #9f9f9f; 74 | font-size:16px; 75 | font-family: "Playfair Display"; 76 | } 77 | .item-remove { 78 | font-size: 30px; 79 | color:#9f9f9f; 80 | cursor:pointer; 81 | } 82 | .item-remove:hover { 83 | color:black; 84 | } 85 | 86 | .cart-total { 87 | text-transform: uppercase; 88 | color:#9f9f9f; 89 | letter-spacing: 2px; 90 | margin:0; 91 | } 92 | .cart-total-row { 93 | line-height: 30px; 94 | } 95 | .cart-total-label { 96 | text-align: left; 97 | } 98 | .cart-total-value { 99 | text-align: right; 100 | } 101 | .cart-total-price { 102 | color:black 103 | } 104 | 105 | .cart-buttons { 106 | padding:20px 0; 107 | } 108 | .continue-shopping a { 109 | text-transform: uppercase; 110 | color: black; 111 | float: left; 112 | } 113 | .checkout-button { 114 | float: right; 115 | margin-bottom: 20px; 116 | } 117 | 118 | @media screen and (min-width: 768px) { 119 | .cart-item-row { 120 | display: table; 121 | width: 100%; 122 | border-collapse: separate; 123 | border-spacing: 0 30px; 124 | box-sizing: border-box; 125 | table-layout: fixed; 126 | } 127 | .cart-item-product { 128 | width: 320%; 129 | text-align: left; 130 | } 131 | .cart-item-cell { 132 | display: table-cell; 133 | vertical-align: top; 134 | text-align: right; 135 | } 136 | } 137 | @media screen and (max-width: 820px) { 138 | .cart-page-content { 139 | margin:0; 140 | } 141 | .cart-page-header h1 { 142 | margin: 30px 0; 143 | } 144 | .cart-item-header { 145 | display: none; 146 | } 147 | .cart-item-product { 148 | width: 100%; 149 | float: left; 150 | margin-left: 0; 151 | padding-bottom: 15px; 152 | } 153 | .cart-item-quantity { 154 | width: 80%; 155 | float: left; 156 | padding-bottom: 15px; 157 | text-align: left; 158 | } 159 | .cart-item-total, 160 | .cart-item-action { 161 | text-align: right; 162 | } 163 | .cart-total-label { 164 | float: left; 165 | } 166 | .continue-shopping a { 167 | float: none; 168 | } 169 | .checkout-button { 170 | float: none; 171 | margin:20px 0 0 0; 172 | } 173 | } --------------------------------------------------------------------------------