-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
175 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @vitest-environment jsdom | ||
import { | ||
vi, | ||
test, | ||
describe, | ||
beforeEach, | ||
afterEach, | ||
expect, | ||
Mock, | ||
} from "vitest"; | ||
import "vitest-dom/extend-expect"; | ||
|
||
import { loader } from "../resources.browserversion"; | ||
import { createFetchResponse, getDefaultContext } from "./testutils"; | ||
|
||
describe("Resources/Browserversion route", () => { | ||
let fetch: Mock; | ||
|
||
beforeEach(() => { | ||
fetch = global.fetch = vi.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
describe("loader", () => { | ||
test("returns valid json", async () => { | ||
fetch.mockResolvedValueOnce( | ||
createFetchResponse({ | ||
data: [ | ||
{ blob6: "Chrome", blob9: "118", count: "5" }, | ||
{ blob6: "Chrome", blob9: "117", count: "15" }, | ||
{ blob6: "Chrome", blob9: "116", count: "1" }, | ||
], | ||
}), | ||
); | ||
|
||
const response = await loader({ | ||
...getDefaultContext(), | ||
// @ts-expect-error we don't need to provide all the properties of the request object | ||
request: { | ||
url: "http://localhost:3000/resources/browserversion?browserName=Chrome", // need browserName query param | ||
}, | ||
}); | ||
|
||
const json = await response; | ||
expect(json).toEqual({ | ||
countsByProperty: [ | ||
["118", 5], | ||
["117", 15], | ||
["116", 1], | ||
], | ||
page: 1, | ||
}); | ||
}); | ||
}); | ||
}); |
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,56 @@ | ||
import { useFetcher } from "@remix-run/react"; | ||
|
||
import type { LoaderFunctionArgs } from "@remix-run/cloudflare"; | ||
|
||
import { getFiltersFromSearchParams, paramsFromUrl } from "~/lib/utils"; | ||
import PaginatedTableCard from "~/components/PaginatedTableCard"; | ||
import { SearchFilters } from "~/lib/types"; | ||
|
||
export async function loader({ context, request }: LoaderFunctionArgs) { | ||
const { analyticsEngine } = context; | ||
|
||
const { interval, site, page = 1 } = paramsFromUrl(request.url); | ||
const url = new URL(request.url); | ||
const tz = url.searchParams.get("timezone") || "UTC"; | ||
const filters = getFiltersFromSearchParams(url.searchParams); | ||
|
||
return { | ||
countsByProperty: await analyticsEngine.getCountByBrowserVersion( | ||
site, | ||
interval, | ||
tz, | ||
filters, | ||
Number(page), | ||
), | ||
page: Number(page), | ||
}; | ||
} | ||
|
||
export const BrowserVersionCard = ({ | ||
siteId, | ||
interval, | ||
filters, | ||
onFilterChange, | ||
timezone, | ||
}: { | ||
siteId: string; | ||
interval: string; | ||
filters: SearchFilters; | ||
onFilterChange: (filters: SearchFilters) => void; | ||
timezone: string; | ||
}) => { | ||
return ( | ||
<PaginatedTableCard | ||
siteId={siteId} | ||
interval={interval} | ||
columnHeaders={["Browser Versions", "Visitors"]} | ||
dataFetcher={useFetcher<typeof loader>()} | ||
loaderUrl="/resources/browserversion" | ||
onClick={(browserVersion) => | ||
onFilterChange({ ...filters, browserVersion }) | ||
} | ||
filters={filters} | ||
timezone={timezone} | ||
/> | ||
); | ||
}; |