Skip to content

Commit

Permalink
test(app): Add tests for the app module
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed May 19, 2017
1 parent 1f4d8f5 commit aa98b56
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"i18n": "rm -Rf src/assets/i18n && mkdir src/assets/i18n && cp node_modules/tw-i18n/lang/*.json src/assets/i18n",
"twwatches": "rm -Rf src/assets/watches && mkdir src/assets/watches && cp -R node_modules/tw-watches/* src/assets/watches",
"prod": "npm run assets && ionic-app-scripts build --prod",
"test": "karma start ./test-config/karma.conf.js",
"test": "karma start ./test-config/karma.conf.js --coverage",
"test-ci": "karma start ./test-config/karma.conf.js --single-run --coverage",
"e2e": "webdriver-manager update --standalone false --gecko false; protractor ./test-config/protractor.conf.js",
"coverage": "codecov -f coverage/*.info"
Expand Down
44 changes: 41 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, TestBed } from '@angular/core/testing';
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { IonicModule, Platform } from 'ionic-angular';

import { PlatformMock } from '../../test-config/mocks-ionic';
Expand Down Expand Up @@ -32,7 +32,6 @@ import { Pipe, PipeTransform } from '@angular/core';

class ApiMock {
constructor() {
console.log("constructed");
}
}

Expand Down Expand Up @@ -63,7 +62,11 @@ describe('MyApp Component', () => {
AnalyticsService,
Keyboard
]
})
});

window.open = function(url?: string, target?: string, features?: string, replace?: boolean): Window{
return window;
}
}));

beforeEach(() => {
Expand All @@ -75,4 +78,39 @@ describe('MyApp Component', () => {
expect(component instanceof MyApp).toBe(true);
});

it('should open intagram', () => {
expect(component.intagram()).toBeUndefined();
});

it('should open pinterest', () => {
expect(component.pinterest()).toBeUndefined();
});

it('should open twitter', () => {
expect(component.twitter()).toBeUndefined();
});

it('should open facebook', () => {
expect(component.facebook()).toBeUndefined();
});

it('should enable the menu controller', fakeAsync(() => {

MyApp.userLogged.emit();
tick();
expect((component as any).menuController).toBeDefined();
}));

it('should open the contact form', fakeAsync(() => {
component.contact();
tick();
expect((component as any).menuController).toBeDefined();
}));

it('should open the beer form', fakeAsync(() => {
component.beer();
tick();
expect((component as any).menuController).toBeDefined();
}));

});
53 changes: 27 additions & 26 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class MyApp {
private platform: Platform,
private twapi: TwAPIService,
private alertController: AlertController,
public menuController: MenuController,
private menuController: MenuController,
private analytics: AnalyticsService,
private storage: Storage,
private translate: TranslateService,
private keyboard: Keyboard,
Expand All @@ -82,29 +83,29 @@ export class MyApp {

keyboard.disableScroll(true);
this.menuController.enable(false);


MyApp.userLogged.subscribe(
() => { this.menuController.enable(true); }
);

appVersion.getVersionNumber().then(
(version) => {
analytics.appVersion = version;
this.version = version;
}
).catch(
(err) => {
analytics.appVersion = "0.0.0";
this.version = "0.0.0";
}
);

// AppVersion.getVersionNumber().then(
// (version)=> {
// GAService.appVersion = version;
// this.version = version;
// }
// ).catch(
// (err)=> {
// GAService.appVersion = "0.0.0";
// this.version = "0.0.0";
// }
// );

// if(platform.is('ios')){
// GAService.appName = "ios";
// }else{
// GAService.appName = "android";
// }
if (platform.is('ios')) {
analytics.appName = "ios";
} else {
analytics.appName = "android";
}
});
}

Expand All @@ -125,20 +126,20 @@ export class MyApp {
}

contact() {
this.iab.create('https://go.crisp.im/chat/embed/?website_id=-K4rBEcM_Qbt6JrISVzu', '_blank');
let browser = this.iab.create('https://go.crisp.im/chat/embed/?website_id=-K4rBEcM_Qbt6JrISVzu', '_blank');

/**
* Don't do inject if user isn't logged yet
*/
// if(GAService.userEmail != null && GAService.userName != null){
if (this.analytics.userEmail != null && this.analytics.userName != null) {


// let script:string = ''
// + '$crisp.set("user:email", "'+ GAService.userEmail +'");'
// + '$crisp.set("user:nickname", "'+ GAService.userName +'");'
// +''
// browser.executeScript({code: script});
// }
let script: string = ''
+ '$crisp.set("user:email", "' + this.analytics.userEmail + '");'
+ '$crisp.set("user:nickname", "' + this.analytics.userName + '");'
+ ''
browser.executeScript({ code: script });
}
this.menuController.close();

}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/watches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"/"
],
"_resolved": "git+https://github.com/Toolwatchapp/tw-watches.git#a32dbd4b494ff364e3cfda08fd9753bdf6a38917",
"_shasum": "2368333744ddcd458661c649afd55edbc603c75f",
"_shasum": "7afb48249513e6c10981be43e62a3cc2ae67d928",
"_shrinkwrap": null,
"_spec": "tw-watches@git+https://github.com/Toolwatchapp/tw-watches.git",
"_where": "/mnt/dev/1-NodeWorkspace/toolwatch/tw-mobile",
Expand Down
77 changes: 77 additions & 0 deletions src/pages/about/about.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { IonicModule, Platform } from 'ionic-angular';

import { PlatformMock } from '../../../test-config/mocks-ionic';

import { AboutPage } from './about';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule, Http } from '@angular/http';
import { IonicStorageModule } from '@ionic/storage';
import { BrowserModule } from '@angular/platform-browser';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { Keyboard } from '@ionic-native/keyboard';
import { AppVersion } from '@ionic-native/app-version';
import { Facebook } from '@ionic-native/facebook';
import { SocialSharing } from '@ionic-native/social-sharing';
import { AppRate } from '@ionic-native/app-rate';

import { TranslateService, TranslateModule } from '@ngx-translate/core';


import { HeaderComponentModule } from './../../components/header/header.module';
import { FooterComponentModule } from './../../components/footer/footer.module';

import {
TwAPIService,
AnalyticsService,
ConfigurationService
} from 'tw-core';


import { Pipe, PipeTransform } from '@angular/core';

class ApiMock {
constructor() {
}
}

describe('MyApp Component', () => {
let fixture;
let component: AboutPage;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AboutPage],
imports: [
IonicModule.forRoot(AboutPage),
TranslateModule.forRoot(),
HeaderComponentModule,
FooterComponentModule,
],
providers: [
StatusBar,
SplashScreen,
{ provide: Platform, useClass: PlatformMock },
{ provide: TwAPIService, useClass: ApiMock },
Keyboard,
AppVersion,
StatusBar,
Facebook,
SocialSharing,
AppRate,
InAppBrowser,
AnalyticsService,
Keyboard
]
});
}));

beforeEach(() => {
fixture = TestBed.createComponent(AboutPage);
component = fixture.componentInstance;
});

});

0 comments on commit aa98b56

Please sign in to comment.