chore(trading): 4384 all markets in switcher (#4516)
This commit is contained in:
parent
069b57d4ae
commit
d624957e6d
@ -134,6 +134,20 @@ describe('MarketSelector', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Button "All" should be selected by default', () => {
|
||||||
|
const buttons = ['All', 'Futures', 'Spot', 'Perpetuals'];
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<MarketSelector currentMarketId="market-0" onSelect={jest.fn()} />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
screen
|
||||||
|
.getAllByTestId(/^product-(All|Future|Spot|Perpetual)$/)
|
||||||
|
.forEach((elem, i) => {
|
||||||
|
expect(elem.textContent).toEqual(buttons[i]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('renders only active markets', () => {
|
it('renders only active markets', () => {
|
||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
@ -169,6 +183,12 @@ describe('MarketSelector', () => {
|
|||||||
activeMarkets.length
|
activeMarkets.length
|
||||||
);
|
);
|
||||||
expect(screen.queryByTestId('no-items')).not.toBeInTheDocument();
|
expect(screen.queryByTestId('no-items')).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByTestId('product-All'));
|
||||||
|
expect(screen.queryAllByTestId(/market-\d/)).toHaveLength(
|
||||||
|
activeMarkets.length
|
||||||
|
);
|
||||||
|
expect(screen.queryByTestId('no-items')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters by search term', async () => {
|
it('filters by search term', async () => {
|
||||||
|
@ -39,7 +39,7 @@ export const MarketSelector = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [filter, setFilter] = useState<Filter>({
|
const [filter, setFilter] = useState<Filter>({
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
product: Product.Future,
|
product: Product.All,
|
||||||
sort: Sort.None,
|
sort: Sort.None,
|
||||||
assets: [],
|
assets: [],
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ import { VegaIcon, VegaIconNames } from '@vegaprotocol/ui-toolkit';
|
|||||||
|
|
||||||
// Make sure these match the available __typename properties on product
|
// Make sure these match the available __typename properties on product
|
||||||
export const Product = {
|
export const Product = {
|
||||||
|
All: 'All',
|
||||||
Future: 'Future',
|
Future: 'Future',
|
||||||
Spot: 'Spot',
|
Spot: 'Spot',
|
||||||
Perpetual: 'Perpetual',
|
Perpetual: 'Perpetual',
|
||||||
@ -16,6 +17,7 @@ export type ProductType = keyof typeof Product;
|
|||||||
const ProductTypeMapping: {
|
const ProductTypeMapping: {
|
||||||
[key in ProductType]: string;
|
[key in ProductType]: string;
|
||||||
} = {
|
} = {
|
||||||
|
[Product.All]: 'All',
|
||||||
[Product.Future]: 'Futures',
|
[Product.Future]: 'Futures',
|
||||||
[Product.Spot]: 'Spot',
|
[Product.Spot]: 'Spot',
|
||||||
[Product.Perpetual]: 'Perpetuals',
|
[Product.Perpetual]: 'Perpetuals',
|
||||||
@ -49,8 +51,12 @@ export const ProductSelector = ({
|
|||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<Link to={Routes.MARKETS} className="flex items-center gap-2 ml-auto">
|
<Link
|
||||||
<span className="underline underline-offset-4">{t('All markets')}</span>
|
to={Routes.MARKETS}
|
||||||
|
className="flex items-center gap-2 ml-auto"
|
||||||
|
title={t('See all markets')}
|
||||||
|
>
|
||||||
|
<span className="underline underline-offset-4">{t('Browse')}</span>
|
||||||
<VegaIcon name={VegaIconNames.ARROW_RIGHT} />
|
<VegaIcon name={VegaIconNames.ARROW_RIGHT} />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
@ -120,6 +120,13 @@ describe('useMarketSelectorList', () => {
|
|||||||
assets: [],
|
assets: [],
|
||||||
});
|
});
|
||||||
expect(result.current.markets).toEqual([markets[2]]);
|
expect(result.current.markets).toEqual([markets[2]]);
|
||||||
|
rerender({
|
||||||
|
searchTerm: '',
|
||||||
|
product: Product.All,
|
||||||
|
sort: Sort.None,
|
||||||
|
assets: [],
|
||||||
|
});
|
||||||
|
expect(result.current.markets).toEqual(markets);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters by asset', () => {
|
it('filters by asset', () => {
|
||||||
|
@ -5,6 +5,7 @@ import { calcCandleVolume, useMarketList } from '@vegaprotocol/markets';
|
|||||||
import { priceChangePercentage } from '@vegaprotocol/utils';
|
import { priceChangePercentage } from '@vegaprotocol/utils';
|
||||||
import type { Filter } from '../../components/market-selector/market-selector';
|
import type { Filter } from '../../components/market-selector/market-selector';
|
||||||
import { Sort } from './sort-dropdown';
|
import { Sort } from './sort-dropdown';
|
||||||
|
import { Product } from './product-selector';
|
||||||
|
|
||||||
// Used for sort order and filter
|
// Used for sort order and filter
|
||||||
const MARKET_TEMPLATE = [
|
const MARKET_TEMPLATE = [
|
||||||
@ -28,7 +29,10 @@ export const useMarketSelectorList = ({
|
|||||||
.filter((m) => isMarketActive(m.state))
|
.filter((m) => isMarketActive(m.state))
|
||||||
// only selected product type
|
// only selected product type
|
||||||
.filter((m) => {
|
.filter((m) => {
|
||||||
if (m.tradableInstrument.instrument.product.__typename === product) {
|
if (
|
||||||
|
product === Product.All ||
|
||||||
|
m.tradableInstrument.instrument.product.__typename === product
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
- by newest markets (opening timestamp) (<a name="6001-MARK-032" href="#6001-MARK-032">6001-MARK-032</a>)
|
- by newest markets (opening timestamp) (<a name="6001-MARK-032" href="#6001-MARK-032">6001-MARK-032</a>)
|
||||||
- **Must** be able to close and open the market selector (<a name="6001-MARK-066" href="#6001-MARK-066">6001-MARK-066</a>)
|
- **Must** be able to close and open the market selector (<a name="6001-MARK-066" href="#6001-MARK-066">6001-MARK-066</a>)
|
||||||
- **Must** must change color and have + or negative suffix of the price change and change color for the sparkline (<a name="6001-MARK-067" href="#6001-MARK-067">6001-MARK-067</a>)
|
- **Must** must change color and have + or negative suffix of the price change and change color for the sparkline (<a name="6001-MARK-067" href="#6001-MARK-067">6001-MARK-067</a>)
|
||||||
|
- **Must** be default tab "All" where there's no filtering by product. (<a name="6001-MARK-070" href="#6001-MARK-070">6001-MARK-070</a>)
|
||||||
|
|
||||||
## All Markets
|
## All Markets
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user