Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement views for expression metadata #975

Merged
merged 22 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
462799c
WIP(expression-metadata): Implement views for expression metadata
hamo225 Feb 4, 2025
91b9698
Updated API docs
VictorDelCampo Feb 5, 2025
98f93c2
refactor(routes): update route structure and eli handling
hamo225 Feb 6, 2025
c9c40ed
refactor(routes): update expression views
hamo225 Feb 6, 2025
f016798
fix: fix routing for the tree nodes
hamo225 Feb 7, 2025
3769cb3
Backend big refactor done (TOC endpoint missing)
VictorDelCampo Feb 9, 2025
3d0e194
Fix java docs
VictorDelCampo Feb 9, 2025
a6dc967
refactor(tree): remove unused expressionEli from route params
hamo225 Feb 9, 2025
1830d57
test(proprietaryService): update tests to remove atDate dependency
hamo225 Feb 9, 2025
0ca85e3
fix(tree): replace <span> with <button> for improved accessibility an…
hamo225 Feb 10, 2025
a4a28fd
test(e2e): update tests to reflect removal of atDate parameter
hamo225 Feb 10, 2025
9a2be69
TOC endpoint with expression eli
VictorDelCampo Feb 10, 2025
552c41d
feat: add service function for getting table of contents
hamo225 Feb 10, 2025
08c1535
feat(tests): add unit test for useGetNormTableOfContents service func…
hamo225 Feb 11, 2025
45bfb10
feat: Connect new TOC endpoint
hamo225 Feb 11, 2025
c96ac13
fix: align TreeNode type with PrimeVue definition
hamo225 Feb 11, 2025
b5fe44a
Comment back in playright projects
hamo225 Feb 11, 2025
29dccee
fix(tree): preserve selection and expand parents on refresh
hamo225 Feb 11, 2025
604bc4a
fix(tree): fix sonarcube error
hamo225 Feb 11, 2025
aa1cedb
feat(toc): persist selection and expansion on reload
hamo225 Feb 11, 2025
b9e4fd3
fix(e2e): skip failing e2e test to be removed later
hamo225 Feb 12, 2025
b8c70ec
chore: removes old amending law metadata editor views and e2e tests
hamo225 Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(tests): add unit test for useGetNormTableOfContents service func…
…tion

RISDEV-6266
  • Loading branch information
hamo225 committed Feb 12, 2025
commit 08c15355689dc25bf323ef87b3fd77944b025d53
87 changes: 87 additions & 0 deletions frontend/src/services/normService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Norm } from "@/types/norm"
import { TabelOfContentsItem } from "@/types/tableOfContents"
import { flushPromises } from "@vue/test-utils"
import { beforeEach, describe, expect, it, vi } from "vitest"
import { ref } from "vue"
Expand Down Expand Up @@ -386,4 +387,90 @@ describe("useNormService", () => {
)
})
})

describe("useGetNormTableOfContents", () => {
beforeEach(() => {
vi.resetAllMocks()
vi.resetModules()
})

it("fetches the table of contents from the API", async () => {
const fixture: TabelOfContentsItem[] = [
{
id: "1",
marker: "§ 1",
heading: "Article 1",
type: "article",
children: [
{
id: "1.1",
marker: "1.",
heading: "First Point",
type: "section",
children: [],
},
{
id: "1.2",
marker: "2.",
heading: "Second Point",
type: "section",
children: [],
},
],
},
{
id: "2",
marker: "§ 2",
heading: "Inkrafttreten",
type: "article",
children: [],
},
]

const useApiFetch = vi.fn().mockReturnValue({
data: ref(fixture),
json: vi.fn().mockReturnValue({
data: ref(fixture),
}),
execute: vi.fn(),
})

vi.doMock("@/services/apiService", () => ({ useApiFetch }))

const { useGetNormTableOfContents } = await import("./normService")

const result = useGetNormTableOfContents("fake/eli")
expect(result.data.value).toEqual(fixture)

vi.doUnmock("@/services/apiService")
})

it("does not load if the ELI has no value", async () => {
const fetchSpy = vi
.spyOn(window, "fetch")
.mockResolvedValue(new Response("[]"))

const { useGetNormTableOfContents } = await import("./normService")

const eli = ref("")
useGetNormTableOfContents(eli)
await flushPromises()
expect(fetchSpy).not.toHaveBeenCalled()
})

it("reloads with a new ELI value", async () => {
const fetchSpy = vi
.spyOn(window, "fetch")
.mockResolvedValue(new Response("[]"))

const { useGetNormTableOfContents } = await import("./normService")

const eli = ref("fake/eli/1")
useGetNormTableOfContents(eli, { immediate: true, refetch: true })
await vi.waitFor(() => expect(fetchSpy).toHaveBeenCalledTimes(1))

eli.value = "fake/eli/2"
await vi.waitFor(() => expect(fetchSpy).toHaveBeenCalledTimes(2))
})
})
})