Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminaAiren committed Feb 14, 2024
1 parent 566389a commit db39b10
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mocks/contract/audits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { SmartContractSecurityAudits } from 'types/api/contract';

export const contractAudits: SmartContractSecurityAudits = {
items: [
{ audit_company_name: 'Company-Name 1', audit_publish_date: '2024-01-31', audit_report_url: 'https://ya.ru' },
{ audit_company_name: 'Company-Name 1', audit_publish_date: '2024-01-31', audit_report_url: 'https://ya.ru' },
],
};
6 changes: 6 additions & 0 deletions playwright/utils/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const viewsEnvs = {
},
};

export const UIEnvs = {
hasContractAuditReports: [
{ name: 'NEXT_PUBLIC_HAS_CONTRACT_AUDIT_REPORTS', value: 'true' },
],
};

export const stabilityEnvs = [
{ name: 'NEXT_PUBLIC_VIEWS_ADDRESS_HIDDEN_VIEWS', value: '["top_accounts"]' },
{ name: 'NEXT_PUBLIC_VIEWS_TX_HIDDEN_FIELDS', value: '["value","fee_currency","gas_price","gas_fees","burnt_fees"]' },
Expand Down
52 changes: 52 additions & 0 deletions ui/address/contract/ContractCode.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { test as base, expect } from '@playwright/experimental-ct-react';
import React from 'react';

import * as addressMock from 'mocks/address/address';
import { contractAudits } from 'mocks/contract/audits';
import * as contractMock from 'mocks/contract/info';
import contextWithEnvs from 'playwright/fixtures/contextWithEnvs';
import * as socketServer from 'playwright/fixtures/socketServer';
import TestApp from 'playwright/TestApp';
import buildApiUrl from 'playwright/utils/buildApiUrl';
import * as configs from 'playwright/utils/configs';
import MockAddressPage from 'ui/address/testUtils/MockAddressPage';

import ContractCode from './ContractCode';

const addressHash = 'hash';
const CONTRACT_API_URL = buildApiUrl('contract', { hash: addressHash });
const CONTRACT_AUDITS_API_URL = buildApiUrl('contract_security_audits', { hash: addressHash });
const hooksConfig = {
router: {
query: { hash: addressHash },
Expand Down Expand Up @@ -229,3 +233,51 @@ test('non verified', async({ mount, page }) => {

await expect(component).toHaveScreenshot();
});

const withAuditsTest = test.extend({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context: contextWithEnvs(configs.UIEnvs.hasContractAuditReports) as any,
});

withAuditsTest('with audits feature, no audits', async({ mount, page }) => {
await page.route(CONTRACT_API_URL, (route) => route.fulfill({
status: 200,
body: JSON.stringify(contractMock.verified),
}));
await page.route(CONTRACT_AUDITS_API_URL, (route) => route.fulfill({
status: 200,
body: JSON.stringify({ items: [] }),
}));
await page.route('https://cdn.jsdelivr.net/npm/[email protected]/**', (route) => route.abort());

const component = await mount(
<TestApp>
<ContractCode addressHash={ addressHash } noSocket/>
</TestApp>,
{ hooksConfig },
);

await expect(component).toHaveScreenshot();
});

withAuditsTest('with audits feature, has audits', async({ mount, page }) => {
await page.route(CONTRACT_API_URL, (route) => route.fulfill({
status: 200,
body: JSON.stringify(contractMock.verified),
}));
await page.route(CONTRACT_AUDITS_API_URL, (route) => route.fulfill({
status: 200,
body: JSON.stringify(contractAudits),
}));

await page.route('https://cdn.jsdelivr.net/npm/[email protected]/**', (route) => route.abort());

const component = await mount(
<TestApp>
<ContractCode addressHash={ addressHash } noSocket/>
</TestApp>,
{ hooksConfig },
);

await expect(component).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/experimental-ct-react';
import React from 'react';

import TestApp from 'playwright/TestApp';

import ContractSubmitAuditForm from './ContractSubmitAuditForm';

test('base view', async({ mount }) => {

const component = await mount(
<TestApp>
{ /* eslint-disable-next-line react/jsx-no-bind */ }
<ContractSubmitAuditForm address="hash" onSuccess={ () => {} }/>
</TestApp>,
);

await expect(component).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db39b10

Please sign in to comment.