Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Apr 10, 2024
1 parent 8adfd8d commit 040cf75
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 9 deletions.
7 changes: 6 additions & 1 deletion apps/autonolas-registry/common-util/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ export const Details: FC<DetailsProps> = ({

<div className="right-content">
{canShowUpdateBtn && (
<Button type="primary" ghost onClick={() => handleUpdate()}>
<Button
type="primary"
ghost
onClick={() => handleUpdate()}
data-testid="service-update-button"
>
Update
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
notifyError,
notifySuccess,
} from '@autonolas/frontend-library';
import { isArray } from 'lodash';

import { useHelpers } from 'common-util/hooks';
import { SendTransactionButton } from 'common-util/TransactionHelpers/SendTransactionButton';
Expand Down Expand Up @@ -171,12 +172,13 @@ export const ActiveRegistration = ({
const totalBondEthToken = convertToEth((totalBonds || 0).toString()) || '--';

let totalTokenBonds = 0;
ethTokenBonds?.forEach((bond, index) => {
const addressCount = getNumberOfAgentAddress(
dataSource[index].agentAddresses,
);
totalTokenBonds += addressCount * bond;
});
isArray(ethTokenBonds) &&
ethTokenBonds.forEach((bond, index) => {
const addressCount = getNumberOfAgentAddress(
dataSource[index].agentAddresses,
);
totalTokenBonds += addressCount * bond;
});

return (
<div className="step-2-active-registration">
Expand Down
4 changes: 2 additions & 2 deletions apps/autonolas-registry/components/ListServices/details.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from 'react';
import { useRouter } from 'next/router';

import Details from 'common-util/Details';
import { useHelpers } from 'common-util/hooks';
import Details from '../../common-util/Details';
import { useHelpers } from '../../common-util/hooks';

import { ServiceState } from './ServiceState';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { GATEWAY_URL } from '../../../util/constants';
import AgentDetails from '../../../components/ListAgents/details';
Expand Down Expand Up @@ -123,4 +124,36 @@ describe('listAgents/details.jsx', () => {
);
});
});

it('should display update hash button only for owner and open the modal when clicked', async () => {
getAgentOwner.mockResolvedValue(dummyAddress);
const { findByRole, findByText, queryByText } = render(
wrapProvider(<AgentDetails />),
);
const updateHashButton = await findByRole('button', {
name: 'Update Hash',
});

if (!updateHashButton) {
console.log('Update Button not found');
}

expect(updateHashButton).toBeInTheDocument();

// Initially, the modal should not be visible
expect(queryByText(/Generate IPFS Hash of Metadata File/)).toBeNull();

await userEvent.click(updateHashButton);

const modalTitle = await findByText(/Generate IPFS Hash of Metadata File/);
expect(modalTitle).toBeInTheDocument();
});

it('should not display update hash button for non-owner', async () => {
getAgentOwner.mockResolvedValue('0x123');
const { queryByRole } = render(wrapProvider(<AgentDetails />));

const updateHashButton = queryByRole('button', { name: 'Update Hash' });
expect(updateHashButton).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { GATEWAY_URL } from '../../../util/constants';
import Component from '../../../components/ListComponents/details';
import {
Expand Down Expand Up @@ -113,4 +115,36 @@ describe('listComponents/details.jsx', () => {
);
});
});

it('should display update hash button only for owner and open the modal when clicked', async () => {
getComponentOwner.mockResolvedValue(dummyAddress);
const { findByRole, findByText, queryByText } = render(
wrapProvider(<Component />),
);
const updateHashButton = await findByRole('button', {
name: 'Update Hash',
});

if (!updateHashButton) {
console.log('Update Button not found');
}

expect(updateHashButton).toBeInTheDocument();

// Initially, the modal should not be visible
expect(queryByText(/Generate IPFS Hash of Metadata File/)).toBeNull();

await userEvent.click(updateHashButton);

const modalTitle = await findByText(/Generate IPFS Hash of Metadata File/);
expect(modalTitle).toBeInTheDocument();
});

it('should not display update hash button for non-owner', async () => {
getComponentOwner.mockResolvedValue('0x123');
const { queryByRole } = render(wrapProvider(<Component />));

const updateHashButton = queryByRole('button', { name: 'Update Hash' });
expect(updateHashButton).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ describe('listServices/details.jsx', () => {
).toHaveTextContent('Terminated Bonded');
});
});

it('should display "Update" button for service owner', async () => {
const mockHandleUpdate = jest.fn();

const { findByTestId } = render(
wrapProvider(<Services handleUpdate={mockHandleUpdate} />),
);

const updateButton = await findByTestId('service-update-button');

if (!updateButton) {
throw new Error('Update button not found');
}

expect(updateButton).toBeInTheDocument();
});
});

describe('SVM', () => {
Expand Down

0 comments on commit 040cf75

Please sign in to comment.