Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobgy committed Jan 30, 2020
1 parent 9e3a991 commit 3dd28bd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 34 deletions.
39 changes: 29 additions & 10 deletions frontend/server/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { Storage as GCSStorage } from '@google-cloud/storage';
import { UIServer } from './app';
import { loadConfigs } from './configs';
import * as minioHelper from './minio-helper';
import { getTensorboardInstance } from './k8s-helper';

jest.mock('minio');
jest.mock('node-fetch');
Expand All @@ -46,15 +45,6 @@ describe('UIServer apis', () => {
</script>
<script id="kubeflow-client-placeholder"></script>
</head>
</html>`;
const expectedIndexHtml = `
<html>
<head>
<script>
window.KFP_FLAGS.DEPLOYMENT="KUBEFLOW"
</script>
<script id="kubeflow-client-placeholder" src="/dashboard_lib.bundle.js"></script>
</head>
</html>`;

beforeAll(() => {
Expand Down Expand Up @@ -92,6 +82,15 @@ describe('UIServer apis', () => {
});

it('responds with a modified index.html if it is a kubeflow deployment', done => {
const expectedIndexHtml = `
<html>
<head>
<script>
window.KFP_FLAGS.DEPLOYMENT="KUBEFLOW"
</script>
<script id="kubeflow-client-placeholder" src="/dashboard_lib.bundle.js"></script>
</head>
</html>`;
const configs = loadConfigs(argv, { DEPLOYMENT: 'kubeflow' });
app = new UIServer(configs);

Expand All @@ -101,6 +100,26 @@ describe('UIServer apis', () => {
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(200, expectedIndexHtml, done);
});

it('responds with flag DEPLOYMENT=MARKETPLACE if it is a marketplace deployment', done => {
const expectedIndexHtml = `
<html>
<head>
<script>
window.KFP_FLAGS.DEPLOYMENT="MARKETPLACE"
</script>
<script id="kubeflow-client-placeholder"></script>
</head>
</html>`;
const configs = loadConfigs(argv, { DEPLOYMENT: 'marketplace' });
app = new UIServer(configs);

const request = requests(app.start());
request
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(200, expectedIndexHtml, done);
})
});

describe('/apis/v1beta1/healthz', () => {
Expand Down
4 changes: 3 additions & 1 deletion frontend/server/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ export function loadConfigs(
apiVersionPrefix,
basePath: BASEPATH,
deployment:
DEPLOYMENT_STR.toUpperCase() === 'KUBEFLOW'
DEPLOYMENT_STR.toUpperCase() === Deployments.KUBEFLOW
? Deployments.KUBEFLOW
: DEPLOYMENT_STR.toUpperCase() === Deployments.MARKETPLACE
? Deployments.MARKETPLACE
: Deployments.NOT_SPECIFIED,
port,
staticDir,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import { Route, Switch, Redirect } from 'react-router-dom';
import { classes, stylesheet } from 'typestyle';
import { commonCss } from '../Css';
import NewPipelineVersion from '../pages/NewPipelineVersion';
import { GettingStarted } from 'src/pages/GettingStarted';
import { KFP_FLAGS, Deployments } from 'src/lib/Flags';
import { GettingStarted } from '../pages/GettingStarted';
import { KFP_FLAGS, Deployments } from '../lib/Flags';

export type RouteConfig = { path: string; Component: React.ComponentType<any>; view?: any };

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { RouterProps } from 'react-router';
import { classes, stylesheet } from 'typestyle';
import { fontsize, commonCss } from '../Css';
import { logger } from '../lib/Utils';
import { KFP_FLAGS, Deployments } from 'src/lib/Flags';
import { KFP_FLAGS, Deployments } from '../lib/Flags';

export const sideNavColors = {
bg: '#f8fafb',
Expand Down
38 changes: 22 additions & 16 deletions frontend/src/components/__snapshots__/Router.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,108 @@ exports[`Router initial render 1`] = `
<Route
exact={true}
key="0"
path="/archive"
path="/start"
render={[Function]}
/>
<Route
exact={true}
key="1"
path="/artifacts"
path="/archive"
render={[Function]}
/>
<Route
exact={true}
key="2"
path="/artifact_types/:artifactType+/artifacts/:id"
path="/artifacts"
render={[Function]}
/>
<Route
exact={true}
key="3"
path="/executions"
path="/artifact_types/:artifactType+/artifacts/:id"
render={[Function]}
/>
<Route
exact={true}
key="4"
path="/execution_types/:executionType+/executions/:id"
path="/executions"
render={[Function]}
/>
<Route
exact={true}
key="5"
path="/experiments"
path="/execution_types/:executionType+/executions/:id"
render={[Function]}
/>
<Route
exact={true}
key="6"
path="/experiments/details/:eid"
path="/experiments"
render={[Function]}
/>
<Route
exact={true}
key="7"
path="/experiments/new"
path="/experiments/details/:eid"
render={[Function]}
/>
<Route
exact={true}
key="8"
path="/pipeline_versions/new"
path="/experiments/new"
render={[Function]}
/>
<Route
exact={true}
key="9"
path="/runs/new"
path="/pipeline_versions/new"
render={[Function]}
/>
<Route
exact={true}
key="10"
path="/pipelines"
path="/runs/new"
render={[Function]}
/>
<Route
exact={true}
key="11"
path="/pipelines/details/:pid/version/:vid?"
path="/pipelines"
render={[Function]}
/>
<Route
exact={true}
key="12"
path="/pipelines/details/:pid?"
path="/pipelines/details/:pid/version/:vid?"
render={[Function]}
/>
<Route
exact={true}
key="13"
path="/runs"
path="/pipelines/details/:pid?"
render={[Function]}
/>
<Route
exact={true}
key="14"
path="/recurringrun/details/:rid"
path="/runs"
render={[Function]}
/>
<Route
exact={true}
key="15"
path="/runs/details/:rid"
path="/recurringrun/details/:rid"
render={[Function]}
/>
<Route
exact={true}
key="16"
path="/runs/details/:rid"
render={[Function]}
/>
<Route
exact={true}
key="17"
path="/compare"
render={[Function]}
/>
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/lib/Flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ export enum Deployments {
export const KFP_FLAGS = {
DEPLOYMENT:
// tslint:disable-next-line:no-string-literal
window && window['KFP_FLAGS'] && window['KFP_FLAGS']['DEPLOYMENT'] === Deployments.KUBEFLOW
? Deployments.KUBEFLOW
window && window['KFP_FLAGS']
// tslint:disable-next-line:no-string-literal
: window['KFP_FLAGS']['DEPLOYMENT'] === Deployments.MARKETPLACE
? Deployments.MARKETPLACE
? window['KFP_FLAGS']['DEPLOYMENT'] === Deployments.KUBEFLOW
? Deployments.KUBEFLOW
// tslint:disable-next-line:no-string-literal
: window['KFP_FLAGS']['DEPLOYMENT'] === Deployments.MARKETPLACE
? Deployments.MARKETPLACE
: undefined
: undefined,
};

0 comments on commit 3dd28bd

Please sign in to comment.