8000 feat: add base event service by ldhyen99 Β· Pull Request #7 Β· uncefact/tests-untp Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add base event service #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9980041
feat: add base event service
ldhyen99 Jan 29, 2024
635e8d3
refactor: change context in issue event
ldhyen99 Jan 29, 2024
ef2ceca
refactor: change code in base event
ldhyen99 Jan 29, 2024
4cb4ac2
refactor: change type in issue event similar to integrate vckit function
ldhyen99 Jan 29, 2024
eaf033d
fix: remove unuse comment
ldhyen99 Jan 29, 2024
d7e68c2
refactor: convert class to abstract class
ldhyen99 Jan 29, 2024
a840f53
docs: add comment in base event class and document in readme
ldhyen99 Jan 30, 2024
cd2ffed
test: add unit test for base event class and config TS to run unit te…
ldhyen99 Jan 30, 2024
ef767e6
docs: add docs for base event
ldhyen99 Jan 30, 2024
2d888fa
refactor: change name of issue function and delete create event func …
ldhyen99 Jan 30, 2024
7f65182
feat: add storage event
ldhyen99 Feb 1, 2024
119987e
feat: add DLP service
ldhyen99 Feb 1, 2024
e6de616
feat: add base event service
ldhyen99 Jan 29, 2024
dc1c5e9
8000 refactor: change context in issue event
ldhyen99 Jan 29, 2024
3c879ba
refactor: change code in base event
ldhyen99 Jan 29, 2024
a237c75
refactor: change type in issue event similar to integrate vckit function
ldhyen99 Jan 29, 2024
feb49fd
fix: remove unuse comment
ldhyen99 Jan 29, 2024
bc053ee
refactor: convert class to abstract class
ldhyen99 Jan 29, 2024
9fb1c39
docs: add comment in base event class and document in readme
ldhyen99 Jan 30, 2024
d716ebd
test: add unit test for base event class and config TS to run unit te…
ldhyen99 Jan 30, 2024
e199154
docs: add docs for base event
ldhyen99 Jan 30, 2024
ed248f2
refactor: change name of issue function and delete create event func …
ldhyen99 Jan 30, 2024
a684e5c
feat: add storage event
ldhyen99 Feb 1, 2024
871fa6e
feat: add DLP service
ldhyen99 Feb 1, 2024
a4f62c3
refactor: simplify the object event and base event
namhoang1604 Feb 19, 2024
33c47f7
feat: add base event service
ldhyen99 Jan 29, 2024
787e95a
feat: add DLP service
ldhyen99 Feb 1, 2024
7f26bd0
refactor: add some code for unit test
ldhyen99 Feb 19, 2024
093d39e
resolve conflict
ldhyen99 Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
{
"root": true,
"plugins": ["@typescript-eslint", "prettier"],
"plugins": [
"@typescript-eslint",
"prettier"
],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parserOptions": {
"project": ["./packages/tsconfig.settings.json", "./packages/*/tsconfig.json"]
"project": [
"./packages/tsconfig.settings.json",
"./packages/*/tsconfig.json"
]
},
"rules": {
"no-console": "warn",
// Off for now, but we should enable this in the future
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off"
},
"overrides": [
{
"files": [
"*.js"
],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ tmp/

# logs
/logs
packages/services/tsconfig.tsbuildinfo
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint
yarn lint
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ UNTP mock implementations and test cases
## Install dependencies

```bash
pnpm install
yarn install
```

## Build the package

```bash
pnpm build
yarn build
```

## Start the project

```bash
pnpm start
yarn start
```
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "1.0.0",
"npmClient": "pnpm",
"packages": ["packages/*"],
"npmClient": "yarn",
"command": {
"publish": {
"allowBranch": ["main", "next"],
Expand Down
27 changes: 16 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
"packages/*"
],
"scripts": {
"start": "cd packages/core && pnpm start",
"build": "pnpm build:components && pnpm build:services",
"build:components": "cd packages/components && pnpm run build",
"build:services": "cd packages/services && pnpm run build",
"test": "pnpm run test:components",
"test:components": "cd packages/components && pnpm run test",
"storybook": "pnpm run storybook:components",
"storybook:components": "cd packages/components && pnpm run storybook",
"upgrade:packages": "pnpm -r --stream upgrade --latest",
"start": "cd packages/core && yarn start",
"build": "yarn run build-clean && yarn build:components && yarn build:services",
"build:components": "cd packages/components && yarn run build",
"build:services": "cd packages/services && yarn run build",
"build-clean": "rimraf --glob ./packages/*/tsconfig.tsbuildinfo",
"test": "yarn run test:components && yarn run test:services",
"test:components": "cd packages/components && yarn run test",
"test:services": "cd packages/services && yarn run test",
"storybook": "yarn run storybook:components",
"storybook:components": "cd packages/components && yarn run storybook",
"upgrade:packages": "yarn -r --stream upgrade --latest",
"version": "lerna version",
"prepare": "husky install",
"lint": " pnpm eslint ."
"lint": " yarn eslint ."
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand All @@ -38,7 +40,7 @@
"pretty-quick": "3.1.3",
"ts-jest": "29.1.1",
"ts-node": "10.9.2",
"typescript": "5.1.6"
"typescript": "^4"
},
"publishConfig": {
"access": "public"
Expand All @@ -48,5 +50,8 @@
},
"engines": {
"node": ">= 18.0.0"
},
"dependencies": {
"rimraf": "^5.0.5"
}
}
6 changes: 3 additions & 3 deletions packages/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Make sure your machine has Node.js version 18 or later installed.
To install the project dependencies, run the following command:

```bash
pnpm install
yarn install
```

## Storybook
Expand All @@ -21,7 +21,7 @@ Explore and interact with the components using Storybook.
### Run Storybook

```bash
pnpm run storybook
yarn run storybook
```

Visit http://localhost:6006/ in your browser to view Storybook.
Expand All @@ -31,5 +31,5 @@ Visit http://localhost:6006/ in your browser to view Storybook.
Run unit tests using Jest.

```bash
pnpm test
yarn test
```
20 changes: 10 additions & 10 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"devDependencies": {
"@babel/preset-react": "^7.7.0",
"@babel/preset-typescript": "^7.22.5",
"@storybook/addon-essentials": "^7.1.0-rc.2",
"@storybook/addon-interactions": "^7.1.0-rc.2",
"@storybook/addon-links": "^7.1.0-rc.2",
"@storybook/addon-essentials": "^7.6.16",
"@storybook/addon-interactions": "^7.6.16",
"@storybook/addon-links": "^7.6.16",
"@storybook/addon-onboarding": "^1.0.7",
"@storybook/blocks": "^7.1.0-rc.2",
"@storybook/preset-create-react-app": "^7.1.0-rc.2",
"@storybook/react": "^7.1.0-rc.2",
"@storybook/react-webpack5": "^7.1.0-rc.2",
"@storybook/blocks": "^7.6.16",
"@storybook/preset-create-react-app": "^7.6.16",
"@storybook/react": "^7.6.16",
"@storybook/react-webpack5": "^7.6.16",
"@storybook/testing-library": "^0.2.0",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^13.4.0",
Expand All @@ -75,11 +75,11 @@
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"prop-types": "^15.8.1",
"storybook": "^7.1.0-rc.2",
"storybook": "^7.6.16",
"tslib": "^2.6.0",
"typescript": "^5.1.6",
"typescript": "^4",
"web-vitals": "^2.1.4",
"webpack": "5.88.2"
"webpack": "^5.11.0"
},
"publishConfig": {
"access": "public"
Expand Down
45 changes: 25 additions & 20 deletions packages/components/src/__tests__/ImportButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('ImportButton', () => {
forms: [
{
serialNumber: '12345678',
type: 'TPEC1'
}
type: 'TPEC1',
},
],
};
const fileMock = new File([JSON.stringify(contentObjectMock)], 'testFile.json', {
Expand All @@ -38,11 +38,15 @@ describe('ImportButton', () => {
});

it('handles file upload and calls onChange with file content', async () => {
render(<ImportButton object[]) => {
const [fileContentObject] = data;
// Expect the onChange function to have been called with the expected content
expect(fileContentObject).toMatchObject(contentObjectMock);
})} />);
render(
<ImportButton
object[]) => {
const [fileContentObject] = data;
// Expect the onChange function to have been called with the expected content
expect(fileContentObject).toMatchObject(contentObjectMock);
}}
/>,
);

const fileInput = screen.getByLabelText('Import');
fireEvent.change(fileInput, { target: { files: [fileMock] } });
Expand All @@ -51,20 +55,22 @@ describe('ImportButton', () => {
await waitFor(() => expect(fileInput).not.toBeDisabled());
});

it('handles file upload error due to exceeding maximum file size', async () => {
// TODO: The test does not work as expected because jest has no way of catching errors coming out of event handlers
// ref: https://stackoverflow.com/questions/71978839/how-to-catch-such-an-error-with-jest-and-testing-library-react
it.skip('handles file upload error due to exceeding maximum file size', async () => {
try {
const >

const oversizedFileMock = new File(['file content'], 'oversizedFile.json', {
type: 'application/json',
});

// Set the file size greater than the maximum allowed size (in bytes)
Object.defineProperty(oversizedFileMock, 'size', { value: 1024 * 1024 * 6 });

// Render the ImportButton component with the provided label and onChange mock function
render(<ImportButton />);

// Simulate a file change event by providing an oversized file to the file input
const input = screen.getByTestId('file-input');
fireEvent.change(input, {
Expand All @@ -79,14 +85,14 @@ describe('ImportButton', () => {
it('handles file upload error when content is empty', async () => {
try {
const >

const emptyContentFileMock = new File([], 'emptyContentFile.json', {
type: 'application/json',
});

// Render the ImportButton component with the provided label and onChange mock function
render(<ImportButton />);

// Simulate a file change event by providing a file with empty content to the file input
const input = screen.getByTestId('file-input');
fireEvent.change(input, {
Expand All @@ -101,14 +107,14 @@ describe('ImportButton', () => {
it('handles file upload error for invalid JSON file', async () => {
try {
const >

const invalidJsonFileMock = new File(['{ invalid json }'], 'invalidJsonFile.json', {
type: 'application/json',
});

// Render the ImportButton component with the provided label and onChange mock function
render(<ImportButton />);

// Simulate a file change event by providing a file with invalid JSON content to the file input
const input = screen.getByTestId('file-input');
fireEvent.change(input, {
Expand All @@ -119,5 +125,4 @@ describe('ImportButton', () => {
expect(error.message).toMatch(/^Invalid JSON file! /);
}
});

});
});
18 changes: 14 additions & 4 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -19,6 +23,12 @@
"sourceMap": true,
"rootDir": "src"
},
"types": ["node", "jest", "@testing-library/jest-dom"],
"include": ["src", "src/__tests__"]
}
"types": [
"node",
"jest",
"@testing-library/jest-dom"
],
"include": [
"src"
]
}
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ React components for the core of the application, rendering the page by wrap up
## Install package before start

```sh
pnpm install
yarn install
```

## Start the project

```sh
pnpm start
yarn start
```
13 changes: 6 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@mock-app/components": "workspace:^",
"@mock-app/services": "workspace:^",
"@mock-app/components": "1.0.0",
"@mock-app/services": "1.0.0",
"@mui/icons-material": "^5.15.5",
"@mui/material": "^5.15.5",
"react": "^18.2.0",
Expand Down Expand Up @@ -46,15 +46,14 @@
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/jest": "^28",
"@types/node": "^16.18.72",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"history": "^5.3.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"storybook": "^7.1.0-rc.2",
"typescript": "5.1.6",
"webpack": "5.88.2"
"typescript": "^4",
"webpack": "^5.11.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/core/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppBar, Toolbar, Typography, Container, Box, IconButton, Menu, MenuItem
import { Menu as MenuIcon } from '@mui/icons-material';
import appConfig from '../../constants/app-config.json';
import { convertStringToPath } from '../../utils';
import { IApp, IStyles } from '../../types/common.types';
import { IStyles } from '../../types/common.types';

function Header() {
const [anchorElNav, setAnchorElNav] = useState<null | HTMLElement>(null);
Expand Down Expand Up @@ -33,7 +33,7 @@ function Header() {
};

const renderMenuByScreenType = (screenType: string) => {
return appConfig.apps.map((app: IApp) => {
return appConfig.apps.map((app: any) => {
const route = `/${convertStringToPath(app.name)}`;

if (screenType === 'mobile') {
Expand Down
Loading
0