Skip to content

Commit

Permalink
properly type return of navigateToApp
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 12, 2020
1 parent cd6a2d7 commit b66df7e
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,27 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
}, s);
};

const navigateToApp = async (i: string) => {
return await browser.executeAsync(async (appId, cb: Function) => {
const navigateToApp = async (i: string): Promise<{ error?: string }> => {
return (await browser.executeAsync(async (appId, cb: Function) => {
// navigating in legacy mode performs a page refresh
// and webdriver seems to re-execute the script after the reload
// as it considers it didn't end on the previous session.
// however when testing navigation to NP app, __coreProvider is not accessible
// so we need to check for existence.
if (!window.__coreProvider) {
cb();
cb({});
}
const plugin = window.__coreProvider.start.plugins
.core_app_status as CoreAppStatusPluginStart;
try {
await plugin.navigateToApp(appId);
cb();
cb({});
} catch (e) {
cb(e.message);
cb({
error: e.message,
});
}
}, i);
}, i)) as any;
};

describe('application status management', () => {
Expand Down Expand Up @@ -96,17 +98,19 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
status: AppStatus.inaccessible,
});

const error = await navigateToApp('app_status');
expect(error).to.contain('Trying to navigate to an inaccessible application: app_status');
const result = await navigateToApp('app_status');
expect(result.error).to.contain(
'Trying to navigate to an inaccessible application: app_status'
);
});

it('allows to navigate to an accessible app', async () => {
await setAppStatus({
status: AppStatus.accessible,
});

const error = await navigateToApp('app_status');
expect(error).to.eql(null);
const result = await navigateToApp('app_status');
expect(result.error).to.eql(undefined);
});
});
}

0 comments on commit b66df7e

Please sign in to comment.