Skip to content

Commit

Permalink
Merge pull request #50 from atlp-rwanda/fix-vitest
Browse files Browse the repository at this point in the history
fixing vitest errors
  • Loading branch information
faid-terence committed Jul 2, 2024
2 parents 523bb6d + 697dc98 commit 86a5319
Show file tree
Hide file tree
Showing 51 changed files with 89 additions and 43 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import { render } from '../../utils/test-utils';
import { describe, it } from 'vitest';
import mockStore from '../../utils/mockStore';

export const testindata = {
code: 'string',
discountType: 'percentage',
discountRate: 0,
expirationDate: '',
maxUsageLimit: 0,
product: 'string'
};
describe('ProductCoupon Component', () => {
it('renders loading state initially', () => {
render(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
import { cleanup } from './test-utils';
import '@testing-library/jest-dom';
import { decodedToken } from '../../services';
import { DecodedToken } from '../../types/CouponTypes';
import { expectedOutput } from './testPayload';

afterEach(() => {
cleanup();
});
export const expectedOutput: DecodedToken = {
id: 'string',
email: 'string',
userType: 'string',
iat: 5,
exp: 8
};

describe('JWT operation', () => {
it('should return a passed information', () => {
expect(decodedToken({ testData: expectedOutput })).toBe(expectedOutput);
Expand Down
File renamed without changes.
66 changes: 66 additions & 0 deletions src/__test__/utils/test-utils.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// src/utils/test-utils.test.tsx
import React from 'react';
import { cleanup, render, screen } from './test-utils';
import { testindata, expectedOutput } from './testPayload';
import '@testing-library/jest-dom';
import { DecodedToken } from '../../types/CouponTypes';

afterEach(() => {
cleanup();
});

function TestComponent() {
return <div>Test Component</div>;
}

describe('customRender and cleanup', () => {
it('renders a component using custom render', () => {
render(<TestComponent />);
expect(screen.getByText('Test Component')).toBeInTheDocument();
});

it('cleans up after each test', () => {
expect(document.body.innerHTML).toBe('');
});
});

describe('Test payload', () => {
it('should have correct structure for testindata', () => {
expect(testindata).toEqual({
code: 'string',
discountType: 'percentage',
discountRate: 0,
expirationDate: '',
maxUsageLimit: 0,
product: 'string'
});
});

it('should have correct structure for expectedOutput', () => {
const expected: DecodedToken = {
id: 'string',
email: 'string',
userType: 'string',
iat: 5,
exp: 8
};
expect(expectedOutput).toEqual(expected);
});

it('should have valid data types for testindata', () => {
expect(typeof testindata.code).toBe('string');
expect(typeof testindata.discountType).toBe('string');
expect(typeof testindata.discountRate).toBe('number');
expect(typeof testindata.expirationDate).toBe('string');
expect(typeof testindata.maxUsageLimit).toBe('number');
expect(typeof testindata.product).toBe('string');
});

it('should have valid data types for expectedOutput', () => {
expect(typeof expectedOutput.id).toBe('string');
expect(typeof expectedOutput.email).toBe('string');
expect(typeof expectedOutput.userType).toBe('string');
expect(typeof expectedOutput.iat).toBe('number');
expect(typeof expectedOutput.exp).toBe('number');
});
});
File renamed without changes.
17 changes: 17 additions & 0 deletions src/__test__/utils/testPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DecodedToken } from '../../types/CouponTypes';

export const testindata = {
code: 'string',
discountType: 'percentage',
discountRate: 0,
expirationDate: '',
maxUsageLimit: 0,
product: 'string'
};
export const expectedOutput: DecodedToken = {
id: 'string',
email: 'string',
userType: 'string',
iat: 5,
exp: 8
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { decodedToken } from '../../../services/jwtOperation';
import ListPopup from '../../Popups/ListPopup';
import ProductCoupon from '../ProductCoupon/ProductCoupon';
import { DecodedToken } from '../../../pages/Authentication/Login';
import { expectedOutput } from '../../../test/utils/jwtOperation.test';
import { expectedOutput } from '../../../__test__/utils/testPayload';

const DashboardSingleProduct: React.FC = () => {
const { id, app_env } = useParams<{ id: string; app_env: string }>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Products/ProductCoupon/ProductCoupon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Popup from '../../Popups/Popup';
import { decodedToken } from '../../../services';
import ConfirmDeletePopup from '../../Popups/ConfirmDeletePopup';
import { DecodedToken } from '../../../pages/Authentication/Login';
import { testindata } from '../../../test/components/Popups/ProductCoupon.test';
import { testindata } from '../../../__test__/utils/testPayload';

interface ProductCouponProps {
vendorId: string;
Expand Down
23 changes: 0 additions & 23 deletions src/test/utils/test-utils.test.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"jsx": "react-jsx",
"types": ["vitest/globals", "vite/client", "jest"]
},
"include": ["src", "./src/test/setup.ts"],
"include": ["src"],
"references": [
{
"path": "./tsconfig.node.json"
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
setupFiles: './src/__test__/setup.ts',
coverage: {
exclude: [...configDefaults.exclude, '**.**js', '**/**.d.ts']
}
Expand Down

0 comments on commit 86a5319

Please sign in to comment.