-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config files changes to work with d3-scale (mui/mui-x#11568)
- Loading branch information
1 parent
9ce36fe
commit 6c90be0
Showing
5 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react"] | ||
} | ||
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
// ... other configurations | ||
transform: { | ||
"^.+\\.[t|j]sx?$": "babel-jest", | ||
"^.+\\.svg$": "jest-transform-stub", | ||
"^.+\\.css$": "jest-transform-stub", | ||
}, | ||
moduleNameMapper: { | ||
"\\.(css|less|scss|sass)$": "identity-obj-proxy", | ||
}, | ||
|
||
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom'; | ||
// setupTests.ts | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
// Mocking the PieChart component globally | ||
jest.mock('@mui/x-charts/PieChart', () => ({ | ||
PieChart: jest.fn().mockImplementation(({ children }) => children), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Login.test.tsx | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { createStore } from 'redux'; | ||
import Login from '../Pages/login/Login'; | ||
import rootReducer from '../store/rootReducer'; | ||
import LocalStorageService from '../app/services/localStorageService'; | ||
|
||
jest.mock('../app/services/localStorageService'); | ||
|
||
const store = createStore(rootReducer); | ||
|
||
describe('Login Component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders login form', () => { | ||
render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<Login /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
|
||
expect(screen.getByLabelText(/E-mail/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Senha/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Login/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows error message when fields are empty', () => { | ||
render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<Login /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
|
||
fireEvent.click(screen.getByText(/Entrar/i)); | ||
|
||
expect(screen.getByText(/Preencha todos os campos/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows error message with invalid credentials', () => { | ||
render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<Login /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
|
||
fireEvent.change(screen.getByLabelText(/E-mail/i), { target: { value: 'wrong' } }); | ||
fireEvent.change(screen.getByLabelText(/Senha/i), { target: { value: 'wrong' } }); | ||
fireEvent.click(screen.getByText(/Entrar/i)); | ||
|
||
expect(screen.getByText(/Invalid username or password/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls login with correct credentials', () => { | ||
const fakeUser = 'user'; | ||
const fakePassword = 'password'; | ||
|
||
render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<Login /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
|
||
fireEvent.change(screen.getByLabelText(/E-mail/i), { target: { value: fakeUser } }); | ||
fireEvent.change(screen.getByLabelText(/Senha/i), { target: { value: fakePassword } }); | ||
fireEvent.click(screen.getByText(/Entrar/i)); | ||
|
||
expect(LocalStorageService.addItem).toHaveBeenCalledWith('isAuthenticated', true); | ||
expect(LocalStorageService.addItem).toHaveBeenCalledWith('user', fakeUser); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// InvestmentCalculator.test.tsx | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import InvestmentCalculator from '../Pages/simulateInvestment/SimulateInvestment'; | ||
import { Provider } from 'react-redux'; | ||
import { createStore } from 'redux'; | ||
import rootReducer from '../store/rootReducer'; | ||
|
||
|
||
// Mocking the PieChart component | ||
jest.mock('@mui/x-charts/PieChart', () => ({ | ||
PieChart: jest.fn().mockImplementation(({ children }) => <div>{children}</div>), | ||
})); | ||
|
||
const store = createStore(rootReducer); | ||
|
||
describe('InvestmentCalculator Component', () => { | ||
test('renders the form fields correctly', () => { | ||
render( | ||
<Provider store={store}> | ||
<InvestmentCalculator /> | ||
</Provider> | ||
); | ||
|
||
expect(screen.getByLabelText(/Initial Investment/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Monthly Inflation Rate/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Monthly Contribution/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Investment Period \(months\)/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Monthly Interest Rate/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows error message when required fields are empty', () => { | ||
render( | ||
<Provider store={store}> | ||
<InvestmentCalculator /> | ||
</Provider> | ||
); | ||
|
||
fireEvent.click(screen.getByText(/Calculate/i)); | ||
|
||
expect(screen.getByText(/Please fill in all required fields with valid numbers./i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('calculates and displays results when form is submitted with valid inputs', () => { | ||
render( | ||
<Provider store={store}> | ||
<InvestmentCalculator /> | ||
</Provider> | ||
); | ||
|
||
fireEvent.change(screen.getByLabelText(/Initial Investment/i), { target: { value: '1000' } }); | ||
fireEvent.change(screen.getByLabelText(/Monthly Inflation Rate/i), { target: { value: '0.5' } }); | ||
fireEvent.change(screen.getByLabelText(/Monthly Contribution/i), { target: { value: '100' } }); | ||
fireEvent.change(screen.getByLabelText(/Investment Period \(months\)/i), { target: { value: '12' } }); | ||
fireEvent.change(screen.getByLabelText(/Monthly Interest Rate/i), { target: { value: '1' } }); | ||
|
||
fireEvent.click(screen.getByText(/Calculate/i)); | ||
|
||
expect(screen.getByText(/Results:/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Future Value:/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Total Invested:/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Gross Profit:/i)).toBeInTheDocument(); | ||
}); | ||
}); |