fix: proposals list spec
This commit is contained in:
parent
42079206b4
commit
de42caa2a3
@ -1,77 +1,42 @@
|
|||||||
import { render, screen, waitFor, within } from '@testing-library/react';
|
import { render, screen, waitFor, within } from '@testing-library/react';
|
||||||
import merge from 'lodash/merge';
|
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { ProposalsList } from './proposals-list';
|
import { ProposalsList } from './proposals-list';
|
||||||
import * as Types from '@vegaprotocol/types';
|
import { MarketState } from '@vegaprotocol/types';
|
||||||
|
import { createMarketFragment } from '@vegaprotocol/mock';
|
||||||
import {
|
import {
|
||||||
createProposalListFieldsFragment,
|
type MarketsQuery,
|
||||||
ProposalsListDocument,
|
MarketsDocument,
|
||||||
type ProposalsListQuery,
|
type MarketsQueryVariables,
|
||||||
} from '@vegaprotocol/proposals';
|
} from '@vegaprotocol/markets';
|
||||||
import type { PartialDeep } from 'type-fest';
|
|
||||||
|
|
||||||
const parentMarketName = 'Parent Market Name';
|
const parentMarketName = 'Parent Market Name';
|
||||||
const ParentMarketCell = () => <span>{parentMarketName}</span>;
|
const ParentMarketCell = () => <span>{parentMarketName}</span>;
|
||||||
|
|
||||||
describe('ProposalsList', () => {
|
describe('ProposalsList', () => {
|
||||||
const rowContainerSelector = '.ag-center-cols-container';
|
const rowContainerSelector = '.ag-center-cols-container';
|
||||||
|
const market = createMarketFragment({
|
||||||
const createProposalsMock = (override?: PartialDeep<ProposalsListQuery>) => {
|
state: MarketState.STATE_PROPOSED,
|
||||||
const defaultProposalEdges = [
|
|
||||||
{
|
|
||||||
__typename: 'ProposalEdge' as const,
|
|
||||||
node: createProposalListFieldsFragment({
|
|
||||||
id: 'id-1',
|
|
||||||
state: Types.ProposalState.STATE_OPEN,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
__typename: 'ProposalEdge' as const,
|
|
||||||
node: createProposalListFieldsFragment({
|
|
||||||
id: 'id-2',
|
|
||||||
state: Types.ProposalState.STATE_PASSED,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
__typename: 'ProposalEdge' as const,
|
|
||||||
node: createProposalListFieldsFragment({
|
|
||||||
id: 'id-3',
|
|
||||||
state: Types.ProposalState.STATE_WAITING_FOR_NODE_VOTE,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const data = merge(
|
|
||||||
{
|
|
||||||
proposalsConnection: {
|
|
||||||
__typename: 'ProposalsConnection' as const,
|
|
||||||
edges: defaultProposalEdges,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
override
|
|
||||||
);
|
|
||||||
|
|
||||||
const mock: MockedResponse<ProposalsListQuery> = {
|
|
||||||
request: {
|
|
||||||
query: ProposalsListDocument,
|
|
||||||
variables: {
|
|
||||||
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
result: {
|
|
||||||
data,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return mock;
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be properly rendered', async () => {
|
it('should be properly rendered', async () => {
|
||||||
const mock = createProposalsMock();
|
const mock: MockedResponse<MarketsQuery, MarketsQueryVariables> = {
|
||||||
|
request: {
|
||||||
|
query: MarketsDocument,
|
||||||
|
},
|
||||||
|
result: {
|
||||||
|
data: {
|
||||||
|
marketsConnection: {
|
||||||
|
edges: [
|
||||||
|
{
|
||||||
|
node: market,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<MockedProvider mocks={[mock]}>
|
<MockedProvider mocks={[mock]}>
|
||||||
<ProposalsList cellRenderers={{ ParentMarketCell }} />
|
<ProposalsList cellRenderers={{ ParentMarketCell }} />
|
||||||
@ -104,30 +69,25 @@ describe('ProposalsList', () => {
|
|||||||
|
|
||||||
expect(await container.findAllByRole('row')).toHaveLength(
|
expect(await container.findAllByRole('row')).toHaveLength(
|
||||||
// @ts-ignore data is mocked
|
// @ts-ignore data is mocked
|
||||||
mock?.result?.data.proposalsConnection.edges.length
|
mock?.result?.data.marketsConnection.edges.length
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
container.getAllByRole('gridcell', {
|
container.getAllByRole('gridcell', {
|
||||||
name: (_, element) =>
|
name: (_, element) =>
|
||||||
element.getAttribute('col-id') ===
|
element.getAttribute('col-id') === 'parentMarketID',
|
||||||
'terms.change.successorConfiguration.parentMarketId',
|
|
||||||
})[0]
|
})[0]
|
||||||
).toHaveTextContent(parentMarketName);
|
).toHaveTextContent(parentMarketName);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('empty response should causes no data message display', async () => {
|
it('empty response should causes no data message display', async () => {
|
||||||
const mock: MockedResponse<ProposalsListQuery> = {
|
const mock: MockedResponse<MarketsQuery, MarketsQueryVariables> = {
|
||||||
request: {
|
request: {
|
||||||
query: ProposalsListDocument,
|
query: MarketsDocument,
|
||||||
variables: {
|
|
||||||
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: {
|
data: {
|
||||||
proposalsConnection: {
|
marketsConnection: {
|
||||||
__typename: 'ProposalsConnection',
|
|
||||||
edges: [],
|
edges: [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user