Skip to content

Commit

Permalink
Sort uptime monitors by alphabetical order (#58)
Browse files Browse the repository at this point in the history
Display uptime monitors in alphabetical order
  • Loading branch information
shairyar authored Mar 16, 2023
1 parent 90ce505 commit 09de3f6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/UptimeMonitor/UptimeMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const UptimeMonitor = ({ uptimeMonitor, threshold }) => {

return (
<>
<div className="px-6 py-5 space-y-3">
<div className="px-6 py-5 space-y-3" data-testid="UptimeMonitor">
<div className="sm:flex justify-between">
<h2>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`UptimeMonitor renders without errors 1`] = `
<div>
<div
class="px-6 py-5 space-y-3"
data-testid="UptimeMonitor"
>
<div
class="sm:flex justify-between"
Expand Down
3 changes: 3 additions & 0 deletions components/UptimeMonitors/UptimeMonitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import PropTypes from "prop-types";
import UptimeMonitor from "../UptimeMonitor";

const UptimeMonitors = ({ statusPage }) => {
// Display uptime monitors in alphabetical order
statusPage.uptime_monitors.sort((a, b) => a.title.localeCompare(b.title));

const renderUptimeMonitors = () => {
if (statusPage.uptime_monitors.length === 0) {
return (
Expand Down
16 changes: 16 additions & 0 deletions components/UptimeMonitors/UptimeMonitors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import UptimeMonitors from "./UptimeMonitors";

import statusPageMock from "../../mocks/status_pages/appsignal.json";

import multipleMonitorsMock from "../../mocks/monitors/multiple.json";

const build = (props = {}) => {
return render(<UptimeMonitors statusPage={statusPageMock} {...props} />);
};
Expand Down Expand Up @@ -40,4 +42,18 @@ describe("UptimeMonitors", () => {
expect(screen.getByText("Always Down")).toBeInTheDocument();
});
});

test("should render uptime monitors sorted by title", () => {
const statusPage = { ...statusPageMock };

statusPage.uptime_monitors = multipleMonitorsMock.uptime_monitors;

build({ statusPage });

const updates = screen.getAllByTestId("UptimeMonitor");

expect(updates[0].querySelector("h2").innerHTML).toContain("Always Down");
expect(updates[1].querySelector("h2").innerHTML).toContain("blog");
expect(updates[2].querySelector("h2").innerHTML).toContain("homepage");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`UptimeMonitors renders without problems 1`] = `
>
<div
class="px-6 py-5 space-y-3"
data-testid="UptimeMonitor"
>
<div
class="sm:flex justify-between"
Expand All @@ -21,7 +22,7 @@ exports[`UptimeMonitors renders without problems 1`] = `
<button
class="c_h-heading focus:outline-none"
>
homepage
Always Down
</button>
</h2>
<p
Expand Down Expand Up @@ -160,6 +161,7 @@ exports[`UptimeMonitors renders without problems 1`] = `
</div>
<div
class="px-6 py-5 space-y-3"
data-testid="UptimeMonitor"
>
<div
class="sm:flex justify-between"
Expand Down Expand Up @@ -307,6 +309,7 @@ exports[`UptimeMonitors renders without problems 1`] = `
</div>
<div
class="px-6 py-5 space-y-3"
data-testid="UptimeMonitor"
>
<div
class="sm:flex justify-between"
Expand All @@ -315,7 +318,7 @@ exports[`UptimeMonitors renders without problems 1`] = `
<button
class="c_h-heading focus:outline-none"
>
Always Down
homepage
</button>
</h2>
<p
Expand Down
28 changes: 28 additions & 0 deletions mocks/monitors/multiple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"uptime_monitors": [
{
"id": "blog",
"title": "blog",
"url": "https://blog.appsignal.com",
"description": "",
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/blog.json"
},
{
"id": "homepage",
"title": "homepage",
"url": "https://www.appsignal.com",
"description": "The AppSignal homepage. Notify #operations when this alert is triggered. ",
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/homepage.json"
},
{
"id": "always-down",
"title": "Always Down",
"url": "https://banana.appsignal.com",
"description": "This endpoint will always be down!",
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/always-down.json"
}
]
}

0 comments on commit 09de3f6

Please sign in to comment.