Skip to content

Commit

Permalink
fest: add Next Run column for tests list table (#251)
Browse files Browse the repository at this point in the history
* fix: schedule time storing format

* feat: update run configuration table with next run
  • Loading branch information
Vitalii Melnychuk authored Mar 2, 2022
1 parent 2278873 commit 57bc63c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Col, Row, Space, Table } from "antd";
import moment from "moment";
import PropTypes from "prop-types";
import React from "react";
import { Link } from "react-router-dom";

import { daysOfTheWeek, toLocalHourMinute } from "../../../lib/date";
import { testSingleUrl } from "../../../lib/routes";

const columns = [
Expand All @@ -12,28 +14,30 @@ const columns = [
key: "title"
},
{
title: "Created",
dataIndex: "createdAt",
key: "createdAt",
title: "Next Run",
dataIndex: "nextRun",
key: "nextRun",
sorter: {
compare: (recordA, recordB) => recordA.createdAt.diff(recordB.createdAt),
compare: (recordA, recordB) => recordA.nextRun.diff(recordB.nextRun),
multiple: 1
},
render: (text, record) => record.createdAt.format("L HH:mm:ss"),
defaultSortOrder: "descend",
render: (text, record) =>
record.nextRun ? record.nextRun.format("L HH:mm") : null,
width: 180
},
{
title: "Updated",
dataIndex: "updatedAt",
key: "updatedAt",
title: "Created",
dataIndex: "createdAt",
key: "createdAt",
sorter: {
compare: (recordA, recordB) => recordA.updatedAt.diff(recordB.updatedAt),
compare: (recordA, recordB) => recordA.createdAt.diff(recordB.createdAt),
multiple: 1
},
render: (text, record) => record.updatedAt.format("L HH:mm:ss"),
render: (text, record) => record.createdAt.format("L HH:mm"),
defaultSortOrder: "descend",
width: 180
},

{
title: "Action",
key: "action",
Expand All @@ -48,22 +52,43 @@ const columns = [
}
];

const findNextRun = (schedule) => {
if (!schedule) return false;

let isDayAvailable = false;
const nextRunningDate = toLocalHourMinute(schedule.time);
const now = moment().local();
while (isDayAvailable === false) {
const dayToLook = daysOfTheWeek[nextRunningDate.day()];

isDayAvailable = schedule.days.includes(dayToLook) && nextRunningDate > now;

if (!isDayAvailable) {
nextRunningDate.add(1, "days");
}
}

return nextRunningDate;
};

const runConfigurationMapper = ({
id,
title,
runPlanId,
createdAt,
updatedAt
schedule
}) => ({
key: id,
title,
runPlanId,
createdAt,
updatedAt
nextRun: findNextRun(schedule),
schedule,
createdAt
});

const RunConfigurationsTable = ({ runConfigurations, isLoading = false }) => {
const dataSource = runConfigurations.map(runConfigurationMapper);

const pagination = {
defaultPageSize: 50,
hideOnSinglePage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe("components/RunConfiguration/Table", () => {
</MemoryRouter>
);

const badgeComponent = rendered.container;
expect(badgeComponent.outerHTML).toMatchSnapshot();
const runConfigurationTableComponent = rendered.container;
expect(runConfigurationTableComponent.outerHTML).toMatchSnapshot();
});

test(`should render RunConfigurationTable loader`, async () => {
Expand All @@ -39,7 +39,56 @@ describe("components/RunConfiguration/Table", () => {
</MemoryRouter>
);

const badgeComponent = rendered.container;
expect(badgeComponent.outerHTML).toMatchSnapshot();
const runConfigurationTableComponent = rendered.container;
expect(runConfigurationTableComponent.outerHTML).toMatchSnapshot();
});

test(`should render RunConfigurationTable nextRun column`, async () => {
const runConfigurationsWithSchedule = [
{
id: "run-configuration-id",
title: "Confgiuration title",
runPlanId: "run-plan-id",
schedule: {
days: ["Thu"],
time: "13:50"
},
createdAt: moment("2018-05-24T13:48:04.313000"),
updatedAt: moment("2018-05-24T13:48:04.313000")
},
{
id: "run-configuration-id",
title: "Confgiuration title",
runPlanId: "run-plan-id",
schedule: {
days: ["Thu"],
time: "13:00"
},
createdAt: moment("2018-05-24T13:48:04.313000"),
updatedAt: moment("2018-05-24T13:48:04.313000")
},
{
id: "run-configuration-id",
title: "Confgiuration title",
runPlanId: "run-plan-id",
schedule: {
days: ["Sun"],
time: "10:00"
},
createdAt: moment("2018-05-24T13:48:04.313000"),
updatedAt: moment("2018-05-24T13:48:04.313000")
}
];
const rendered = render(
<MemoryRouter initialEntries={["/tests"]}>
<RunConfigurationsTable
runConfigurations={runConfigurationsWithSchedule}
isLoading={false}
/>
</MemoryRouter>
);

const runConfigurationTableComponent = rendered.container;
expect(runConfigurationTableComponent.outerHTML).toMatchSnapshot();
});
});
Loading

0 comments on commit 57bc63c

Please sign in to comment.