This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const romanNumerics = { | |
I: 1, | |
V: 5, | |
X: 10, | |
L: 50, | |
C: 100, | |
D: 500, | |
M: 1000 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const DragEvent = (selector:string):Observable<boolean> => { | |
//element where the drag event should be recorded (make sure element is in the dom) | |
const elem = document.querySelector(selector); | |
// touch events to handle mobile devices | |
const touchStart$ = fromEvent<TouchEvent>(elem, 'touchstart'); | |
const touchEnd$ = fromEvent<TouchEvent>(elem, 'touchend'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//testing both success and fail status | |
it('should handle Add to bag Message', () => { | |
const msg: BagResponse = { | |
actionType: 'add', | |
category: 'bag', | |
product: { colorId: '01', productId: '23423', sizeId: 'SM003' }, | |
status: 'success' | |
}; | |
component.chooseMessageHandler(msg); | |
expect(component.bag[0]).toBe(component.buildIdentifier(msg.product)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('CounterComponent', () => { | |
let component: CounterComponent; | |
let fixture: ComponentFixture<CounterComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [CounterComponent] | |
}).compileComponents(); | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BaseProduct { | |
name: string; | |
id: number; | |
price: number; | |
} | |
interface ProductsList { | |
top: BaseProduct[]; | |
bottom: BaseProduct[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BaseProduct { | |
name: string; | |
id: number; | |
price: number; | |
} | |
interface ProductsList { | |
top: BaseProduct[]; | |
bottom: BaseProduct[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ProductComponent implements OnInit { | |
product: Product; | |
constructor(private route: ActivatedRoute) {} | |
ngOnInit() { | |
this.product = this.route.snapshot.data['product']; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class ProductResolver implements Resolve<Product> { | |
constructor(private api: ApiService) {} | |
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Product> { | |
return this.api.product(route.params['id']); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ProductComponent implements OnInit { | |
product$: Observable<Product>; | |
constructor(private api: ApiService,private route:ActivatedRoute) {} | |
ngOnInit() { | |
const id = this.route.snapshop.params['id']; | |
this.product$ = this.api.product(id); | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//src/common/services/api.service.ts | |
@Injectable({ providedIn: 'root' }) | |
export class ApiService { | |
monitor = "/monitor"; | |
analytics = "/analytics"; | |
api = "/api" | |
constructor(private httpClient: HttpClient) { } | |