Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Schwarz committed Jul 10, 2023
1 parent f9912de commit 67cbb16
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"jest.jestCommandLine": "npm run test:api -- --watch"
"jest.jestCommandLine": "npm run test:component -- --watch"
}
35 changes: 5 additions & 30 deletions test/component/ListDID.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import { render, act, screen, cleanup, fireEvent } from "@testing-library/react";
import { ListDID as ListDIDStory } from "@/component-library/components/Pages/ListDID/ListDID";
import { DIDMeta } from "@/lib/core/entity/rucio";
import { createDID } from "test/fixtures/table-fixtures";
import { createDID, createDIDMeta, mockUseComDOM } from "test/fixtures/table-fixtures";
var format = require("date-format")

describe("ListDID Story Test", () => {
it("Checks empty render of the story", async () => {
await act(async () => render(
<ListDIDStory
didSearch={jest.fn(x => console.log(x))}
didResponse={{ data: [], fetchStatus: "idle" }}
comdom={mockUseComDOM(Array.from({length: 0}, () => createDID()))}
didMetaQuery={jest.fn(x => console.log(x))}
didMetaQueryResponse={{} as DIDMeta}
/>
Expand Down Expand Up @@ -60,39 +59,15 @@ describe("ListDID Story Test", () => {
SOLUTION:
remove `aria-label` from the table rows, grab table rows differently.
*/
const arrayLength = 5
const mockDIDMeta = {
"name": "dataset-YSytZjXJMdiCsSiiUwXx",
"scope": "Lawrence.Myers",
"account": "Lawrence_Myers",
"did_type": "Dataset",
"created_at": new Date(2021, 3),
"updated_at": new Date(2022, 10),
"availability": "Deleted",
"obsolete": false,
"hidden": true,
"suppressed": true,
"purge_replicas": true,
"monotonic": true,
"is_open": true,
"adler32": null,
"guid": null,
"md5": null,
"filesize": null
} as DIDMeta
const mockDIDMeta = createDIDMeta()
await act(async () => render(
<ListDIDStory
didSearch={jest.fn(x => console.log(x))}
didResponse={{
data: Array.from({length: arrayLength}, (v, k) => createDID()), fetchStatus: "idle"
}}
comdom={mockUseComDOM(Array.from({length: 100}, () => createDID()))}
didMetaQuery={jest.fn(x => console.log(x))}
didMetaQueryResponse={mockDIDMeta}
/>
))
const tableRows = screen.getAllByRole("row", {selected: false})
expect(tableRows).toHaveLength(arrayLength)
expect(tableRows[0]).toBeInTheDocument()
// check that metaview is still invisible
const noDIDSelectedDiv = screen.getByText("No DID selected").closest("div")
expect(noDIDSelectedDiv).toHaveClass("block")
Expand All @@ -104,7 +79,7 @@ describe("ListDID Story Test", () => {
const goDIDViewButton = screen.getByRole("generic", { name: "Go To DID Page" })
expect(goDIDViewButton).toHaveClass("block")
const didCreationRow = screen.getByRole("row", { name: "Date of DID Creation" })
expect(didCreationRow).toHaveTextContent(format("yyyy-MM-dd", mockDIDMeta.created_at))
expect(didCreationRow).toHaveTextContent(format("yyyy-MM-dd", new Date(mockDIDMeta.created_at)))
const didObsoleteRow = screen.getByRole("row", { name: "DID Obsolete" })
expect(didObsoleteRow).toHaveTextContent(mockDIDMeta.obsolete ? "True" : "False")
})
Expand Down
6 changes: 3 additions & 3 deletions test/component/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Login Page Test", () => {
const OIDCButton = screen.getByText(provider.name)
expect(OIDCButton).toBeInTheDocument()
})
const oidcParent = screen.getByTestId('oidc-buttons')
const oidcParent = screen.getByRole('generic', {name: /OIDC Login Buttons/})
expect(oidcParent.className).not.toContain('hidden')

// Check VO tabs are rendered
Expand All @@ -79,7 +79,7 @@ describe("Login Page Test", () => {
expect(loginFormParent.className).toContain('hidden')

// check only 1 account field is rendered
const accountFieldParent = screen.getByRole("group", {name: "Account Fields"})
const accountFieldParent = screen.getByRole("group", {name: /Choose Account Name/})
expect(accountFieldParent.className).not.toContain('hidden')
fireEvent.click(userpassButton)
expect(accountFieldParent.className).toContain('hidden')
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("Login Page Test", () => {
await act( async () => render(<Login/>))

// Check OIDC buttons: 2 pieces and collapsed
const oidcParent = screen.getByTestId('oidc-buttons')
const oidcParent = screen.getByRole('generic', {name: /OIDC Login Buttons/})
expect(oidcParent.className).toContain('hidden')

})
Expand Down
8 changes: 2 additions & 6 deletions test/component/PageRule.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { render, act, screen, cleanup, fireEvent, getByRole } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { PageRule as PageRuleStory } from "@/component-library/components/Pages/PageRule/PageRule";
import { createRuleMeta } from "test/fixtures/table-fixtures";
import { createRandomRulePageLockEntry, createRuleMeta, mockUseComDOM } from "test/fixtures/table-fixtures";
var format = require("date-format")

const ruleMeta = createRuleMeta()
Expand All @@ -15,11 +15,7 @@ describe("PageRule Story Test", () => {
await act(async () => render(
<PageRuleStory
ruleMeta={ruleMeta}
ruleLocks={{
data: [],
fetchStatus: "idle",
pageSize: 10,
}}
ruleLocks={mockUseComDOM(Array.from({length: 100}, (v,k) => createRandomRulePageLockEntry()))}
/>
))
const user = userEvent.setup()
Expand Down

0 comments on commit 67cbb16

Please sign in to comment.