Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rollups): Add input's payload information (Root Payload) #120

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 20 additions & 121 deletions apps/rollups/__tests__/containers/rollups/DApp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import { CombinedError } from '@urql/core';
import { Provider, createClient } from 'urql';
import {
DApp,
EpochItem,
InputContent,
Inputs,
hexToJSON,
transformPayload,
} from '../../../src/containers/rollups/DApp';
import {
PageInfo,
useDappQuery,
useInputEdgeQuery,
PageInfo,
} from '../../../src/generated/graphql/rollups/0.9';
import { withChakraTheme } from '../../test-utilities';
const path = '../../../src/generated/graphql/rollups/0.9';
Expand Down Expand Up @@ -73,13 +71,13 @@ const inputContentProps = {
label: 'Input content label',
};

const InputsComponent = withChakraTheme(Inputs);
const edge = {
cursor: '2',
node: {
id: '1',
index: 0,
msgSender: '0x912d9dfa80c617e5e9ef4f43eca01a05cc2123e1',
payload: PAYLOAD_STRING,
timestamp: new Date().getTime() / 1000,
blockNumber: 7704915,
notices: {
Expand Down Expand Up @@ -141,29 +139,6 @@ const edge = {
},
},
};
const inputItems = [edge, edge];
const inputsProps = {
inputs: inputItems,
count: inputItems.length,
};

const EpochItemComponent = withChakraTheme(EpochItem);
const epochItemProps = {
item: {
id: '1',
index: 0,
inputs: {
totalCount: 0,
pageInfo: {
startCursor: '',
endCursor: '',
hasNextPage: false,
hasPreviousPage: false,
},
edges: [edge],
},
},
};

describe('DApp container', () => {
describe('DApp component', () => {
Expand Down Expand Up @@ -279,6 +254,24 @@ describe('DApp container', () => {
).toBeInTheDocument();
});

it('should not display internal paging when it is disabled', async () => {
render(
<InputContentComponent
items={[inputContentItems[0]]}
label="Payload"
showPagination={false}
/>
);

expect(screen.getByText('Payload')).toBeInTheDocument();
expect(
screen.queryByTestId('input-content-position')
).not.toBeInTheDocument();
expect(screen.queryByText('PREV')).not.toBeInTheDocument();
expect(screen.queryByText('NEXT')).not.toBeInTheDocument();
expect(screen.queryByText('Total 1')).not.toBeInTheDocument();
});

it('should display items count', () => {
render(<InputContentComponent {...inputContentProps} />);

Expand Down Expand Up @@ -384,100 +377,6 @@ describe('DApp container', () => {
});
});

describe('EpochItem component', () => {
it('should display epoch position', () => {
render(<EpochItemComponent {...epochItemProps} />);

expect(
screen.getByText(`Epoch ${epochItemProps.item.index + 1}`)
).toBeInTheDocument();
});
});
describe('Inputs component', () => {
it('should display items count', () => {
render(<InputsComponent {...inputsProps} />);

expect(
screen.getByText(`Total ${inputsProps.count}`)
).toBeInTheDocument();
});

it('should increase position when next position exists', async () => {
render(<InputsComponent {...inputsProps} />);

const nextButton = screen.getByTestId('inputs-next-button');

await act(() => {
fireEvent.click(nextButton);
});

await waitFor(() =>
expect(screen.getByTestId('inputs-position').innerHTML).toBe(
'2'
)
);
});

it('should not increase position when next position does not exist', async () => {
render(<InputsComponent {...inputsProps} count={1} />);

const nextButton = screen.getByTestId('inputs-next-button');

await act(() => {
fireEvent.click(nextButton);
});

await waitFor(() =>
expect(screen.getByTestId('inputs-position').innerHTML).toBe(
'1'
)
);
});

it('should decrease position when previous position exists', async () => {
render(<InputsComponent {...inputsProps} />);

const nextButton = screen.getByTestId('inputs-next-button');

await act(() => {
fireEvent.click(nextButton);
});

await waitFor(() =>
expect(screen.getByTestId('inputs-position').innerHTML).toBe(
'2'
)
);
const prevButton = screen.getByTestId('inputs-prev-button');

await act(() => {
fireEvent.click(prevButton);
});

await waitFor(() =>
expect(screen.getByTestId('inputs-position').innerHTML).toBe(
'1'
)
);
});

it('should not decrease position when previous position does not exist', async () => {
render(<InputsComponent {...inputsProps} />);

const prevButton = screen.getByTestId('inputs-prev-button');

await act(() => {
fireEvent.click(prevButton);
});

await waitFor(() =>
expect(screen.getByTestId('inputs-position').innerHTML).toBe(
'1'
)
);
});
});

describe('utils', () => {
it('should return the converted payload as true', () => {
expect(hexToJSON(PAYLOAD_JSON)).toBeTruthy();
Expand Down
3 changes: 3 additions & 0 deletions apps/rollups/graphql/documents/0.9/queries.graphql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you renaming this directory to 1.0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! For consistency even though the schema did not change between versions. Here dc16d1f are the changes

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ query inputEdge {
cursor
node {
index
payload
msgSender
timestamp
notices {
totalCount
pageInfo {
Expand Down
Loading