-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI] deep links to pipeline details page from start page (#3086)
* [UI] deep links to pipeline details page from start page * Fix * Update GettingStarted.tsx * Update GettingStarted.tsx * Update GettingStarted.tsx * Adjust format to improve readability * Use react-testing-library for getting started page tests * Add error case unit tests * Frontend import sample config from jsonn and presubmit test to verify configs are synced * Update presubmit test error message * Changed to sync only sample_config.json name to frontend * Improve error message * Fix tests
- Loading branch information
Showing
12 changed files
with
711 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This should be run in pipelines/frontend folder. | ||
|
||
const PATH_BACKEND_CONFIG = '../../backend/src/apiserver/config/sample_config.json'; | ||
const PATH_FRONTEND_CONFIG = 'src/config/sample_config_from_backend.json'; | ||
|
||
const fs = require('fs'); | ||
const backendConfig = require(PATH_BACKEND_CONFIG); | ||
const frontendConfig = backendConfig.map(sample => sample.name); | ||
const content = JSON.stringify(frontendConfig, null, 2) + '\n'; | ||
fs.writeFileSync(PATH_FRONTEND_CONFIG, content); | ||
console.log(`Synced ${PATH_BACKEND_CONFIG} to ${PATH_FRONTEND_CONFIG}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
"[Demo] XGBoost - Training with Confusion Matrix", | ||
"[Demo] TFX - Taxi Tip Prediction Model Trainer", | ||
"[Tutorial] Data passing in python components", | ||
"[Tutorial] DSL - Control structures" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React from 'react'; | ||
import { GettingStarted } from './GettingStarted'; | ||
import TestUtils, { formatHTML } from '../TestUtils'; | ||
import { render } from '@testing-library/react'; | ||
import { PageProps } from './Page'; | ||
import { Apis } from '../lib/Apis'; | ||
import { ApiListPipelinesResponse } from 'src/apis/pipeline/api'; | ||
import snapshotDiff from 'snapshot-diff'; | ||
|
||
const PATH_BACKEND_CONFIG = '../../../backend/src/apiserver/config/sample_config.json'; | ||
const PATH_FRONTEND_CONFIG = '../config/sample_config_from_backend.json'; | ||
describe(`${PATH_FRONTEND_CONFIG}`, () => { | ||
it(`should be in sync with ${PATH_BACKEND_CONFIG}, if not please run "npm run sync-backend-sample-config" to update.`, () => { | ||
const configBackend = require(PATH_BACKEND_CONFIG); | ||
const configFrontend = require(PATH_FRONTEND_CONFIG); | ||
expect(configFrontend).toEqual(configBackend.map((sample: any) => sample.name)); | ||
}); | ||
}); | ||
|
||
describe('GettingStarted page', () => { | ||
const updateBannerSpy = jest.fn(); | ||
const updateToolbarSpy = jest.fn(); | ||
const historyPushSpy = jest.fn(); | ||
const pipelineListSpy = jest.spyOn(Apis.pipelineServiceApi, 'listPipelines'); | ||
|
||
function generateProps(): PageProps { | ||
return TestUtils.generatePageProps( | ||
GettingStarted, | ||
{} as any, | ||
{} as any, | ||
historyPushSpy, | ||
updateBannerSpy, | ||
null, | ||
updateToolbarSpy, | ||
null, | ||
); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
const empty: ApiListPipelinesResponse = { | ||
pipelines: [], | ||
total_size: 0, | ||
}; | ||
pipelineListSpy.mockImplementation(() => Promise.resolve(empty)); | ||
}); | ||
|
||
it('initially renders documentation', () => { | ||
const { container } = render(<GettingStarted {...generateProps()} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders documentation with pipeline deep link after querying demo pipelines', async () => { | ||
let count = 0; | ||
pipelineListSpy.mockImplementation(() => { | ||
++count; | ||
const response: ApiListPipelinesResponse = { | ||
pipelines: [{ id: `pipeline-id-${count}` }], | ||
}; | ||
return Promise.resolve(response); | ||
}); | ||
const { container } = render(<GettingStarted {...generateProps()} />); | ||
const initialHtml = container.innerHTML; | ||
await TestUtils.flushPromises(); | ||
expect(pipelineListSpy.mock.calls).toMatchSnapshot(); | ||
expect( | ||
snapshotDiff(formatHTML(initialHtml), formatHTML(container.innerHTML)), | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it('fallbacks to show pipeline list page if request failed', async () => { | ||
let count = 0; | ||
pipelineListSpy.mockImplementation( | ||
(): Promise<ApiListPipelinesResponse> => { | ||
++count; | ||
if (count === 1) { | ||
return Promise.reject(new Error('Mocked error')); | ||
} else if (count === 2) { | ||
// incomplete data | ||
return Promise.resolve({}); | ||
} else if (count === 3) { | ||
// empty data | ||
return Promise.resolve({ pipelines: [], total_size: 0 }); | ||
} | ||
return Promise.resolve({ | ||
pipelines: [{ id: `pipeline-id-${count}` }], | ||
total_size: 1, | ||
}); | ||
}, | ||
); | ||
const { container } = render(<GettingStarted {...generateProps()} />); | ||
const initialHtml = container.innerHTML; | ||
await TestUtils.flushPromises(); | ||
expect( | ||
snapshotDiff(formatHTML(initialHtml), formatHTML(container.innerHTML)), | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.