-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci-savings-plan): avoid exceeding max quantity (#13565)
ref: TAPC-1697 Signed-off-by: Lionel Bueno <[email protected]>
- Loading branch information
1 parent
c42357d
commit d67d30c
Showing
3 changed files
with
68 additions
and
4 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
54 changes: 54 additions & 0 deletions
54
...s/manager/apps/pci-savings-plan/src/components/QuantitySelector/QuantitySelector.test.tsx
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,54 @@ | ||
import React from 'react'; | ||
import { vi, describe, it, expect } from 'vitest'; | ||
import { screen, fireEvent } from '@testing-library/react'; | ||
import QuantitySelector, { MAX_QUANTITY } from './QuantitySelector'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { render } from '@/utils/testProvider'; | ||
|
||
const defaultProps = { | ||
quantity: 1, | ||
onMinusClick: vi.fn(), | ||
onPlusClick: vi.fn(), | ||
onChangeQuantity: vi.fn(), | ||
}; | ||
|
||
const setupSpecTest = async (props = defaultProps) => | ||
render(<QuantitySelector {...props} />); | ||
|
||
describe('QuantitySelector', () => { | ||
it('should render the quantity input with the correct value', async () => { | ||
await setupSpecTest(); | ||
const input = screen.getByTestId('input-quantity'); | ||
expect(input).toHaveValue(defaultProps.quantity); | ||
}); | ||
|
||
it('should call onMinusClick when minus button is clicked', async () => { | ||
await setupSpecTest(); | ||
const minusButton = screen.getByTestId('minus-button'); | ||
fireEvent.click(minusButton); | ||
expect(defaultProps.onMinusClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onPlusClick when plus button is clicked', async () => { | ||
await setupSpecTest(); | ||
const plusButton = screen.getByTestId('plus-button'); | ||
fireEvent.click(plusButton); | ||
expect(defaultProps.onPlusClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onChangeQuantity with the correct value when input changes', async () => { | ||
await setupSpecTest(); | ||
const input = screen.getByTestId('input-quantity'); | ||
fireEvent.change(input, { target: { value: '5' } }); | ||
expect(defaultProps.onChangeQuantity).toHaveBeenCalledWith(5); | ||
}); | ||
it('should not call onChangeQuantity with a value greater than MAX_QUANTITY', async () => { | ||
await setupSpecTest(); | ||
const input = screen.getByTestId('input-quantity'); | ||
fireEvent.change(input, { target: { value: MAX_QUANTITY + 1 } }); | ||
expect(defaultProps.onChangeQuantity).not.toHaveBeenCalledWith( | ||
MAX_QUANTITY + 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