Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jwafu authored Jan 26, 2024
2 parents 1d723f8 + cb5c75a commit 8547d0f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 10 deletions.
1 change: 1 addition & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
"roots": [
"<rootDir>/src"
],
"testMatch": [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"moduleNameMapper": {
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
},
"testEnvironment": "jsdom"
}
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@
"dev": "ts-node src/index.tsx",
"clean": "rimraf node_modules && rimraf package-lock.json",
"start": "cross-env react-scripts start",
"build": "cross-env react-scripts build"
"build": "cross-env react-scripts build",
"test": "jest"
},
"dependencies": {
"@pieces.app/pieces-os-client": "1.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"ts-node": "^10.9.1"
"ts-node": "^10.9.1",
"jest-environment-jsdom": "^29.7.0"
},
"devDependencies": {
"@types/node": "^20.8.7",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.17",
"cross-env": "^7.0.3",
"rimraf": "^3.0.2",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.11",
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
},
"browserslist": {
"production": [
Expand Down
12 changes: 12 additions & 0 deletions src/app/components/Button/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import { CreateButton } from '../Button';
import '@testing-library/jest-dom'

describe('CreateButton', () => {
it('should have "Create Snippet" as button label', () => {
render(<CreateButton applicationData={null} data={null} name={null} />);
const buttonElement = screen.getByRole('button', { name: /Create Snippet/i });
expect(buttonElement).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function CopilotChat(): React.JSX.Element {
setMessage("")
setData("")
};

// for setting the initial copilot chat that takes place on page load.
useEffect(() => {
const getInitialChat = async () => {
Expand Down
35 changes: 35 additions & 0 deletions src/app/components/TextInput/__tests__/textinput.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { DataTextInput } from '../TextInput';
import '@testing-library/jest-dom';

describe('DataTextInput', () => {
test('renders input and textarea elements', () => {
render(<DataTextInput applicationData={null} />);

const nameInput = screen.getByPlaceholderText('Type the name of your snippet...') as HTMLInputElement;
const dataTextarea = screen.getByPlaceholderText('Add your code/text content into this box') as HTMLTextAreaElement;

expect(nameInput).toBeInTheDocument();
expect(dataTextarea).toBeInTheDocument();
});

test('updates the state when input and textarea values change', () => {
render(<DataTextInput applicationData={null} />);

const nameInput = screen.getByPlaceholderText('Type the name of your snippet...') as HTMLInputElement;
const dataTextarea = screen.getByPlaceholderText('Add your code/text content into this box') as HTMLTextAreaElement;

// Simulate user input and check if the state is updated accordingly
expect(nameInput.value).toEqual('');
fireEvent.change(nameInput, { target: { value: 'Snippet name' } });
expect(nameInput.value).toEqual('Snippet name');

expect(dataTextarea.value).toEqual('');
fireEvent.change(dataTextarea, { target: { value: 'Snippet code' } });
expect(dataTextarea.value).toEqual('Snippet code');
});
});



13 changes: 7 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"target": "es2022",
"module": "CommonJS",
"allowJs": true,
"checkJs": true,
"allowJs": true,
"checkJs": true,
"types": ["@testing-library/jest-dom"],
"forceConsistentCasingInFileNames": true,

"outDir": "./dist",
/* Type Checking */
"strict": false,
"skipLibCheck": true,
/* Skip type checking all .d.ts files. */
"jsx": "react"
},
"exclude": ["node_modules"]
}
"exclude": ["node_modules","jest.config.js", "**/__mocks__/*"]
}

0 comments on commit 8547d0f

Please sign in to comment.