-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import ToggleableInput from "$lib/components/composites/input/ToggleableInput.svelte"; | ||
import { render, screen } from "@testing-library/svelte"; | ||
import { keyboard } from "@testing-library/user-event/dist/cjs/setup/directApi.js"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
describe("ToggleableInput", () => { | ||
test("When isEditable is set to true, then input border is shown and content can be edited", async () => { | ||
render(ToggleableInput, { | ||
target: document.body, | ||
props: { | ||
isEditable: true, | ||
value: "", | ||
}, | ||
}); | ||
|
||
const input = screen.getByRole("textbox"); | ||
expect(input).toBeInTheDocument(); | ||
|
||
expect(input.classList.contains("border")).toBe(true); | ||
expect(input.classList.contains("border-input")).toBe(true); | ||
expect(input.classList.contains("rounded-md")).toBe(true); | ||
expect(input.classList.contains("border-transparent")).toBe(false); | ||
|
||
expect(input).not.toHaveAttribute("readonly"); | ||
|
||
await keyboard("Test"); | ||
|
||
expect(input).not.toHaveValue("Test"); | ||
expect(input).toHaveValue(""); | ||
}); | ||
|
||
test("When isEditable is set to false, then input border is not shown and content cannot be edited", () => { | ||
render(ToggleableInput, { | ||
target: document.body, | ||
props: { | ||
isEditable: false, | ||
}, | ||
}); | ||
|
||
const input = screen.getByRole("textbox"); | ||
expect(input).toBeInTheDocument(); | ||
|
||
expect(input.classList.contains("border")).toBe(true); | ||
expect(input.classList.contains("border-input")).toBe(false); | ||
expect(input.classList.contains("rounded-md")).toBe(false); | ||
expect(input.classList.contains("border-transparent")).toBe(true); | ||
|
||
expect(input).toHaveAttribute("readonly"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import PaperDetailsCard from "$lib/components/composites/paper-components/paper-view/cards/PaperDetailsCard.svelte"; | ||
import { render, screen, waitFor } from "@testing-library/svelte"; | ||
import { describe, expect, test } from "vitest"; | ||
import { createPaper } from "../../../../model-builder"; | ||
import { waitForComponentLoading } from "../../../test-helper"; | ||
import userEvent from "@testing-library/user-event"; | ||
import type { Paper } from "$lib/model/backend"; | ||
|
||
describe("PaperDetailsCard", () => { | ||
test("When props are provided, then component is shown", async () => { | ||
render(PaperDetailsCard, { | ||
target: document.body, | ||
props: { | ||
loadingPaper: Promise.resolve(createPaper()), | ||
allowEditModeToggle: true, | ||
startInEditMode: false, | ||
showButtonBar: true, | ||
}, | ||
}); | ||
|
||
await waitForComponentLoading(); | ||
|
||
const card = screen.getByTestId("paper-details-card"); | ||
expect(card).toBeInTheDocument(); | ||
|
||
// edit mode can be toggled | ||
const editButtons = document.getElementsByTagName("svg"); | ||
let editButtonCount = 0; | ||
for (const editButton of editButtons) { | ||
if (!editButton.classList.contains("lucide-pencil")) { | ||
continue; | ||
} | ||
|
||
expect(editButton).toBeInTheDocument(); | ||
editButtonCount++; | ||
} | ||
expect(editButtonCount).toBe(2); | ||
|
||
// paper details are in read-only mode | ||
const paperDetails = screen.queryAllByTestId("paper-details"); | ||
expect(paperDetails).toHaveLength(5); | ||
Check failure on line 41 in tests/integration/paper-components/paper-view/cards/paper-details-card.test.ts GitHub Actions / Integration Testing with Vitesttests/integration/paper-components/paper-view/cards/paper-details-card.test.ts > PaperDetailsCard > When props are provided, then component is shown
|
||
for (const paperDetail of paperDetails) { | ||
expect(paperDetail).toBeInTheDocument(); | ||
const input = paperDetail.getElementsByTagName("textarea")[0]; | ||
expect(input).toHaveAttribute("readonly"); | ||
} | ||
|
||
// additional details are not shown by default | ||
const buttons = screen | ||
.queryAllByRole("button") | ||
.filter((button) => button.textContent === "Show more information"); | ||
expect(buttons).toHaveLength(1); | ||
const showMoreButton = buttons[0]; | ||
expect(showMoreButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("When show more information button is pressed, then additional details are shown", async () => { | ||
const user = userEvent.setup(); | ||
render(PaperDetailsCard, { | ||
target: document.body, | ||
props: { | ||
loadingPaper: Promise.resolve(createPaper()), | ||
allowEditModeToggle: true, | ||
startInEditMode: false, | ||
showButtonBar: true, | ||
}, | ||
}); | ||
|
||
await waitForComponentLoading(); | ||
|
||
const buttons = screen | ||
.queryAllByRole("button") | ||
.filter((button) => button.textContent === "Show more information"); | ||
expect(buttons).toHaveLength(1); | ||
Check failure on line 74 in tests/integration/paper-components/paper-view/cards/paper-details-card.test.ts GitHub Actions / Integration Testing with Vitesttests/integration/paper-components/paper-view/cards/paper-details-card.test.ts > PaperDetailsCard > When show more information button is pressed, then additional details are shown
|
||
const showMoreButton = buttons[0]; | ||
expect(showMoreButton).toBeInTheDocument(); | ||
|
||
await user.click(showMoreButton); | ||
|
||
await waitFor(() => { | ||
const paperDetails = screen.queryAllByTestId("paper-details"); | ||
expect(paperDetails).toHaveLength(8); | ||
}); | ||
|
||
expect(showMoreButton).toHaveTextContent("Show less information"); | ||
}); | ||
|
||
test("When edit mode is toggled, then paper details are in edit mode", async () => { | ||
const user = userEvent.setup(); | ||
render(PaperDetailsCard, { | ||
target: document.body, | ||
props: { | ||
loadingPaper: Promise.resolve(createPaper()), | ||
allowEditModeToggle: true, | ||
startInEditMode: false, | ||
showButtonBar: true, | ||
}, | ||
}); | ||
|
||
await waitForComponentLoading(); | ||
|
||
const svgs = document.getElementsByTagName("svg"); | ||
const editButtons: SVGSVGElement[] = []; | ||
for (const svg of svgs) { | ||
if (svg.classList.contains("lucide-pencil")) { | ||
editButtons.push(svg); | ||
} | ||
} | ||
expect(editButtons.length).toBe(2); | ||
|
||
const generalInfoBtn = editButtons[0]; | ||
const abstractBtn = editButtons[1]; | ||
|
||
await user.click(generalInfoBtn); | ||
|
||
await waitFor(() => { | ||
const paperDetails = screen.queryAllByTestId("paper-details"); | ||
expect(paperDetails).toHaveLength(5); | ||
Check failure on line 118 in tests/integration/paper-components/paper-view/cards/paper-details-card.test.ts GitHub Actions / Integration Testing with Vitesttests/integration/paper-components/paper-view/cards/paper-details-card.test.ts > PaperDetailsCard > When edit mode is toggled, then paper details are in edit mode
|
||
for (const paperDetail of paperDetails.slice(0, 4)) { | ||
const input = paperDetail.getElementsByTagName("textarea")[0]; | ||
expect(input).not.toHaveAttribute("readonly"); | ||
} | ||
}); | ||
|
||
await user.click(abstractBtn); | ||
|
||
await waitFor(() => { | ||
const paperDetails = screen.queryAllByTestId("paper-details"); | ||
expect(paperDetails).toHaveLength(5); | ||
const input = paperDetails[4].getElementsByTagName("textarea")[0]; | ||
expect(input).not.toHaveAttribute("readonly"); | ||
}); | ||
}); | ||
|
||
test("When editMode is not allowed, then edit buttons are not shown", async () => { | ||
render(PaperDetailsCard, { | ||
target: document.body, | ||
props: { | ||
loadingPaper: Promise.resolve(createPaper()), | ||
allowEditModeToggle: false, | ||
startInEditMode: false, | ||
showButtonBar: true, | ||
}, | ||
}); | ||
|
||
await waitForComponentLoading(); | ||
|
||
const editButtons = document.getElementsByTagName("svg"); | ||
let editButtonCount = 0; | ||
for (const editButton of editButtons) { | ||
if (!editButton.classList.contains("lucide-pencil")) { | ||
continue; | ||
} | ||
|
||
expect(editButton).toBeInTheDocument(); | ||
editButtonCount++; | ||
} | ||
expect(editButtonCount).toBe(0); | ||
}); | ||
|
||
test("When paper is loading, then skeletons are shown", async () => { | ||
render(PaperDetailsCard, { | ||
target: document.body, | ||
props: { | ||
loadingPaper: new Promise<Paper>((resolve) => { | ||
setTimeout(() => { | ||
resolve(createPaper()); | ||
}, 1000); | ||
}), | ||
allowEditModeToggle: true, | ||
startInEditMode: false, | ||
showButtonBar: true, | ||
}, | ||
}); | ||
|
||
const skeletons = screen.queryAllByTestId("skeleton"); | ||
expect(skeletons).toHaveLength(11); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import PaperDetail from "$lib/components/composites/paper-components/paper-view/PaperDetail.svelte"; | ||
import { render, screen } from "@testing-library/svelte"; | ||
import { describe, expect, test } from "vitest"; | ||
import { createPaper } from "../../../model-builder"; | ||
import type { Paper } from "$lib/model/backend"; | ||
import { waitForComponentLoading } from "../../test-helper"; | ||
|
||
describe("PaperDetail", () => { | ||
test("When props are provided, then component is shown", async () => { | ||
render(PaperDetail, { | ||
target: document.body, | ||
props: { | ||
key: "Title", | ||
value: "Example Title", | ||
loadingPaper: Promise.resolve(createPaper()), | ||
areDetailsInEditMode: false, | ||
}, | ||
}); | ||
|
||
await waitForComponentLoading(); | ||
|
||
const spans = document.getElementsByTagName("span"); | ||
expect(spans.length).toEqual(2); | ||
Check failure on line 23 in tests/integration/paper-components/paper-view/paper-detail.test.ts GitHub Actions / Integration Testing with Vitesttests/integration/paper-components/paper-view/paper-detail.test.ts > PaperDetail > When props are provided, then component is shown
|
||
const keySpan = spans[0]; | ||
const valueSpan = spans[1]; | ||
|
||
expect(keySpan.textContent).toEqual("Title"); | ||
expect(valueSpan.textContent).toEqual("Example Title"); | ||
}); | ||
|
||
test("When paper is loading, then skeleton is shown", () => { | ||
render(PaperDetail, { | ||
target: document.body, | ||
props: { | ||
key: "Title", | ||
value: "Example Title", | ||
loadingPaper: new Promise<Paper>((resolve) => { | ||
setTimeout(() => { | ||
resolve(createPaper()); | ||
}, 1000); | ||
}), | ||
areDetailsInEditMode: false, | ||
}, | ||
}); | ||
|
||
const spans = document.getElementsByTagName("span"); | ||
expect(spans.length).toEqual(1); | ||
const keySpan = spans[0]; | ||
|
||
expect(keySpan.textContent).toEqual("Title"); | ||
expect(screen.queryByTestId("skeleton")).not.toBeNull(); | ||
}); | ||
|
||
test("When paper loading failed, then errot text is shown", () => { | ||
render(PaperDetail, { | ||
target: document.body, | ||
props: { | ||
key: "Title", | ||
value: "Example Title", | ||
loadingPaper: Promise.reject(), | ||
areDetailsInEditMode: false, | ||
}, | ||
}); | ||
|
||
const spans = document.getElementsByTagName("span"); | ||
expect(spans.length).toEqual(2); | ||
Check failure on line 66 in tests/integration/paper-components/paper-view/paper-detail.test.ts GitHub Actions / Integration Testing with Vitesttests/integration/paper-components/paper-view/paper-detail.test.ts > PaperDetail > When paper loading failed, then errot text is shown
|
||
const keySpan = spans[0]; | ||
const valueSpan = spans[1]; | ||
|
||
expect(keySpan.textContent).toEqual("Title"); | ||
expect(valueSpan.textContent).toEqual("Couldn't load Title"); | ||
}); | ||
}); |