From 4980659bd6d20446c0e3d3036d9f5ab5e74c3030 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 28 Jun 2016 15:20:42 -0500 Subject: [PATCH] test(overlay): use injectable overlay controllers --- .../action-sheet/test/basic/index.ts | 30 ++++---- src/components/alert/test/basic/index.ts | 59 +++++++------- src/components/alert/test/dismiss/index.ts | 31 ++++---- src/components/app/test/app.spec.ts | 60 +++++++-------- src/components/app/test/cordova/e2e.ts | 4 +- src/components/app/test/cordova/index.ts | 15 ++-- src/components/item/test/sliding/index.ts | 28 +++---- src/components/loading/test/basic/index.ts | 76 +++++++++---------- src/components/loading/test/tabs/index.ts | 22 ++---- src/components/menu/test/basic/index.ts | 10 +-- src/components/menu/test/overlay/index.ts | 10 ++- src/components/menu/test/push/index.ts | 10 ++- src/components/modal/test/basic/index.ts | 32 ++++---- src/components/modal/test/modal.spec.ts | 29 ++----- src/components/nav/test/basic/index.ts | 18 +++-- src/components/picker/test/basic/index.ts | 24 +++--- src/components/popover/test/basic/index.ts | 47 +++++------- src/components/tabs/test/advanced/index.ts | 9 +-- src/components/tabs/test/basic/index.ts | 11 ++- src/components/tabs/test/tabs.spec.ts | 4 +- src/components/toast/test/basic/index.ts | 23 +++--- 21 files changed, 263 insertions(+), 289 deletions(-) diff --git a/src/components/action-sheet/test/basic/index.ts b/src/components/action-sheet/test/basic/index.ts index c2caa533a6..ca93821ff8 100644 --- a/src/components/action-sheet/test/basic/index.ts +++ b/src/components/action-sheet/test/basic/index.ts @@ -1,5 +1,5 @@ -import {Component} from '@angular/core'; -import {ionicBootstrap, ActionSheet, Alert, Modal, NavController, ViewController, Platform} from '../../../../../src'; +import { Component } from '@angular/core'; +import { ionicBootstrap, ActionSheetController, AlertController, ModalController, ViewController, Platform } from '../../../../../src'; @Component({ @@ -8,12 +8,12 @@ import {ionicBootstrap, ActionSheet, Alert, Modal, NavController, ViewController class E2EPage { result: string = ''; - constructor(private nav: NavController, private platform: Platform) {} + constructor(private actionSheetCtrl: ActionSheetController, private alertCtrl: AlertController, private modalCtrl: ModalController, private platform: Platform) {} presentActionSheet1() { this.result = ''; - let actionSheet = ActionSheet.create({ + let actionSheet = this.actionSheetCtrl.create({ title: 'Albums', buttons: [ { @@ -37,8 +37,8 @@ class E2EPage { text: 'Play', icon: !this.platform.is('ios') ? 'arrow-dropright-circle' : null, handler: () => { - let modal = Modal.create(ModalPage); - this.nav.present(modal); + let modal = this.modalCtrl.create(ModalPage); + modal.present(); // returning false does not allow the actionsheet to be closed return false; @@ -64,13 +64,13 @@ class E2EPage { ] }); - this.nav.present(actionSheet); + actionSheet.present(); } - presentActionSheet2(ev) { + presentActionSheet2() { this.result = ''; - let actionSheet = ActionSheet.create({ + let actionSheet = this.actionSheetCtrl.create({ enableBackdropDismiss: false, buttons: [ { @@ -99,20 +99,20 @@ class E2EPage { ] }); - this.nav.present(actionSheet); + actionSheet.present(actionSheet); } - presentActionSheet3(ev) { + presentActionSheet3() { this.result = ''; - let actionSheet = ActionSheet.create({ + let actionSheet = this.actionSheetCtrl.create({ buttons: [ { text: 'Open Alert', handler: () => { this.result = 'Opened alert'; - let alert = Alert.create(); + let alert = this.alertCtrl.create(); alert.setTitle('Alert!'); alert.setMessage('Alert opened from an action sheet'); alert.addButton({ @@ -129,7 +129,7 @@ class E2EPage { } }); - this.nav.present(alert).then(() => { + alert.present().then(() => { this.result = 'Alert from action sheet opened'; }); @@ -147,7 +147,7 @@ class E2EPage { ] }); - this.nav.present(actionSheet); + actionSheet.present(); } } diff --git a/src/components/alert/test/basic/index.ts b/src/components/alert/test/basic/index.ts index 766e3c1881..5816669414 100644 --- a/src/components/alert/test/basic/index.ts +++ b/src/components/alert/test/basic/index.ts @@ -1,5 +1,5 @@ -import {Component} from '@angular/core'; -import {ionicBootstrap, Alert, Modal, NavController, ViewController} from '../../../../../src'; +import { Component } from '@angular/core'; +import { ionicBootstrap, AlertController, ModalController, ViewController } from '../../../../../src'; @Component({ @@ -15,21 +15,21 @@ class E2EPage { testCheckboxOpen: boolean = false; testCheckboxResult: string = ''; - constructor(private nav: NavController) { } + constructor(private alertCtrl: AlertController, private modalCtrl: ModalController) { } doAlert() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Alert', subTitle: 'Subtitle', message: 'This is an alert message.', buttons: ['OK'] }); - this.nav.present(alert); + alert.present(); } doConfirm() { - let alert = Alert.create(); + let alert = this.alertCtrl.create(); alert.setTitle('Confirm!'); alert.setMessage('Message text!!!'); alert.addButton({ @@ -50,30 +50,30 @@ class E2EPage { } }); - this.nav.present(alert).then(() => { + alert.present(alert).then(() => { this.testConfirmOpen = true; }); } doAlertLongMessage() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Alert', message: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum hendrerit diam lorem, a faucibus turpis sagittis eu. In finibus augue in dui varius convallis. Donec vulputate nibh gravida odio vulputate commodo. Suspendisse imperdiet consequat egestas. Nulla feugiat consequat urna eu tincidunt. Cras nec blandit turpis, eu auctor nunc. Pellentesque finibus, magna eu vestibulum imperdiet, arcu ex lacinia massa, eget volutpat quam leo a orci. Etiam mauris est, elementum at feugiat at, dictum in sapien. Mauris efficitur eros sodales convallis egestas. Phasellus eu faucibus nisl. In eu diam vitae libero egestas lacinia. Integer sed convallis metus, nec commodo felis. Duis libero augue, ornare at tempus non, posuere vel augue. Cras mattis dui at tristique aliquam. Phasellus fermentum nibh ligula, porta hendrerit ligula elementum eu. Suspendisse sollicitudin enim at libero iaculis pulvinar. Donec ac massa id purus laoreet rutrum quis eu urna. Mauris luctus erat vel magna porttitor, vel varius erat rhoncus. Donec eu turpis vestibulum, feugiat urna id, gravida mauris. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at lobortis tortor. Nam ultrices volutpat elit, sed pharetra nulla suscipit at. Nunc eu accumsan eros, id auctor libero. Suspendisse potenti. Nam vitae dapibus metus. Maecenas nisi dui, sagittis et condimentum eu, bibendum vel eros. Vivamus malesuada, tortor in accumsan iaculis, urna velit consectetur ante, nec semper sem diam a diam. In et semper ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus blandit, velit vel porttitor euismod, neque risus blandit nulla, non laoreet libero dolor et odio. Nulla enim risus, feugiat eu urna sed, ultrices semper felis. Sed blandit mi diam. Nunc quis mi ligula. Pellentesque a elit eu orci volutpat egestas. Aenean fermentum eleifend quam, ut tincidunt eros tristique et. Nam dapibus tincidunt ligula, id faucibus felis sodales quis. Donec tincidunt lectus ipsum, ac semper tellus cursus ac. Vestibulum nec dui a lectus accumsan vestibulum quis et velit. Aliquam finibus justo et odio euismod, viverra condimentum eros tristique. Sed eget luctus risus. Pellentesque lorem magna, dictum non congue sodales, laoreet eget quam. In sagittis vulputate dolor a ultricies. Donec viverra leo sed ex maximus, in finibus elit gravida. Aliquam posuere vulputate mi. Suspendisse potenti. Nunc consectetur congue arcu, at pharetra dui varius non. Etiam vestibulum congue felis, id ullamcorper neque convallis ultrices. Aenean congue, diam a iaculis mollis, nisl eros maximus arcu, nec hendrerit purus felis porta diam. Nullam vitae ultrices dui, ac dictum sapien. Phasellus eu magna luctus, varius urna id, molestie quam. Nulla in semper tellus. Curabitur lacinia tellus sit amet lacinia dapibus. Sed id condimentum tellus, nec aliquam sapien. Vivamus luctus at ante a tincidunt.', buttons: ['Cancel', 'OK'] }); - this.nav.present(alert); + alert.present(alert); } doAlertNoMessage() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Alert', buttons: ['OK'] }); - this.nav.present(alert); + alert.present(); } doMultipleButtons() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Alert', subTitle: 'Subtitle', message: 'This is an alert message.' @@ -82,19 +82,18 @@ class E2EPage { alert.addButton({ text: 'Open Modal', handler: () => { - let modal = Modal.create(ModalPage); - this.nav.present(modal); + this.modalCtrl.create(ModalPage).present(); // do not close the alert when this button is pressed return false; } }); alert.addButton('Delete'); - this.nav.present(alert); + alert.present(); } doPrompt() { - let alert = Alert.create(); + let alert = this.alertCtrl.create(); alert.setTitle('Prompt!'); alert.addInput({ placeholder: 'Placeholder 1' @@ -112,7 +111,7 @@ class E2EPage { }); alert.addButton({ text: 'Cancel', - handler: data => { + handler: (data: any) => { console.log('500ms delayed prompt close'); setTimeout(() => { @@ -126,24 +125,24 @@ class E2EPage { }); alert.addButton({ text: 'Ok', - handler: data => { + handler: (data: any) => { console.log('Prompt data:', data); this.testPromptOpen = false; this.testPromptResult = data; } }); - this.nav.present(alert).then(() => { + alert.present().then(() => { this.testPromptOpen = true; }); - alert.onDismiss((data, role) => { + alert.onDismiss((data: any, role: any) => { console.log('onDismiss, data:', data, 'role:', role); }); } doRadio() { - let alert = Alert.create(); + let alert = this.alertCtrl.create(); alert.setTitle('Radio!'); alert.addInput({ @@ -186,20 +185,20 @@ class E2EPage { alert.addButton('Cancel'); alert.addButton({ text: 'Ok', - handler: data => { + handler: (data: any) => { console.log('Radio data:', data); this.testRadioOpen = false; this.testRadioResult = data; } }); - this.nav.present(alert).then(() => { + alert.present().then(() => { this.testRadioOpen = true; }); } doCheckbox() { - let alert = Alert.create(); + let alert = this.alertCtrl.create(); alert.setTitle('Checkbox!'); alert.addInput({ @@ -242,25 +241,25 @@ class E2EPage { alert.addButton('Cancel'); alert.addButton({ text: 'Ok', - handler: data => { + handler: (data: any) => { console.log('Checkbox data:', data); this.testCheckboxOpen = false; this.testCheckboxResult = data; } }); - this.nav.present(alert).then(() => { + alert.present().then(() => { this.testCheckboxOpen = true; }); } doFastClose() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Alert!', buttons: ['OK'] }); - this.nav.present(alert); + alert.present(); setTimeout(() => { alert.dismiss(); @@ -268,7 +267,7 @@ class E2EPage { } doDisabledBackdropAlert() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ enableBackdropDismiss: false }); alert.setTitle('Disabled Backdrop Click'), @@ -281,7 +280,7 @@ class E2EPage { } }); - this.nav.present(alert); + alert.present(); } ionViewDidLeave() { diff --git a/src/components/alert/test/dismiss/index.ts b/src/components/alert/test/dismiss/index.ts index a01daa24eb..597e9477a2 100644 --- a/src/components/alert/test/dismiss/index.ts +++ b/src/components/alert/test/dismiss/index.ts @@ -1,6 +1,6 @@ -import {Component} from '@angular/core'; -import {ionicBootstrap, Alert, Loading, NavController} from '../../../../index'; -import {FormBuilder, ControlGroup, Validators} from '@angular/common'; +import { Component } from '@angular/core'; +import { ionicBootstrap, AlertController, LoadingController, NavController } from '../../../../index'; +import { FormBuilder, ControlGroup, Validators } from '@angular/common'; @Component({ @@ -8,10 +8,10 @@ import {FormBuilder, ControlGroup, Validators} from '@angular/common'; }) export class E2EPage { - constructor(private nav: NavController) {} + constructor(private alertCtrl: AlertController, private nav: NavController) {} submit() { - var alert = Alert.create({ + var alert = this.alertCtrl.create({ title: 'Not logged in', message: 'Sign in to continue.', buttons: [ @@ -29,7 +29,7 @@ export class E2EPage { this.nav.push(AnotherPage); }); - this.nav.present(alert); + alert.present(); } } @@ -63,7 +63,7 @@ export class E2EPage { class AnotherPage { form: ControlGroup; - constructor(private nav: NavController, private builder: FormBuilder) { + constructor(private nav: NavController, private alertCtrl: AlertController, private loadingCtrl: LoadingController, private builder: FormBuilder) { this.form = builder.group({ name: builder.control('', Validators.compose([ Validators.required, @@ -75,12 +75,13 @@ class AnotherPage { submit(value: any): void { if (this.form.valid) { console.log(value); + } else { - this.nav.present(Alert.create({ + this.alertCtrl.create({ title: 'Invalid input data', subTitle: "Please correct the errors and resubmit the data.", buttons: [ 'OK' ] - })); + }).present(); } } @@ -89,7 +90,7 @@ class AnotherPage { } showConfirm() { - const alert = Alert.create({ + const alert = this.alertCtrl.create({ title: `Hi there`, buttons: [ { @@ -110,21 +111,21 @@ class AnotherPage { } ] }); - this.nav.present(alert); + alert.present(); } doFastPop() { - let alert = Alert.create({ + let alert = this.alertCtrl.create({ title: 'Async Nav Transition', message: 'This is an example of dismissing an alert, then quickly starting another transition on the same nav controller.', buttons: [{ text: 'Ok', handler: () => { // present a loading indicator - let loading = Loading.create({ + let loading = this.loadingCtrl.create({ content: 'Loading...' }); - this.nav.present(loading); + loading.present(); // start an async operation setTimeout(() => { @@ -150,7 +151,7 @@ class AnotherPage { } }] }); - this.nav.present(alert); + alert.present(); } } diff --git a/src/components/app/test/app.spec.ts b/src/components/app/test/app.spec.ts index 9ec924992b..afe9f6b14f 100644 --- a/src/components/app/test/app.spec.ts +++ b/src/components/app/test/app.spec.ts @@ -11,7 +11,7 @@ describe('App', () => { it('should select the previous tab', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); let tabs = mockTabs(); @@ -42,7 +42,7 @@ describe('App', () => { it('should pop from the active tab, when tabs is nested is the root nav', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); let tabs = mockTabs(); @@ -94,7 +94,7 @@ describe('App', () => { let rootNav = mockNav(); let nestedNav = mockNav(); let portal = mockNav(); - rootNav.setPortal(portal); + app.setPortal(portal); rootNav.registerChildNav(nestedNav); nestedNav.parent = rootNav; app.setRootNav(rootNav); @@ -123,7 +123,7 @@ describe('App', () => { let rootNav = mockNav(); let nestedNav = mockNav(); let portal = mockNav(); - rootNav.setPortal(portal); + app.setPortal(portal); app.setRootNav(rootNav); rootNav.registerChildNav(nestedNav); @@ -151,7 +151,7 @@ describe('App', () => { it('should pop the overlay in the portal of the root nav', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); spyOn(platform, 'exitApp'); @@ -175,7 +175,7 @@ describe('App', () => { it('should pop the second view in the root nav', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); spyOn(platform, 'exitApp'); @@ -196,7 +196,7 @@ describe('App', () => { it('should exit app when only one view in the root nav', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); spyOn(platform, 'exitApp'); @@ -219,7 +219,7 @@ describe('App', () => { it('should not exit app when only one view in the root nav, but navExitApp config set', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); spyOn(platform, 'exitApp'); @@ -244,7 +244,7 @@ describe('App', () => { it('should not go back if app is not enabled', () => { let nav = mockNav(); let portal = mockNav(); - nav.setPortal(portal); + app.setPortal(portal); app.setRootNav(nav); spyOn(platform, 'exitApp'); @@ -372,71 +372,71 @@ describe('App', () => { describe('setEnabled', () => { it('should disable click block when app is enabled', () => { // arrange - let mockClickBlock = { - show: () => {} + let mockClickBlock: any = { + activate: () => {} }; - spyOn(mockClickBlock, 'show'); + spyOn(mockClickBlock, 'activate'); - app._clickBlock = mockClickBlock; + app.clickBlock = mockClickBlock; // act app.setEnabled(true); // assert - expect(mockClickBlock.show).toHaveBeenCalledWith(false, 0); + expect(mockClickBlock.activate).toHaveBeenCalledWith(false, 0); }); it('should disable click block when app is disabled but duration of less than 32 passed', () => { // arrange - let mockClickBlock = { - show: () => {} + let mockClickBlock: any = { + activate: () => {} }; - spyOn(mockClickBlock, 'show'); + spyOn(mockClickBlock, 'activate'); - app._clickBlock = mockClickBlock; + app.clickBlock = mockClickBlock; // act app.setEnabled(false, 20); // assert - expect(mockClickBlock.show).toHaveBeenCalledWith(false, 0); + expect(mockClickBlock.activate).toHaveBeenCalledWith(false, 0); }); it('should enable click block when false is passed with duration', () => { // arrange - let mockClickBlock = { - show: () => {} + let mockClickBlock: any = { + activate: () => {} }; - spyOn(mockClickBlock, 'show'); + spyOn(mockClickBlock, 'activate'); - app._clickBlock = mockClickBlock; + app.clickBlock = mockClickBlock; // act app.setEnabled(false, 200); // assert - expect(mockClickBlock.show).toHaveBeenCalledWith(true, 200 + 64); + expect(mockClickBlock.activate).toHaveBeenCalledWith(true, 200 + 64); }); it('should enable click block when false is passed w/o duration', () => { // arrange - let mockClickBlock = { - show: () => {} + let mockClickBlock: any = { + activate: () => {} }; - spyOn(mockClickBlock, 'show'); + spyOn(mockClickBlock, 'activate'); - app._clickBlock = mockClickBlock; + app.clickBlock = mockClickBlock; // act app.setEnabled(false); // assert // 700 is the default - expect(mockClickBlock.show).toHaveBeenCalledWith(true, 700 + 64); + expect(mockClickBlock.activate).toHaveBeenCalledWith(true, 700 + 64); }); }); @@ -469,7 +469,7 @@ describe('App', () => { beforeEach(() => { config = new Config(); platform = new Platform(); - app = new App(config, null, platform); + app = new App(config, platform); _cd = { reattach: function(){}, detach: function(){} diff --git a/src/components/app/test/cordova/e2e.ts b/src/components/app/test/cordova/e2e.ts index 567a19a73e..7edbfc134e 100644 --- a/src/components/app/test/cordova/e2e.ts +++ b/src/components/app/test/cordova/e2e.ts @@ -15,6 +15,6 @@ it('should open modal', function() { element(by.css('.e2eCordovaOpenModal')).click(); }); -it('should open left menu', function() { - element(by.css('.e2eCordovaOpenLeftMenu')).click(); +it('should close modal', function() { + element(by.css('.e2eCordovaCloseModal')).click(); }); diff --git a/src/components/app/test/cordova/index.ts b/src/components/app/test/cordova/index.ts index b1559e9073..239d442186 100644 --- a/src/components/app/test/cordova/index.ts +++ b/src/components/app/test/cordova/index.ts @@ -1,5 +1,5 @@ import {Component} from '@angular/core'; -import {ionicBootstrap, NavController, Modal, ViewController} from '../../../../../src'; +import {ionicBootstrap, NavController, ModalController, ViewController} from '../../../../../src'; import {Injectable} from '@angular/core'; @@ -26,9 +26,11 @@ export class OtherData { This is a modal - + + +