Skip to content

Commit

Permalink
test: test against entry stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Jun 10, 2024
1 parent 79b2cab commit e7bda91
Show file tree
Hide file tree
Showing 17 changed files with 2,011 additions and 58 deletions.
4 changes: 4 additions & 0 deletions ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ module.exports = {
'plugin:react/jsx-runtime',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:react-hooks/recommended',
'plugin:import/recommended',
'plugin:import/typescript'
],
ignorePatterns: [
'dist',
'.eslintrc.cjs',
'coverage',
'src/generated/schema.ts',
'src/tool/wasm_exec.js',
],
Expand All @@ -21,6 +24,7 @@ module.exports = {
],
rules: {
'sort-imports': ['warn', {ignoreDeclarationSort: true}],
'import/no-unresolved': 'off',
'react-refresh/only-export-components': [
'warn',
{allowConstantExport: true},
Expand Down
2 changes: 2 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev:explorer": "vite -c vite.config-explorer.ts",
"generate": "typia generate --input src/schema --output src/generated --project tsconfig.json",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
"test": "vitest run"
},
"dependencies": {
Expand Down Expand Up @@ -43,6 +44,7 @@
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitest/coverage-istanbul": "^1.6.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
Expand Down
151 changes: 151 additions & 0 deletions ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions ui/src/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {fireEvent, render} from '@testing-library/react';
import {Tooltip} from './Tooltip.tsx';
import {assert, expect, test} from 'vitest';
import {Tooltip} from './Tooltip.tsx';
import {Entry, EntryChildren, type EntryType} from "./tool/entry.ts";

function getTestNode(): Entry {
return {
getChildren(): EntryChildren[EntryType] {
return [];
},
getType(): EntryType {
return "unknown";
}, getID(): number {
getID(): number {
return 1;
}, getName(): string {
return "test";
Expand All @@ -31,14 +29,14 @@ test('Tooltip should render correctly when visible', () => {

test('Tooltip should not render when not visible', () => {
const r = render(<Tooltip visible={false}
node={getTestNode()}/>);
node={getTestNode()}/>);
// should have tooltip-hidden class
expect(r.container.querySelector('.tooltip-hidden')).not.toBeNull();
});

test('Tooltip should update position on mouse move', () => {
const { getByText } = render(<Tooltip visible={true} node={getTestNode()} />);
fireEvent.mouseMove(document, { clientX: 100, clientY: 100 });
const {getByText} = render(<Tooltip visible={true} node={getTestNode()}/>);
fireEvent.mouseMove(document, {clientX: 100, clientY: 100});
const tooltip = getByText('test').parentElement;
if (!tooltip) {
assert.isNotNull(tooltip);
Expand Down
6 changes: 2 additions & 4 deletions ui/src/Treemap.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// @vitest-environment jsdom

import {expect, test} from "vitest";
import {readFileSync} from "fs";
import path from "node:path";
import {expect, test} from "vitest";
import {render} from '@testing-library/react'
import {parseResult} from "./generated/schema.ts";
import {createEntry} from "./tool/entry.ts";
import TreeMap from "./TreeMap.tsx";
import {render} from '@testing-library/react'

test("Treemap", () => {
const data = readFileSync(path.join(__dirname, 'testdata', 'testdata.json')).toString();
Expand Down
4 changes: 2 additions & 2 deletions ui/src/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {ReactNode, useEffect, useMemo} from "react";
import {useAsync} from "react-use";
import {Dialog, DialogContent, DialogContentText, DialogTitle} from "@mui/material";
import gsa from "../../gsa.wasm?init";
import {createEntry} from "../tool/entry.ts";
import {Dialog, DialogContent, DialogContentText, DialogTitle} from "@mui/material";
import {FileSelector} from "./FileSelector.tsx";
import TreeMap from "../TreeMap.tsx";
import {FileSelector} from "./FileSelector.tsx";

type ModalState = {
isOpen: false
Expand Down
2 changes: 1 addition & 1 deletion ui/src/explorer/FileSelector.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {fireEvent, render} from '@testing-library/react';
import {FileSelector} from './FileSelector.tsx';
import {expect, test, vi} from 'vitest';
import {FileSelector} from './FileSelector.tsx';

test('FileSelector should render correctly', () => {
const mockHandler = vi.fn();
Expand Down
Loading

0 comments on commit e7bda91

Please sign in to comment.