Skip to content

Commit

Permalink
Upstreamed all pipeline changes till 2020-03-06. Tackles kubeflow#217 k…
Browse files Browse the repository at this point in the history
  • Loading branch information
avdaredevil committed Mar 6, 2020
1 parent edb7276 commit 1bb0a30
Show file tree
Hide file tree
Showing 22 changed files with 3,044 additions and 999 deletions.
695 changes: 662 additions & 33 deletions frontend/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.isfunction": "^3.0.6",
"@types/node": "^12.0.2",
"@types/prettier": "^1.19.0",
"@types/react": "^16.8.18",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^4.3.1",
Expand All @@ -31,7 +32,9 @@
"enzyme-to-json": "^3.3.5",
"eslint-plugin-import": "^2.18.2",
"license-checker": "^25.0.1",
"prettier": "^1.19.1",
"react-router-test-context": "^0.1.0",
"snapshot-diff": "^0.7.0",
"typescript": "^3.4.5"
},
"scripts": {
Expand Down
25 changes: 8 additions & 17 deletions frontend/src/Css.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
import {NestedCSSProperties} from 'typestyle/lib/types';
import {style, stylesheet} from 'typestyle';
import {NestedCSSProperties} from 'typestyle/lib/types';

export const color = {
activeBg: '#eaf1fd',
Expand Down Expand Up @@ -72,6 +72,7 @@ export const fontsize = {
medium: 16,
large: 18,
title: 18,
pageTitle: 24,
};
// tslint:enable:object-literal-sort-keys

Expand Down Expand Up @@ -122,7 +123,7 @@ export const theme = createMuiTheme({
},
color: color.theme,
marginRight: 10,
padding: '0 8px'
padding: '0 8px',
},
},
MuiDialogActions: {
Expand Down Expand Up @@ -162,7 +163,7 @@ export const theme = createMuiTheme({
},
MuiInput: {
input: { padding: 0 },
root: { padding: 0 }
root: { padding: 0 },
},
MuiInputAdornment: {
positionEnd: {
Expand All @@ -175,13 +176,13 @@ export const theme = createMuiTheme({
backgroundColor: '#666',
color: '#f1f1f1',
fontSize: 12,
}
},
},
},
palette,
typography: {
fontFamily: fonts.main,
fontSize: fontsize.base + ' !important' as any,
fontSize: (fontsize.base + ' !important') as any,
useNextVariants: true,
},
});
Expand Down Expand Up @@ -219,15 +220,6 @@ export const commonCss = stylesheet({
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
fit: {
bottom: 0,
height: '100%',
left: 0,
position: 'absolute',
right: 0,
top: 0,
width: '100%',
},
flex: {
alignItems: 'center !important',
display: 'flex !important',
Expand Down Expand Up @@ -256,7 +248,7 @@ export const commonCss = stylesheet({
infoIcon: {
color: color.lowContrast,
height: 16,
width: 16
width: 16,
},
link: {
$nest: {
Expand Down Expand Up @@ -289,8 +281,7 @@ export const commonCss = stylesheet({
whiteSpace: 'pre-wrap',
},
scrollContainer: {
background:
`linear-gradient(white 30%, rgba(255,255,255,0)),
background: `linear-gradient(white 30%, rgba(255,255,255,0)),
linear-gradient(rgba(255,255,255,0), white 70%) 0 100%,
radial-gradient(farthest-corner at 50% 0, rgba(0,0,0,.2), rgba(0,0,0,0)),
radial-gradient(farthest-corner at 50% 100%, rgba(0,0,0,.2), rgba(0,0,0,0)) 0 100%`,
Expand Down
139 changes: 0 additions & 139 deletions frontend/src/TestUtils.ts

This file was deleted.

154 changes: 154 additions & 0 deletions frontend/src/TestUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable */
// Because this is test utils.

import * as React from 'react';
// @ts-ignore
import createRouterContext from 'react-router-test-context';
import { PageProps, Page } from './pages/Page';
import { ToolbarActionConfig } from './components/Toolbar';
import { match } from 'react-router';
import { mount, ReactWrapper } from 'enzyme';
import { object } from 'prop-types';
import { format } from 'prettier';
import snapshotDiff from 'snapshot-diff';

export default class TestUtils {
/**
* Mounts the given component with a fake router and returns the mounted tree
*/
// tslint:disable-next-line:variable-name
public static mountWithRouter(component: React.ReactElement<any>): ReactWrapper {
const childContextTypes = {
router: object,
};
const context = createRouterContext();
const tree = mount(component, { context, childContextTypes });
return tree;
}

/**
* Flushes all already queued promises and returns a promise. Note this will
* only work if the promises have already been queued, so it cannot be used to
* wait on a promise that hasn't been dispatched yet.
*/
public static flushPromises(): Promise<void> {
return new Promise(resolve => setImmediate(resolve));
}

/**
* Adds a one-time mock implementation to the provided spy that mimics an error
* network response
*/
public static makeErrorResponseOnce(spy: jest.MockInstance<unknown, unknown[]>, message: string): void {
spy.mockImplementationOnce(() => {
throw {
text: () => Promise.resolve(message),
};
});
}

/**
* Generates a customizable PageProps object that can be passed to initialize
* Page components, taking care of setting ToolbarProps properly, which have
* to be set after component initialization.
*/
// tslint:disable-next-line:variable-name
public static generatePageProps(
PageElement: new (_: PageProps) => Page<any, any>,
location: Location,
matchValue: match,
historyPushSpy: jest.SpyInstance<unknown> | null,
updateBannerSpy: jest.SpyInstance<unknown> | null,
updateDialogSpy: jest.SpyInstance<unknown> | null,
updateToolbarSpy: jest.SpyInstance<unknown> | null,
updateSnackbarSpy: jest.SpyInstance<unknown> | null,
): PageProps {
const pageProps = {
history: { push: historyPushSpy } as any,
location: location as any,
match: matchValue,
toolbarProps: { actions: {}, breadcrumbs: [], pageTitle: '' },
updateBanner: updateBannerSpy as any,
updateDialog: updateDialogSpy as any,
updateSnackbar: updateSnackbarSpy as any,
updateToolbar: updateToolbarSpy as any,
} as PageProps;
pageProps.toolbarProps = new PageElement(pageProps).getInitialToolbarState();
// The toolbar spy gets called in the getInitialToolbarState method, reset it
// in order to simplify tests
if (updateToolbarSpy) {
updateToolbarSpy.mockReset();
}
return pageProps;
}

public static getToolbarButton(
updateToolbarSpy: jest.SpyInstance<unknown>,
buttonKey: string,
): ToolbarActionConfig {
const lastCallIdx = updateToolbarSpy.mock.calls.length - 1;
const lastCall = updateToolbarSpy.mock.calls[lastCallIdx][0];
return lastCall.actions[buttonKey];
}
}

/**
* Generate diff text for two HTML strings.
* Recommend providing base and update annotations to clarify context in the diff directly.
*/
export function diffHTML({
base,
update,
baseAnnotation,
updateAnnotation,
}: {
base: string;
baseAnnotation?: string;
update: string;
updateAnnotation?: string;
}) {
return diff({
base: formatHTML(base),
update: formatHTML(update),
baseAnnotation,
updateAnnotation,
});
}

export function diff({
base,
update,
baseAnnotation,
updateAnnotation,
}: {
base: string;
baseAnnotation?: string;
update: string;
updateAnnotation?: string;
}) {
return snapshotDiff(base, update, {
stablePatchmarks: true, // Avoid line numbers in diff, so that diffs are stable against irrelevant changes
aAnnotation: baseAnnotation,
bAnnotation: updateAnnotation,
});
}

function formatHTML(html: string): string {
return format(html, { parser: 'html' });
}
Loading

0 comments on commit 1bb0a30

Please sign in to comment.