-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(frontend): Adding Test Execution Deep Link (#2747)
- Loading branch information
Showing
12 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
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,23 @@ | ||
import {useParams} from 'react-router-dom'; | ||
|
||
import Layout from 'components/Layout'; | ||
import TestSpecFormProvider from 'components/TestSpecForm/TestSpecForm.provider'; | ||
import withAnalytics from 'components/WithAnalytics/WithAnalytics'; | ||
import TestProvider from 'providers/Test/Test.provider'; | ||
import Content from './Content'; | ||
|
||
const AutomatedTestRun = () => { | ||
const {testId = '', version = '1'} = useParams(); | ||
|
||
return ( | ||
<Layout hasMenu> | ||
<TestProvider testId={testId} version={Number(version)}> | ||
<TestSpecFormProvider testId={testId}> | ||
<Content /> | ||
</TestSpecFormProvider> | ||
</TestProvider> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default withAnalytics(AutomatedTestRun, 'automated-test-run'); |
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,17 @@ | ||
import {useEffect} from 'react'; | ||
import {useSearchParams} from 'react-router-dom'; | ||
import useAutomatedTestRun from './hooks/useAutomatedTestRun'; | ||
import TestContent from '../Test/Content'; | ||
|
||
const Content = () => { | ||
const [query] = useSearchParams(); | ||
const onAutomatedRun = useAutomatedTestRun(query); | ||
|
||
useEffect(() => { | ||
onAutomatedRun(); | ||
}, [onAutomatedRun]); | ||
|
||
return <TestContent />; | ||
}; | ||
|
||
export default Content; |
41 changes: 41 additions & 0 deletions
41
web/src/pages/AutomatedTestRun/hooks/useAutomatedTestRun.ts
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,41 @@ | ||
import {useCallback} from 'react'; | ||
import {TEnvironmentValue} from 'models/Environment.model'; | ||
import {useTest} from 'providers/Test/Test.provider'; | ||
import {useEnvironment} from 'providers/Environment/Environment.provider'; | ||
import {useNavigate} from 'react-router-dom'; | ||
|
||
const getParsedVariables = (rawVars: string): TEnvironmentValue[] => { | ||
try { | ||
const variables = JSON.parse(rawVars) as TEnvironmentValue[]; | ||
|
||
return Array.isArray(variables) ? variables : []; | ||
} catch (err) { | ||
return []; | ||
} | ||
}; | ||
|
||
const useAutomatedTestRun = (query: URLSearchParams) => { | ||
const { | ||
onRun, | ||
test: {id: testId}, | ||
} = useTest(); | ||
const {selectedEnvironment} = useEnvironment(); | ||
const navigate = useNavigate(); | ||
|
||
const onAutomatedRun = useCallback(() => { | ||
const variables = getParsedVariables(query.get('variables') ?? '[]'); | ||
const environmentId = query.get('environmentId') ?? selectedEnvironment?.id; | ||
|
||
onRun({ | ||
variables, | ||
environmentId, | ||
onCancel() { | ||
navigate(`/test/${testId}`, {replace: true}); | ||
}, | ||
}); | ||
}, [navigate, onRun, query, selectedEnvironment?.id, testId]); | ||
|
||
return onAutomatedRun; | ||
}; | ||
|
||
export default useAutomatedTestRun; |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export {default} from './AutomatedTestRun'; |
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
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