Skip to content

Commit

Permalink
fix(modal): exception when calling ViewBase.showModal(...) (#5737)
Browse files Browse the repository at this point in the history
  • Loading branch information
manoldonev authored Apr 25, 2018
1 parent 9e3da8e commit 451589d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
104 changes: 104 additions & 0 deletions tests/app/ui/page/page-tests-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,110 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage(
page.off(Label.loadedEvent, navigatedEventHandler);
}

export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() {
let modalClosed = false;

const modalCloseCallback = function (returnValue: any) {
modalClosed = true;
}

const createTabItems = function(count: number) {
var items = new Array<TabViewItem>();

for (var i = 0; i < count; i++) {
var label = new Label();
label.text = "Tab " + i;
var tabEntry = new TabViewItem();
tabEntry.title = "Tab " + i;
tabEntry.view = label;

items.push(tabEntry);
}

return items;
}

const modalPageShownModallyEventHandler = function(args: ShownModallyData) {
const page = <Page>args.object;
page.off(View.shownModallyEvent, modalPageShownModallyEventHandler);
args.closeCallback();
}

const hostNavigatedToEventHandler = function(args) {
const page = <Page>args.object;
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);

const modalPage = new Page();
modalPage.id = "modalPage_test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal";
modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler);
const tabViewItem = (<TabView>page.content).items[0];
tabViewItem.showModal(modalPage, {}, modalCloseCallback, false, false);
}

const masterPageFactory = function(): Page {
const masterPage = new Page();
masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal";
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler)

const tabView = new TabView();
tabView.items = createTabItems(2);
masterPage.content = tabView;

return masterPage;
};

helper.navigate(masterPageFactory);

TKUnit.waitUntilReady(() => modalClosed);
}

export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
let navigatedTo = false;

const createTabItems = function(count: number) {
var items = new Array<TabViewItem>();

for (var i = 0; i < count; i++) {
var label = new Label();
label.text = "Tab " + i;
var tabEntry = new TabViewItem();
tabEntry.title = "Tab " + i;
tabEntry.view = label;

items.push(tabEntry);
}

return items;
}

const hostNavigatedToEventHandler = function(args) {
const page = <Page>args.object;
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);

const hostPage = <Page>args.object;
const tabViewItem = (<TabView>page.content).items[0];
TKUnit.assertThrows(() => tabViewItem.showModal());

navigatedTo = true;
}

const masterPageFactory = function(): Page {
const masterPage = new Page();
masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow";
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler)

const tabView = new TabView();
tabView.items = createTabItems(2);
masterPage.content = tabView;

return masterPage;
};

helper.navigate(masterPageFactory);

TKUnit.waitUntilReady(() => navigatedTo);
}

export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
let page1;
let page2;
Expand Down
4 changes: 2 additions & 2 deletions tns-core-modules/ui/core/view-base/view-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,9 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
}
}

public showModal(): ViewBase {
public showModal(...args): ViewBase {
const parent = this.parent;
return parent && parent.showModal();
return parent && parent.showModal(...args);
}

public closeModal(): void {
Expand Down

0 comments on commit 451589d

Please sign in to comment.