Skip to content

Commit

Permalink
Merge pull request #840 from jlandowner/ui-prettier-lint
Browse files Browse the repository at this point in the history
Apply prettier lint on all ts and tsx files
  • Loading branch information
oruharo authored Jun 17, 2024
2 parents f1876c2 + a60a117 commit 78f01a6
Show file tree
Hide file tree
Showing 55 changed files with 4,952 additions and 2,627 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
6 changes: 2 additions & 4 deletions web/dashboard-ui/src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from '../App';
import { it } from "vitest";

it('renders learn react link', () => {
it("renders learn react link", () => {
//render(<App />);
// const linkElement = screen.getByText(/learn react/i);
// expect(linkElement).toBeInTheDocument();
Expand Down
95 changes: 62 additions & 33 deletions web/dashboard-ui/src/__tests__/components/AuthRoute.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { Box } from '@mui/system';
import { cleanup, render } from '@testing-library/react';
import React from 'react';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { afterEach, beforeEach, describe, expect, it, MockedFunction, vi } from "vitest";
import { AuthRoute } from '../../components/AuthRoute';
import { useLogin } from '../../components/LoginProvider';
import { Box } from "@mui/system";
import { cleanup, render } from "@testing-library/react";
import React from "react";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import {
MockedFunction,
afterEach,
beforeEach,
describe,
expect,
it,
vi,
} from "vitest";
import { AuthRoute } from "../../components/AuthRoute";
import { useLogin } from "../../components/LoginProvider";

//--------------------------------------------------
// mock definition
//--------------------------------------------------
vi.mock('../../components/LoginProvider');
vi.mock("../../components/LoginProvider");

type MockedMemberFunction<T extends (...args: any) => any> = {
[P in keyof ReturnType<T>]: MockedFunction<ReturnType<T>[P]>;
Expand All @@ -19,8 +27,7 @@ type MockedMemberFunction<T extends (...args: any) => any> = {
// test
//-----------------------------------------------

describe('AuthRoute', () => {

describe("AuthRoute", () => {
const useLoginMock = useLogin as MockedFunction<typeof useLogin>;
const loginMock: MockedMemberFunction<typeof useLogin> = {
loginUser: undefined as any,
Expand All @@ -30,7 +37,7 @@ describe('AuthRoute', () => {
updataPassword: vi.fn(),
refreshUserInfo: vi.fn(),
clearLoginUser: vi.fn(),
}
};

beforeEach(async () => {
useLoginMock.mockReturnValue(loginMock);
Expand All @@ -46,45 +53,67 @@ describe('AuthRoute', () => {
<MemoryRouter initialEntries={[path]}>
<Routes>
<Route path="/signin" element={<div>signin</div>} />
<Route path="/workspace" element={<AuthRoute><div>workspace</div></AuthRoute>} />
<Route path="/user" element={<AuthRoute admin><div>user</div></AuthRoute>} />
<Route path='*' element={<Box>404</Box>} />
<Route
path="/workspace"
element={
<AuthRoute>
<div>workspace</div>
</AuthRoute>
}
/>
<Route
path="/user"
element={
<AuthRoute admin>
<div>user</div>
</AuthRoute>
}
/>
<Route path="*" element={<Box>404</Box>} />
</Routes>
</MemoryRouter >
</MemoryRouter>
);
}
};

it('normal not login =>/signin', async () => {
const { asFragment } = routerTester('/workspace');
it("normal not login =>/signin", async () => {
const { asFragment } = routerTester("/workspace");
expect(asFragment()).toMatchSnapshot();
});

it('normal not login admin =>/signin', async () => {
const { asFragment } = routerTester('/user');
it("normal not login admin =>/signin", async () => {
const { asFragment } = routerTester("/user");
expect(asFragment()).toMatchSnapshot();
});

it('normal login =>/workspace', async () => {
useLoginMock.mockReturnValue({ loginUser: { userName: 'user1' } } as ReturnType<typeof useLogin>);
const { asFragment } = routerTester('/workspace');
it("normal login =>/workspace", async () => {
useLoginMock.mockReturnValue({
loginUser: { userName: "user1" },
} as ReturnType<typeof useLogin>);
const { asFragment } = routerTester("/workspace");
expect(asFragment()).toMatchSnapshot();
});

it('normal login admin => /user', async () => {
useLoginMock.mockReturnValue({ loginUser: { userName: 'user1', roles: ["CosmoAdmin"] } } as ReturnType<typeof useLogin>);
const { asFragment } = routerTester('/user');
it("normal login admin => /user", async () => {
useLoginMock.mockReturnValue({
loginUser: { userName: "user1", roles: ["CosmoAdmin"] },
} as ReturnType<typeof useLogin>);
const { asFragment } = routerTester("/user");
expect(asFragment()).toMatchSnapshot();
});

it('normal login admin page not admin user page => 404', async () => {
useLoginMock.mockReturnValue({ loginUser: { userName: 'user1' } } as ReturnType<typeof useLogin>);
const { asFragment } = routerTester('/user');
it("normal login admin page not admin user page => 404", async () => {
useLoginMock.mockReturnValue({
loginUser: { userName: "user1" },
} as ReturnType<typeof useLogin>);
const { asFragment } = routerTester("/user");
expect(asFragment()).toMatchSnapshot();
});

it('normal login another page => 404', async () => {
useLoginMock.mockReturnValue({ loginUser: { userName: 'user1' } } as ReturnType<typeof useLogin>);
const { asFragment } = routerTester('/xxx');
it("normal login another page => 404", async () => {
useLoginMock.mockReturnValue({
loginUser: { userName: "user1" },
} as ReturnType<typeof useLogin>);
const { asFragment } = routerTester("/xxx");
expect(asFragment()).toMatchSnapshot();
});
});
});
35 changes: 19 additions & 16 deletions web/dashboard-ui/src/__tests__/components/Base64.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { base64url } from '../../components/Base64';
import { base64url } from "../../components/Base64";

//-----------------------------------------------
// test
Expand All @@ -23,13 +23,14 @@ function toBuffer(arrayBuffer) {
return buffer;
}

describe('base64url', () => {
describe('encode', () => {
it('✅ ok', async () => {
describe("base64url", () => {
describe("encode", () => {
it("✅ ok", async () => {
const tests = [
{
name: "1",
input: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
input:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
},
{
name: "1",
Expand All @@ -53,31 +54,33 @@ describe('base64url', () => {
},
];
for (const t of tests) {
const raw = Buffer.from(t.input, 'utf8');
const raw = Buffer.from(t.input, "utf8");
const got = base64url.encode(raw);

const want = raw.toString('base64url');
const want = raw.toString("base64url");
expect(got).toEqual(want);
}
});
});

describe('decode', () => {
it('✅ ok', async () => {
const base64str = 'QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw==';
describe("decode", () => {
it("✅ ok", async () => {
const base64str =
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw==";
const got = base64url.decode(base64str);
const want = Buffer.from(base64str, 'base64url');
const want = Buffer.from(base64str, "base64url");
expect(got).toEqual(toArrayBuffer(want));
});

it('✅ ok: no padding', async () => {
const base64strWithPadding = 'QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw==';
const want = Buffer.from(base64strWithPadding, 'base64url');
it("✅ ok: no padding", async () => {
const base64strWithPadding =
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw==";
const want = Buffer.from(base64strWithPadding, "base64url");

const base64strNoPadding = 'QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw';
const base64strNoPadding =
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLw";
const got = base64url.decode(base64strNoPadding);
expect(got).toEqual(toArrayBuffer(want));
});
});

});
Loading

0 comments on commit 78f01a6

Please sign in to comment.