Skip to content

Commit

Permalink
Automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
undyingwraith committed Dec 14, 2024
1 parent 1bf1592 commit 4634788
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 14 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ run-name: Build triggered by @${{ github.actor }}
on: [push]
jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -13,3 +16,5 @@ jobs:
run: yarn --frozen-lockfile --check-cache
- name: Run build
run: yarn build
- name: Run tests
run: yarn test
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"arcanis.vscode-zipfs",
"github.vscode-github-actions",
"dsznajder.es7-react-js-snippets",
"ecmel.vscode-html-css"
"ecmel.vscode-html-css",
"redhat.vscode-yaml"
]
}
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"test": "vitest run"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"jsdom": "^25.0.1",
"terser": "^5.31.0",
"typescript": "^5.4.5",
"vite": "^5.2.11",
Expand Down
28 changes: 28 additions & 0 deletions packages/ui/tests/components/atoms/FileInfoDisplay.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { describe, expect, test } from 'vitest';
import { render } from '@testing-library/react';
import { BrowserModule, CoreModule } from 'ipmc-core';
import { IFileInfo, IIpfsServiceSymbol } from 'ipmc-interfaces';
import { FileInfoDisplay } from '@src/components/atoms/FileInfoDisplay';
import { AppContextProvider } from '@src/context';
import '@src/i18n';

describe('FileInfoDisplay', () => {
test('Renders data correctly', () => {
const fileInfo: IFileInfo = {
cid: 'TestCid',
name: 'Test name',
type: 'dir'
};

const t = render(
<AppContextProvider setup={(app) => {
app.use(CoreModule);
app.use(BrowserModule);
app.registerConstant({}, IIpfsServiceSymbol);
}}>
<FileInfoDisplay file={fileInfo} />
</AppContextProvider>);
expect(t).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`FileInfoDisplay > Renders data correctly 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div
class="MuiBox-root css-0"
>
<h3
class="MuiTypography-root MuiTypography-h3 css-gepadz-MuiTypography-root"
>
Test name
</h3>
</div>
</div>
</body>,
"container": <div>
<div
class="MuiBox-root css-0"
>
<h3
class="MuiTypography-root MuiTypography-h3 css-gepadz-MuiTypography-root"
>
Test name
</h3>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
6 changes: 6 additions & 0 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"target": "ESNext",
"downlevelIteration": true,
"isolatedModules": true,
"baseUrl": ".",
"paths": {
"@src/*": [
"./src/*"
]
}
},
"include": [
"src",
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'path';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import dts from 'vite-plugin-dts';
import path from 'path';

export default defineConfig(({ mode }) => ({
plugins: [
Expand Down Expand Up @@ -55,7 +56,13 @@ export default defineConfig(({ mode }) => ({
manifest: false,
minify: mode == 'dev' ? 'esbuild' : 'terser',
},
resolve: {
alias: {
"@src": path.resolve(__dirname, "./src"),
}
},
test: {
globals: true,
environment: 'jsdom',
},
}));
Loading

0 comments on commit 4634788

Please sign in to comment.