Skip to content

Commit d9199e9

Browse files
committed
TestVariationPage added
1 parent 68d36d2 commit d9199e9

File tree

9 files changed

+140
-4
lines changed

9 files changed

+140
-4
lines changed

src/Router.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PrivateRoute from "./components/PrivateRoute";
77
import { routes } from "./constants";
88
import RegisterPage from "./pages/RegisterPage";
99
import ProfilePage from "./pages/ProfilePage";
10+
import TestVariationPage from "./pages/TestVariationPage";
1011

1112
function Router() {
1213
return (
@@ -28,6 +29,11 @@ function Router() {
2829
path={`${routes.HOME}:projectId`}
2930
component={() => <ProjectPage />}
3031
/>
32+
<PrivateRoute
33+
exact
34+
path={`${routes.VARIATION_LIST_PAGE}/:projectId`}
35+
component={() => <TestVariationPage />}
36+
/>
3137
<PrivateRoute
3238
exact
3339
path={`${routes.HOME}`}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from "react";
2+
import { TestVariation } from "../types";
3+
import {
4+
Card,
5+
Grid,
6+
CardMedia,
7+
CardContent,
8+
Typography,
9+
makeStyles,
10+
} from "@material-ui/core";
11+
import { staticService } from "../services";
12+
13+
interface IProps {
14+
items: TestVariation[];
15+
}
16+
17+
const useStyles = makeStyles({
18+
card: {
19+
maxWidth: 345,
20+
},
21+
media: {
22+
height: 140,
23+
},
24+
});
25+
26+
const TestVariationList: React.FunctionComponent<IProps> = ({ items }) => {
27+
const classes = useStyles();
28+
29+
return (
30+
<Grid container>
31+
{items.map((t) => (
32+
<Grid item key={t.id} xs={4}>
33+
<Card className={classes.card}>
34+
<CardMedia
35+
className={classes.media}
36+
image={staticService.getImage(t.baselineName)}
37+
title={t.name}
38+
/>
39+
<CardContent>
40+
<Typography>{t.name}</Typography>
41+
42+
<Grid container spacing={2}>
43+
<Grid item>
44+
<Typography>OS: {t.os}</Typography>
45+
</Grid>
46+
<Grid item>
47+
<Typography>Browser: {t.browser}</Typography>
48+
</Grid>
49+
<Grid item>
50+
<Typography>Viewport: {t.viewport}</Typography>
51+
</Grid>
52+
</Grid>
53+
</CardContent>
54+
</Card>
55+
</Grid>
56+
))}
57+
</Grid>
58+
);
59+
};
60+
61+
export default TestVariationList;

src/constants/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export const routes = {
77
HOME: "/",
88
PROFILE_PAGE: "/profile",
99
PROJECT_LIST_PAGE: "/projects",
10-
// PROJECT: "/project",
10+
VARIATION_LIST_PAGE: "/variations",
1111
};

src/pages/ProjectListPage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from "../contexts/project.context";
2828
import { Link } from "react-router-dom";
2929
import { Delete, Add } from "@material-ui/icons";
30+
import { routes } from "../constants";
3031

3132
const ProjectsListPage = () => {
3233
const theme = useTheme();
@@ -122,6 +123,13 @@ const ProjectsListPage = () => {
122123
</CardContent>
123124
</CardActionArea>
124125
<CardActions>
126+
<Button
127+
color="primary"
128+
component={Link}
129+
to={`${routes.VARIATION_LIST_PAGE}/${project.id}`}
130+
>
131+
Variations
132+
</Button>
125133
<IconButton
126134
onClick={(event: React.MouseEvent<HTMLElement>) => {
127135
deleteProject(projectDispatch, project.id);

src/pages/ProjectPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import { Grid, Dialog, IconButton, Box } from "@material-ui/core";
2+
import { Grid, Dialog, IconButton, Box, Typography } from "@material-ui/core";
33
import { useParams, useLocation, useHistory } from "react-router-dom";
44
import { Build, TestRun } from "../types";
55
import { projectsService, buildsService, testsService } from "../services";
@@ -119,6 +119,7 @@ const ProjectPage = () => {
119119
<Grid item xs={3}>
120120
<Grid container direction="column">
121121
<Grid item>
122+
<Typography display="inline">Project: </Typography>
122123
<ProjectSelect selectedId={projectId} />
123124
</Grid>
124125
</Grid>

src/pages/TestVariationPage.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import TestVariationList from "../components/TestVariationList";
3+
import { useParams } from "react-router-dom";
4+
import { TestVariation } from "../types";
5+
import { testVariationService } from "../services";
6+
import { Container, Box, Grid, Typography } from "@material-ui/core";
7+
import ProjectSelect from "../components/ProjectSelect";
8+
9+
const TestVariationPage: React.FunctionComponent = () => {
10+
const { projectId } = useParams();
11+
const [testVariations, setTestVariations] = React.useState<TestVariation[]>(
12+
[]
13+
);
14+
15+
React.useEffect(() => {
16+
if (projectId) {
17+
testVariationService.get(projectId).then((testVariations) => {
18+
setTestVariations(testVariations);
19+
});
20+
}
21+
}, [projectId]);
22+
23+
return (
24+
<React.Fragment>
25+
<Container>
26+
<Box mt={2}>
27+
<Grid container direction="column" spacing={2}>
28+
<Grid item>
29+
<Typography display="inline">Project: </Typography>
30+
<ProjectSelect selectedId={projectId} />
31+
</Grid>
32+
<Grid item>
33+
<TestVariationList items={testVariations} />
34+
</Grid>
35+
</Grid>
36+
</Box>
37+
</Container>
38+
</React.Fragment>
39+
);
40+
};
41+
42+
export default TestVariationPage;

src/services/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './users.service';
22
export * from './projects.service'
33
export * from './builds.service'
44
export * from './tests.service'
5-
export * from './static.service'
5+
export * from './static.service'
6+
export * from './testVariation.service'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestVariation } from "../types";
2+
import { handleResponse, authHeader } from "../_helpers/service.helpers";
3+
import { API_URL } from "../_config/api.config";
4+
5+
export const testVariationService = {
6+
get,
7+
};
8+
9+
function get(projectId: String): Promise<TestVariation[]> {
10+
const requestOptions = {
11+
method: "GET",
12+
headers: authHeader(),
13+
};
14+
15+
return fetch(`${API_URL}/test-variations?projectId=${projectId}`, requestOptions).then(handleResponse);
16+
}

src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './user'
22
export * from './project'
33
export * from './build'
4-
export * from './testRun'
4+
export * from './testRun'
5+
export * from './testVariation'

0 commit comments

Comments
 (0)