Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/components/cards/StakingOpportunitesCard/FilteredTags/FilteredTags.tsx
  • Loading branch information
olegkron committed Nov 19, 2023
2 parents bd17918 + f76267f commit 6ce5c14
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 45 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run tests
on:
push:
branches:
- master
- release
pull_request:
branches:
- master
- release
jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- name: get code
uses: actions/checkout@v3
- name: setup npm
uses: actions/setup-node@v2
- name: install bun
uses: oven-sh/setup-bun@v1
- name: install dependencies
run: bun install
- name: run tests
run: bun run test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint:css": "npx stylelint \"src/**/*.{css,pcss}\" --fix",
"format": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,pcss}\"",
"preview": "npx vite preview",
"test": "npx vitest",
"test": "npx vitest --run",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
Expand All @@ -29,6 +29,7 @@
"dayjs": "^1.11.10",
"ethers": "^5.7.2",
"i18next": "^23.6.0",
"jest": "^29.7.0",
"lightweight-charts": "^4.0.1",
"posthog-js": "^1.79.1",
"rango-sdk": "^0.1.40",
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/components/ListModal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { fireEvent, render, waitFor } from '@testing-library/react'
import { ListModal } from '../../components/modals/ListModal/ListModal'
import jest from 'jest-mock'

const mockGetItems = jest.fn().mockResolvedValue([])

describe('ListModal Component', () => {
it('renders ListModal component correctly', () => {
const { getByText, getByPlaceholderText } = render(
<ListModal getItems={mockGetItems} isOpen={true} setIsOpen={() => {}} title="Test Modal" RenderItem={() => <div>Mock Item</div>} />,
)

expect(getByText('Test Modal')).toBeInTheDocument()
expect(getByPlaceholderText('Search...')).toBeInTheDocument()
})

it('handles search functionality', async () => {
const { getByPlaceholderText, getByText } = render(
<ListModal getItems={mockGetItems} isOpen={true} setIsOpen={() => {}} title="Test Modal" RenderItem={() => <div>Mock Item</div>} />,
)

const searchInput = getByPlaceholderText('Search...')

fireEvent.change(searchInput, { target: { value: 'test search' } })

await waitFor(() => {
expect(mockGetItems).toHaveBeenCalledWith({
offset: 0,
limit: 15,
search: 'test search',
})
})

expect(getByText('Test Modal')).toBeInTheDocument()
})
})
35 changes: 35 additions & 0 deletions src/__tests__/components/SwapButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { fireEvent, render } from '@testing-library/react'
import { SwapButton } from '../../components/buttons/SwapButton/SwapButton'
import jest from 'jest-mock'
import { buttonText, ButtonType } from '../../components/buttons/SwapButton/constants'

describe('SwapButton component', () => {
const mockProps = {
swapState: {
isLoading: false,
from: {
amount: 0,
},
},
isConnected: true,
onClick: jest.fn(),
}

test('renders SwapButton correctly', () => {
const { getByText } = render(<SwapButton {...mockProps} />)
expect(getByText(buttonText[ButtonType.ENTER_AMOUNT])).toBeInTheDocument()
})

test('triggers onClick function when button is clicked', () => {
const { getByText } = render(<SwapButton {...mockProps} />)
const button = getByText(buttonText[ButtonType.ENTER_AMOUNT])
fireEvent.click(button)
expect(mockProps.onClick).toHaveBeenCalledTimes(1)
})

test('render connect wallet button', () => {
mockProps.isConnected = false
const { getByText } = render(<SwapButton {...mockProps} />)
expect(getByText(buttonText[ButtonType.CONNECT_WALLET])).toBeInTheDocument()
})
})
41 changes: 0 additions & 41 deletions src/__tests__/components/TokenArea.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export const FilteredTags: FC<FilteredTagsProps> = ({ stakingDispatch, stakingSt
<Button size="sm" variant={getAllTagStyle(filter)} onClick={() => handleTagClick(FilterCategory.all, !all)}>
{t('stakingOpportunitiesCard.filterTag.all')}
</Button>
<Button size="sm" variant={getSelectedStyle(my_holdings)} onClick={() => handleTagClick(FilterCategory.my_holdings, !my_holdings)} isDisabled={!address}>
{t('stakingOpportunitiesCard.filterTag.myHoldings')}
</Button>
{/* <Button size="sm" variant={getSelectedStyle(my_holdings)} onClick={() => handleTagClick(FilterCategory.my_holdings, !my_holdings)} isDisabled={!address}> */}
{/* My holdings */}
{/* </Button> */}
<Button size="sm" variant={getSelectedStyle(my_positions)} onClick={() => handleTagClick(FilterCategory.my_positions, !my_positions)} isDisabled={!address}>
{t('stakingOpportunitiesCard.filterTag.myPositions')}
</Button>
Expand Down

0 comments on commit 6ce5c14

Please sign in to comment.