From 83b2950970ff21067adbf5124a54fd3efbeb766d Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Tue, 4 Oct 2016 21:15:03 +0300 Subject: [PATCH] Step 1.1: Remove boilerplate example files --- both/collections/demo-collection.ts | 4 - both/models/demo-data-object.ts | 4 - client/imports/app/app.component.html | 1 - client/imports/app/app.component.scss | 5 - client/imports/app/app.module.ts | 9 +- .../app/demo/demo-data.service.test.ts | 19 ---- client/imports/app/demo/demo-data.service.ts | 18 ---- client/imports/app/demo/demo.component.html | 8 -- client/imports/app/demo/demo.component.scss | 3 - .../imports/app/demo/demo.component.test.ts | 95 ------------------- client/imports/app/demo/demo.component.ts | 25 ----- client/imports/app/index.ts | 2 - client/init.test.ts | 12 --- client/main.ts | 2 +- package.json | 4 + server/imports/server-main/main.test.ts | 40 -------- server/imports/server-main/main.ts | 22 ----- 17 files changed, 7 insertions(+), 266 deletions(-) delete mode 100644 both/collections/demo-collection.ts delete mode 100644 both/models/demo-data-object.ts delete mode 100644 client/imports/app/demo/demo-data.service.test.ts delete mode 100644 client/imports/app/demo/demo-data.service.ts delete mode 100644 client/imports/app/demo/demo.component.html delete mode 100644 client/imports/app/demo/demo.component.scss delete mode 100644 client/imports/app/demo/demo.component.test.ts delete mode 100644 client/imports/app/demo/demo.component.ts delete mode 100644 client/imports/app/index.ts delete mode 100644 client/init.test.ts delete mode 100644 server/imports/server-main/main.test.ts diff --git a/both/collections/demo-collection.ts b/both/collections/demo-collection.ts deleted file mode 100644 index 371b609..0000000 --- a/both/collections/demo-collection.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { MongoObservable } from 'meteor-rxjs'; -import { DemoDataObject } from '../models/demo-data-object'; - -export const DemoCollection = new MongoObservable.Collection('demo-collection'); \ No newline at end of file diff --git a/both/models/demo-data-object.ts b/both/models/demo-data-object.ts deleted file mode 100644 index 64846d7..0000000 --- a/both/models/demo-data-object.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface DemoDataObject { - name: string; - age: number; -} \ No newline at end of file diff --git a/client/imports/app/app.component.html b/client/imports/app/app.component.html index 1d40faa..3c4adac 100644 --- a/client/imports/app/app.component.html +++ b/client/imports/app/app.component.html @@ -1,4 +1,3 @@

Hello Angular2-Meteor!

