Skip to content

Commit

Permalink
Merge pull request #1085 from syucream/fix/add-fe-tests
Browse files Browse the repository at this point in the history
Add some FE tests
  • Loading branch information
userlocalhost authored Feb 19, 2024
2 parents 5dbc1ba + 5a0e12b commit 956d870
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 5 deletions.
49 changes: 44 additions & 5 deletions frontend/src/components/acl/ACLHistoryList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,54 @@
* @jest-environment jsdom
*/

import { render } from "@testing-library/react";
import { ACLHistory } from "@dmm-com/airone-apiclient-typescript-fetch";
import { render, screen, within } from "@testing-library/react";
import React from "react";

import { ACLHistoryList } from "./ACLHistoryList";

import { TestWrapper } from "TestWrapper";

test("should render with essential props", () => {
expect(() =>
render(<ACLHistoryList histories={[]} />, { wrapper: TestWrapper })
).not.toThrow();
describe("ACLHistoryList", () => {
const histories: ACLHistory[] = [
{
user: {
id: 1,
username: "user1",
},
time: new Date("2020/01/01 00:00:00"),
name: "attr1",
changes: [
{
action: "create",
target: "is_public",
before: null,
after: false,
},
],
},
{
user: {
id: 1,
username: "user1",
},
time: new Date("2020/01/01 00:00:00"),
name: "attr1",
changes: [
{
action: "update",
target: "is_public",
before: false,
after: true,
},
],
},
];

test("should render acl histories", () => {
render(<ACLHistoryList histories={histories} />, { wrapper: TestWrapper });

const bodyRowGroup = screen.getAllByRole("rowgroup")[1];
expect(within(bodyRowGroup).queryAllByRole("row")).toHaveLength(4);
});
});
72 changes: 72 additions & 0 deletions frontend/src/services/entity/Edit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { findDuplicateIndexes } from "./Edit";

test("findDuplicateIndexes() returns attr indexes have duplicated name", () => {
const actual = findDuplicateIndexes([
{
name: "unique1",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note1",
},
// duplicated with index=2
{
name: "duplicated1",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note2",
},
// duplicated with index=1
{
name: "duplicated1",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note3",
},
{
name: "unique2",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note4",
},
// duplicated with index=5
{
name: "duplicated2",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note5",
},
// duplicated with index=4
{
name: "duplicated2",
type: 2,
isMandatory: false,
isDeleteInChain: false,
isSummarized: false,
isWritable: false,
referral: [],
note: "note6",
},
]);

expect(actual).toEqual([2, 1, 5, 4]);
});

0 comments on commit 956d870

Please sign in to comment.