Skip to content

Commit

Permalink
test: add tests and test suites around codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilR8 committed Dec 19, 2024
1 parent a3328bc commit eb5ad2a
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const tableSchema = computed(() => {
}
});
// Get column dates from Django template
const getColumnDates = () => {
if (!document.getElementById("site_config")) return {};
Expand All @@ -47,7 +46,7 @@ const getColumnDates = () => {
);
return rawDates;
}
};
const columnDates = getColumnDates();
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from "@testing-library/vue";
import { describe, it, expect } from "vitest";

import TableCaption from "./TableCaption.vue";

describe("Statute Table Caption", () => {
it(`Creates a snapshot of the Statute Selector with default props`, async () => {
const wrapper = render(TableCaption);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<script setup></script>

<template>
<div class="table__caption">
This table shows U.S. Code sections enacted by the Social Security Act.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Statute Table Caption > Creates a snapshot of the Statute Selector with default props 1`] = `
{
"baseElement": <body>
<div>
<div
class="table__caption"
>
This table shows U.S. Code sections enacted by the Social Security Act. See also:
<a
class="external"
href="https://uscode.house.gov/view.xhtml?req=granuleid%3AUSC-prelim-title42-chapter7&saved=%7CZ3JhbnVsZWlkOlVTQy1wcmVsaW0tdGl0bGU0Mi1jaGFwdGVyNy1mcm9udA%3D%3D%7C%7C%7C0%7Cfalse%7Cprelim&edition=prelim"
rel="noopener noreferrer"
target="_blank"
>
full table of contents and text for 42 U.S.C. Chapter 7 (Social Security)
</a>
.
<br />
Learn about these sources:
<a
class="external"
href="https://uscode.house.gov/"
rel="noopener noreferrer"
target="_blank"
>
US Code House.gov
</a>
,
<a
class="external"
href="https://www.govinfo.gov/app/collection/comps/"
rel="noopener noreferrer"
target="_blank"
>
Statute Compilation
</a>
,
<a
class="external"
href="https://www.govinfo.gov/app/collection/uscode"
rel="noopener noreferrer"
target="_blank"
>
US Code Annual
</a>
,
<a
class="external"
href="https://www.ssa.gov/OP_Home/ssact/ssact.htm"
rel="noopener noreferrer"
target="_blank"
>
SSA.gov Compilation
</a>
.
</div>
</div>
</body>,
"container": <div>
<div
class="table__caption"
>
This table shows U.S. Code sections enacted by the Social Security Act. See also:
<a
class="external"
href="https://uscode.house.gov/view.xhtml?req=granuleid%3AUSC-prelim-title42-chapter7&saved=%7CZ3JhbnVsZWlkOlVTQy1wcmVsaW0tdGl0bGU0Mi1jaGFwdGVyNy1mcm9udA%3D%3D%7C%7C%7C0%7Cfalse%7Cprelim&edition=prelim"
rel="noopener noreferrer"
target="_blank"
>
full table of contents and text for 42 U.S.C. Chapter 7 (Social Security)
</a>
.
<br />
Learn about these sources:
<a
class="external"
href="https://uscode.house.gov/"
rel="noopener noreferrer"
target="_blank"
>
US Code House.gov
</a>
,
<a
class="external"
href="https://www.govinfo.gov/app/collection/comps/"
rel="noopener noreferrer"
target="_blank"
>
Statute Compilation
</a>
,
<a
class="external"
href="https://www.govinfo.gov/app/collection/uscode"
rel="noopener noreferrer"
target="_blank"
>
US Code Annual
</a>
,
<a
class="external"
href="https://www.ssa.gov/OP_Home/ssact/ssact.htm"
rel="noopener noreferrer"
target="_blank"
>
SSA.gov Compilation
</a>
.
</div>
</div>,
"debug": [Function],
"emitted": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"html": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import HeaderCell from "./HeaderCell.vue";

describe("Statute Table Header Cell", () => {
describe("SSA table header", () => {
const secondaryCells = ssaSchema.filter((column) => column.header.secondary);
const secondaryCells = ssaSchema.filter(
(column) => column.header.secondary
);

secondaryCells.forEach((column, index) => {
it(`Creates a snapshot of header cell for column ${index + 1} without dates`, async () => {
Expand All @@ -22,7 +24,9 @@ describe("Statute Table Header Cell", () => {
});
await flushPromises();

const dateCell = wrapper.getByTestId(`${column.header.testId}-subtitle-1`).textContent;
const dateCell = wrapper.getByTestId(
`${column.header.testId}-subtitle-1`
).textContent;
expect(dateCell.trim()).toEqual("");

expect(wrapper).toMatchSnapshot();
Expand All @@ -38,7 +42,9 @@ describe("Statute Table Header Cell", () => {
});
await flushPromises();

const dateCell = wrapper.getByTestId(`${column.header.testId}-subtitle-1`).textContent;
const dateCell = wrapper.getByTestId(
`${column.header.testId}-subtitle-1`
).textContent;
expect(dateCell.trim()).toEqual("effective Aug 2023");

expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe("Statute Table URL methods", () => {
});

describe("statuteCompilationUrl", () => {
it("returns null if source_url is undefined", async () => {
const undefinedSourceUrl = { source_url: undefined };
const computedUndefinedUrl =
statuteCompilationUrl(undefinedSourceUrl);
expect(computedUndefinedUrl).toBeNull();
});

it("returns expected URL string if source_url is valid", async () => {
const statuteItem = statutesFixture[0];
const computedUrl = statuteCompilationUrl(statuteItem);
Expand Down

0 comments on commit eb5ad2a

Please sign in to comment.