-
diff --git a/client/imports/app/app.component.scss b/client/imports/app/app.component.scss index 4c02b72..e69de29 100644 --- a/client/imports/app/app.component.scss +++ b/client/imports/app/app.component.scss @@ -1,5 +0,0 @@ -body { - -} - -@import "./imports/demo/demo.component"; diff --git a/client/imports/app/app.module.ts b/client/imports/app/app.module.ts index 81baa33..40a3119 100644 --- a/client/imports/app/app.module.ts +++ b/client/imports/app/app.module.ts @@ -1,16 +1,11 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; -import { METEOR_PROVIDERS } from 'angular2-meteor'; - import { AppComponent } from './app.component'; -import { DemoComponent } from './demo/demo.component'; -import { DemoDataService } from './demo/demo-data.service'; @NgModule({ // Components, Pipes, Directive declarations: [ - AppComponent, - DemoComponent + AppComponent ], // Entry Components entryComponents: [ @@ -18,7 +13,7 @@ import { DemoDataService } from './demo/demo-data.service'; ], // Providers providers: [ - DemoDataService + ], // Modules imports: [ diff --git a/client/imports/app/demo/demo-data.service.test.ts b/client/imports/app/demo/demo-data.service.test.ts deleted file mode 100644 index 4320d63..0000000 --- a/client/imports/app/demo/demo-data.service.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -// chai uses as asset library -import { assert } from 'chai'; -import { Mongo } from 'meteor/mongo'; - -// Project imports -import { DemoDataService } from './demo-data.service'; - -describe('DemoDataService', () => { - let demoDataService:DemoDataService; - - beforeEach(() => { - // Create the service instance - demoDataService = new DemoDataService(); - }); - - it('Should return MongoDB Cursor when requesting the data', () => { - assert.isTrue(demoDataService.getData() instanceof Mongo.Cursor); - }); -}); diff --git a/client/imports/app/demo/demo-data.service.ts b/client/imports/app/demo/demo-data.service.ts deleted file mode 100644 index 357aaf7..0000000 --- a/client/imports/app/demo/demo-data.service.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ObservableCursor } from 'meteor-rxjs'; - -import { DemoDataObject } from '../../../../both/models/demo-data-object'; -import { DemoCollection } from '../../../../both/collections/demo-collection'; - -@Injectable() -export class DemoDataService { - private data : ObservableCursor; - - constructor() { - this.data = DemoCollection.find({}); - } - - public getData() : ObservableCursor { - return this.data; - } -} diff --git a/client/imports/app/demo/demo.component.html b/client/imports/app/demo/demo.component.html deleted file mode 100644 index 38180c6..0000000 --- a/client/imports/app/demo/demo.component.html +++ /dev/null @@ -1,8 +0,0 @@ -

{{greeting}}

- -This is the available data: -
    -
  • - {{item.name}} ({{item.age}}) -
  • -
diff --git a/client/imports/app/demo/demo.component.scss b/client/imports/app/demo/demo.component.scss deleted file mode 100644 index 9e27489..0000000 --- a/client/imports/app/demo/demo.component.scss +++ /dev/null @@ -1,3 +0,0 @@ -demo { - -} diff --git a/client/imports/app/demo/demo.component.test.ts b/client/imports/app/demo/demo.component.test.ts deleted file mode 100644 index 39221cd..0000000 --- a/client/imports/app/demo/demo.component.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -// chai uses as asset library -import { assert } from 'chai'; - -// Angular 2 tests imports -import { inject } from '@angular/core'; -import { provide } from '@angular/core'; -import { TestComponentBuilder } from '@angular/compiler'; - -// Project imports -import { DemoComponent } from './demo.component'; -import { DemoDataService } from './demo-data.service'; -import { DemoDataObject } from '../../../../both/models/demo-data-object'; - -describe('DemoComponent', () => { - let demoComponentInstance:DemoComponent; - let demoComponentElement; - let componentFixture; - - let mockDataArray = [ - { - name: 'Test', - age: 10 - } - ]; - - let mockDataService = { - getData: () => mockDataArray - }; - - beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => { - // We inject TestComponentBuilder that provides use the ability to control the injections of the component - // Then we will request to get DemoComponent with a mock service instead of the real DemoDataService - // The fixture created contain the element and the instance of the Component class - // Finally, we need to save 'detectChanges' and call it to flush the changes into the view. - return tcb.overrideProviders(DemoComponent, [ - provide(DemoDataService, {useValue: mockDataService}) - ]).createAsync(DemoComponent).then((fixture) => { - componentFixture = fixture; - - demoComponentInstance = componentFixture.componentInstance; - demoComponentElement = componentFixture.nativeElement; - - componentFixture.detectChanges(); - }); - })); - - describe('@Component instance', () => { - it('Should have a greeting string on the component', () => { - assert.typeOf(demoComponentInstance.greeting, 'string', 'Greeting should be a string!'); - }); - - it('Should say hello to the component on the greeting string', () => { - assert.equal(demoComponentInstance.greeting, 'Hello Demo Component!'); - }); - - it('Should have an array (from the mock) of the instance', () => { - assert.typeOf(demoComponentInstance.getData(), 'array'); - }); - - it('Should have an items in the array', () => { - assert.typeOf(demoComponentInstance.getData(), 'array'); - assert.equal((demoComponentInstance.getData()).length, 1); - }); - }); - - describe('@Component view', () => { - it('Should print the greeting to the screen', () => { - assert.include(demoComponentElement.innerHTML, 'Hello Demo Component'); - }); - - it('Should change the greeting when it changes', () => { - assert.include(demoComponentElement.innerHTML, 'Hello Demo Component'); - demoComponentInstance.greeting = 'New Test Greeting'; - componentFixture.detectChanges(); - assert.include(demoComponentElement.innerHTML, 'New Test Greeting'); - }); - - it('Should display a list of items in the screen', () => { - assert.isNotNull(demoComponentElement.querySelector('ul')); - }); - - it('Should add item to the list when modifying the data in the service', () => { - assert.equal(demoComponentElement.querySelectorAll('li').length, 1); - - mockDataArray.push({ - name: 'Dotan', - age: 20 - }); - - componentFixture.detectChanges(); - - assert.equal(demoComponentElement.querySelectorAll('li').length, 2); - }); - }); -}); diff --git a/client/imports/app/demo/demo.component.ts b/client/imports/app/demo/demo.component.ts deleted file mode 100644 index 9a4df43..0000000 --- a/client/imports/app/demo/demo.component.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { ObservableCursor } from 'meteor-rxjs'; -import { Observable } from 'rxjs/Observable'; - -import { DemoDataService } from './demo-data.service'; -import { DemoDataObject } from '../../../../both/models/demo-data-object'; - -import template from './demo.component.html'; - -@Component({ - selector: 'demo', - template -}) -export class DemoComponent implements OnInit { - greeting: string; - data: Observable; - - constructor(private demoDataService: DemoDataService) { - this.greeting = 'Hello Demo Component!'; - } - - ngOnInit() { - this.data = this.demoDataService.getData().zone(); - } -} diff --git a/client/imports/app/index.ts b/client/imports/app/index.ts deleted file mode 100644 index 875bdb2..0000000 --- a/client/imports/app/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './app.component'; -export * from './app.module'; diff --git a/client/init.test.ts b/client/init.test.ts deleted file mode 100644 index cd07c0b..0000000 --- a/client/init.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -// angular2-meteor polyfills required for testing -import 'angular2-meteor-tests-polyfills'; - -// Angular 2 tests imports -import { platformBrowserDynamicTesting, BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic'; -import { TestBed } from '@angular/core'; - -// Init the test framework -TestBed.initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); diff --git a/client/main.ts b/client/main.ts index 8f35a92..2b50651 100644 --- a/client/main.ts +++ b/client/main.ts @@ -3,7 +3,7 @@ import 'angular2-meteor-polyfills'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { Meteor } from "meteor/meteor"; -import { AppModule } from './imports/app'; +import { AppModule } from './imports/app/app.module'; enableProdMode(); diff --git a/package.json b/package.json index 0d5af2b..6214a3d 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,17 @@ "@angular/compiler": "2.1.1", "@angular/core": "2.1.1", "@angular/forms": "2.1.1", + "@angular/http": "2.1.1", "@angular/platform-browser": "2.1.1", "@angular/platform-browser-dynamic": "2.1.1", + "@angular/platform-server": "2.1.1", "@angular/router": "3.1.1", "angular2-meteor": "0.7.1", "angular2-meteor-polyfills": "0.1.1", "angular2-meteor-tests-polyfills": "0.0.2", "meteor-node-stubs": "0.2.4", + "ionic-angular": "^2.0.0-rc.3", + "ionicons": "^3.0.0", "meteor-rxjs": "^0.4.5", "reflect-metadata": "0.1.8", "rxjs": "5.0.0-beta.12", diff --git a/server/imports/server-main/main.test.ts b/server/imports/server-main/main.test.ts deleted file mode 100644 index e050427..0000000 --- a/server/imports/server-main/main.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -// chai uses as asset library -import * as chai from 'chai'; -import * as spies from 'chai-spies'; -import StubCollections from 'meteor/hwillson:stub-collections'; - -import { DemoCollection } from '../../../both/collections/demo-collection'; -import { Main } from './main'; - -chai.use(spies); - -describe('Server Main', () => { - let mainInstance : Main; - - beforeEach(() => { - // Creating database mock - StubCollections.stub(DemoCollection); - - // Create instance of main class - mainInstance = new Main(); - }); - - afterEach(() => { - // Restore database - StubCollections.restore(); - }); - - it('Should call initFakeData on startup', () => { - mainInstance.initFakeData = chai.spy(); - mainInstance.start(); - - chai.expect(mainInstance.initFakeData).to.have.been.called(); - }); - - it('Should call insert 3 times when init fake data', () => { - DemoCollection.insert = chai.spy(); - mainInstance.initFakeData(); - - chai.expect(DemoCollection.insert).to.have.been.called.exactly(3); - }); -}); diff --git a/server/imports/server-main/main.ts b/server/imports/server-main/main.ts index d4b1cda..ca6ff2f 100644 --- a/server/imports/server-main/main.ts +++ b/server/imports/server-main/main.ts @@ -1,27 +1,5 @@ -import { DemoCollection } from '../../../both/collections/demo-collection'; -import { DemoDataObject } from '../../../both/models/demo-data-object'; - export class Main { start(): void { - this.initFakeData(); - } - initFakeData(): void { - if (DemoCollection.find({}).cursor.count() === 0) { - const data: DemoDataObject[] = [{ - name: 'Dotan', - age: 25 - }, { - name: 'Liran', - age: 26 - }, { - name: 'Uri', - age: 30 - }]; - - data.forEach((obj: DemoDataObject) => { - DemoCollection.insert(obj); - }); - } } }