-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WiiQare
committed
Apr 11, 2024
1 parent
926d318
commit ec0252c
Showing
12 changed files
with
8,262 additions
and
7,935 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
import HistoryWallet from './HistoryWallet'; // Adjust the import path as necessary | ||
|
||
describe('HistoryWallet', () => { | ||
it('renders without crashing', () => { | ||
render(<HistoryWallet />); | ||
expect(screen.getByText('Historique des transactions')).toBeInTheDocument(); | ||
}); | ||
|
||
it('switches tabs correctly', async () => { | ||
render(<HistoryWallet />); | ||
const user = userEvent.setup(); | ||
|
||
// Initial state: the first tab is selected | ||
expect(screen.getByRole('tabpanel')).toHaveTextContent(''); | ||
|
||
// Click on the second tab | ||
await user.click(screen.getAllByRole('tab')[1]); | ||
expect(screen.getByRole('tabpanel')).toHaveAttribute('id', 'simple-tabpanel-1'); | ||
|
||
// Click on the third tab | ||
await user.click(screen.getAllByRole('tab')[2]); | ||
expect(screen.getByRole('tabpanel')).toHaveAttribute('id', 'simple-tabpanel-2'); | ||
}); | ||
|
||
it('has correct accessibility props', () => { | ||
render(<HistoryWallet />); | ||
// Check for the first tab | ||
const firstTab = screen.getAllByRole('tab')[0]; | ||
expect(firstTab).toHaveAttribute('id', 'simple-tab-0'); | ||
expect(firstTab).toHaveAttribute('aria-controls', 'simple-tabpanel-0'); | ||
|
||
// Check for the second tab | ||
const secondTab = screen.getAllByRole('tab')[1]; | ||
expect(secondTab).toHaveAttribute('id', 'simple-tab-1'); | ||
expect(secondTab).toHaveAttribute('aria-controls', 'simple-tabpanel-1'); | ||
}); | ||
}); |
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,31 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import Recharge from './Recharge'; | ||
import { SessionProvider } from 'next-auth/react'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter: jest.fn().mockReturnValue({ | ||
query: { | ||
'payment-intent': 'pi_1J4JrjGswQjYFZwX0Z1Z1Z1Z', | ||
}, | ||
}), | ||
})); | ||
|
||
describe('Recharge', () => { | ||
it('renders a recharge button', () => { | ||
const queryClient = new QueryClient(); | ||
const { container } = render( | ||
<QueryClientProvider client={queryClient}> | ||
<SessionProvider | ||
session={{ | ||
user: { name: 'John Doe', data: { access_token: 'at123' } }, | ||
}} | ||
> | ||
<Recharge /> | ||
</SessionProvider> | ||
</QueryClientProvider>, | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
components/organisms/Wallet/__snapshots__/Recharge.test.js.snap
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,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Recharge renders a recharge button 1`] = ` | ||
<div> | ||
<div | ||
class="p-2 space-y-6 md:py-8 md:px-6 mb-20 md:mb-10" | ||
> | ||
<div | ||
class="border w-full rounded-lg py-8 px-6 flex flex-col flex-wrap md:flex-row justify-between items-center gap-4 bg-white cursor-pointer" | ||
> | ||
<div | ||
class="flex flex-col" | ||
> | ||
<h1 | ||
class="md:text-2xl text-gray-700 font-bold flex-wrap flex items-center gap-2 text-lg" | ||
> | ||
Récharger mon épargne | ||
</h1> | ||
<ul | ||
class="flex gap-2" | ||
> | ||
<li> | ||
<span | ||
class="flex gap-2 font-semibold text-sky" | ||
> | ||
Épargne de santé | ||
<span> | ||
/ | ||
</span> | ||
</span> | ||
</li> | ||
<li> | ||
<span | ||
class="flex gap-2 font-light text-gray-500" | ||
> | ||
Récharger mon épargne | ||
</span> | ||
</li> | ||
</ul> | ||
</div> | ||
<div | ||
class="flex flex-row flex-wrap gap-2 center justify-end space-x-2" | ||
/> | ||
</div> | ||
<div | ||
class="flex flex-col items-center justify-center py-20 gap-6" | ||
> | ||
<img | ||
alt="empty" | ||
class="w-40 opacity-80" | ||
data-nimg="1" | ||
decoding="async" | ||
height="512" | ||
loading="lazy" | ||
src="/_next/image?url=https%3A%2F%2Fi.goopics.net%2Fs7t0br.png&w=1080&q=75" | ||
srcset="/_next/image?url=https%3A%2F%2Fi.goopics.net%2Fs7t0br.png&w=640&q=75 1x, /_next/image?url=https%3A%2F%2Fi.goopics.net%2Fs7t0br.png&w=1080&q=75 2x" | ||
style="color: transparent;" | ||
width="512" | ||
/> | ||
<span | ||
class="text-xs text-gray-600" | ||
> | ||
Aucun objectif n'a été défini, le premier paiement n'est pas possible... | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
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,36 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import NewSaving from './NewSaving'; // Adjust the import path as necessary | ||
import '@testing-library/jest-dom'; | ||
|
||
describe('NewSaving Component Tests', () => { | ||
it('should render without crashing', () => { | ||
render(<NewSaving />); | ||
expect(screen.getByText(/Nouvelle épargne/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the correct number of SavingCard components', () => { | ||
render(<NewSaving />); | ||
const savingCards = screen.getAllByRole('img'); // Assuming SavingCard uses <img> for the image | ||
expect(savingCards).toHaveLength(6); // Should match the number of items in the savings array | ||
}); | ||
|
||
it('renders the CardHeader with the correct title', () => { | ||
render(<NewSaving />); | ||
expect(screen.getByText(/Nouvelle épargne/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the correct static descriptive texts', () => { | ||
render(<NewSaving />); | ||
expect(screen.getByText(/Vous éparnez pour qui, mieux pour quoi ?/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Sélectionner un type d'épargne par ceux présenter ici/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Epargner c'est vivre le futur/i)).toBeInTheDocument(); | ||
}); | ||
|
||
// This test assumes SavingCard component displays the title as text | ||
it('passes correct props to SavingCard components', () => { | ||
render(<NewSaving />); | ||
expect(screen.getByText(/Pour moi/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Famille/i)).toBeInTheDocument(); | ||
// Continue for other savings titles... | ||
}); | ||
}); |
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,35 @@ | ||
// Import the functions you wish to test | ||
const { createPaymentIntent, GenericPaymentExport } = require('./SavingHelper'); | ||
|
||
// Mocking the stripe module | ||
jest.mock('stripe', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
paymentIntents: { | ||
create: async (options) => { | ||
return { | ||
client_secret: 'mock-client-secret', | ||
...options, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}); | ||
}); | ||
|
||
describe('createPaymentIntent', () => { | ||
it('should create a payment intent with the correct options', async () => { | ||
const options = { amount: 1000, currency: 'usd' }; | ||
const paymentIntent = await createPaymentIntent(options); | ||
|
||
expect(paymentIntent).toHaveProperty('client_secret', 'mock-client-secret'); | ||
// Ensure the options are passed correctly to the mocked Stripe function | ||
expect(paymentIntent).toMatchObject(options); | ||
}); | ||
}); | ||
|
||
describe('GenericPaymentExport', () => { | ||
it('checks if GenericPaymentExport is defined', () => { | ||
expect(GenericPaymentExport).toBeDefined(); | ||
}); | ||
}); |
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
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
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,19 @@ | ||
import hello from '.././hello'; // assuming the code is in a file named 'handler.js' | ||
|
||
describe('handler function', () => { | ||
it('should respond with status 200 and JSON containing name "John Doe"', () => { | ||
// Mocking the request and response objects | ||
const req = {}; | ||
const res = { | ||
status: jest.fn(() => res), | ||
json: jest.fn(), | ||
}; | ||
|
||
// Calling the handler function with the mock request and response | ||
hello(req, res); | ||
|
||
// Assertions | ||
expect(res.status).toHaveBeenCalledWith(200); // Ensure status code is set to 200 | ||
expect(res.json).toHaveBeenCalledWith({ name: 'John Doe' }); // Ensure JSON response contains the expected name | ||
}); | ||
}); |
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
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,53 +1,7 @@ | ||
// import React from 'react'; | ||
// import { loadStripe } from '@stripe/stripe-js'; | ||
// import { Elements } from '@stripe/react-stripe-js'; | ||
|
||
// import CheckoutForm from '../components/molecules/Stripe/CheckoutForm'; | ||
|
||
// // Make sure to call loadStripe outside of a component’s render to avoid | ||
// // recreating the Stripe object on every render. | ||
// // This is your test publishable API key. | ||
// const stripePromise = loadStripe( | ||
// process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY, | ||
// ); | ||
|
||
// export default function App() { | ||
// const [clientSecret, setClientSecret] = React.useState(''); | ||
|
||
// React.useEffect(() => { | ||
// // Create PaymentIntent as soon as the page loads | ||
// fetch('/api/session', { | ||
// method: 'POST', | ||
// headers: { 'Content-Type': 'application/json' }, | ||
// body: JSON.stringify({ items: [{ id: 'xl-tshirt' }] }), | ||
// }) | ||
// .then((res) => res.json()) | ||
// .then((data) => setClientSecret(data.clientSecret)); | ||
// }, []); | ||
|
||
// const appearance = { | ||
// theme: 'flat', | ||
// }; | ||
// const options = { | ||
// clientSecret, | ||
// appearance, | ||
// }; | ||
|
||
// return ( | ||
// <div className="App"> | ||
// {clientSecret && ( | ||
// <Elements options={options} stripe={stripePromise}> | ||
// <CheckoutForm /> | ||
// </Elements> | ||
// )} | ||
// </div> | ||
// ); | ||
// } | ||
|
||
export default function App() { | ||
return ( | ||
<div className="App"> | ||
|
||
</div> | ||
); | ||
} |
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,24 @@ | ||
import { index } from './index'; // Replace with the correct path to your index file | ||
|
||
describe('index Creation', () => { | ||
test('index object is created successfully', () => { | ||
expect(index).toBeDefined(); | ||
}); | ||
|
||
test('index object has expected properties and values', () => { | ||
// Example checks, add more as needed | ||
expect(index.palette.primary.main).toBe('#f8892b'); | ||
expect(index.breakpoints.values).toEqual({ | ||
xs: 0, | ||
sm: 600, | ||
md: 1000, | ||
lg: 1200, | ||
xl: 1920, | ||
}); | ||
expect(index.typography.body1).toEqual({ | ||
fontSize: '1.1rem', | ||
fontWeight: 300, | ||
lineHeight: 1.5, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.