2024-01-02 11:04:43 +00:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import { ProposalState } from '@vegaprotocol/types';
|
|
|
|
import { MarketUpdateBanner } from './market-update-banner';
|
2024-02-26 16:17:08 +00:00
|
|
|
import { type ProposalFragment } from '@vegaprotocol/proposals';
|
2024-01-02 11:04:43 +00:00
|
|
|
|
|
|
|
describe('MarketUpdateBanner', () => {
|
|
|
|
const change = {
|
|
|
|
__typename: 'UpdateMarket' as const,
|
|
|
|
marketId: 'update-market-id',
|
|
|
|
};
|
|
|
|
|
|
|
|
const openProposal = {
|
|
|
|
__typename: 'Proposal' as const,
|
|
|
|
id: 'proposal-1',
|
|
|
|
state: ProposalState.STATE_OPEN,
|
|
|
|
terms: {
|
|
|
|
__typename: 'ProposalTerms' as const,
|
|
|
|
closingDatetime: '2023-09-27',
|
|
|
|
enactmentDatetime: '2023-09-28',
|
|
|
|
change,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const passedProposal = {
|
|
|
|
__typename: 'Proposal' as const,
|
|
|
|
id: 'proposal-2',
|
|
|
|
state: ProposalState.STATE_PASSED,
|
|
|
|
terms: {
|
|
|
|
__typename: 'ProposalTerms' as const,
|
|
|
|
closingDatetime: '2023-09-27',
|
|
|
|
enactmentDatetime: '2023-09-28',
|
|
|
|
change,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('renders content for a single open proposal', () => {
|
|
|
|
render(
|
2024-02-26 16:17:08 +00:00
|
|
|
<MarketUpdateBanner proposals={[openProposal as ProposalFragment]} />
|
2024-01-02 11:04:43 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText(/^changes have been proposed/i)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('link', { name: 'View proposal' })).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
expect.stringContaining(openProposal.id as string)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders content for a single passed proposal', () => {
|
|
|
|
render(
|
2024-02-26 16:17:08 +00:00
|
|
|
<MarketUpdateBanner proposals={[passedProposal as ProposalFragment]} />
|
2024-01-02 11:04:43 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText(/^proposal set to change market/i)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('link', { name: 'View proposal' })).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
expect.stringContaining(passedProposal.id)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders content for multiple passed proposals', () => {
|
2024-02-26 16:17:08 +00:00
|
|
|
const proposals = [openProposal, openProposal] as ProposalFragment[];
|
2024-01-02 11:04:43 +00:00
|
|
|
|
|
|
|
render(<MarketUpdateBanner proposals={proposals} />);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
new RegExp(`^There are ${proposals.length} open proposals`)
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByRole('link', { name: 'View proposals' })
|
|
|
|
).toHaveAttribute('href', expect.stringContaining('proposals'));
|
|
|
|
});
|
|
|
|
});
|