Skip to content

Commit cf10ac7

Browse files
authored
Playwright tests refactoring, pt.4 (blockscout#1892)
* remove feature config from the pw tests * update screenshots
1 parent 7884356 commit cf10ac7

File tree

55 files changed

+263
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+263
-883
lines changed

mocks/l2withdrawals/withdrawals.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const data = {
1+
import type { OptimisticL2WithdrawalsResponse } from 'types/api/optimisticL2';
2+
3+
export const data: OptimisticL2WithdrawalsResponse = {
24
items: [
35
{
46
challenge_period_end: null,
@@ -11,12 +13,12 @@ export const data = {
1113
private_tags: [],
1214
public_tags: [],
1315
watchlist_names: [],
16+
ens_domain_name: null,
1417
},
1518
l1_tx_hash: '0x1a235bee32ac10cb7efdad98415737484ca66386e491cde9e17d42b136dca684',
1619
l2_timestamp: '2022-02-15T12:50:02.000000Z',
1720
l2_tx_hash: '0x918cd8c5c24c17e06cd02b0379510c4ad56324bf153578fb9caaaa2fe4e7dc35',
1821
msg_nonce: 396,
19-
msg_nonce_raw: '1766847064778384329583297500742918515827483896875618958121606201292620172',
2022
msg_nonce_version: 1,
2123
status: 'Ready to prove',
2224
},
@@ -27,7 +29,6 @@ export const data = {
2729
l2_timestamp: null,
2830
l2_tx_hash: '0x2f117bee32ac10cb7efdad98415737484ca66386e491cde9e17d42b136def593',
2931
msg_nonce: 391,
30-
msg_nonce_raw: '1766847064778384329583297500742918515827483896875618958121606201292620167',
3132
msg_nonce_version: 1,
3233
status: 'Ready to prove',
3334
},
@@ -38,7 +39,6 @@ export const data = {
3839
l2_timestamp: null,
3940
l2_tx_hash: '0xe14b1f46838176702244a5343629bcecf728ca2d9881d47b4ce46e00c387d7e3',
4041
msg_nonce: 390,
41-
msg_nonce_raw: '1766847064778384329583297500742918515827483896875618958121606201292620166',
4242
msg_nonce_version: 1,
4343
status: 'Ready for relay',
4444
},

mocks/withdrawals/withdrawals.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export const data = {
1+
import type { AddressParam } from 'types/api/addressParams';
2+
import type { WithdrawalsResponse } from 'types/api/withdrawals';
3+
4+
export const data: WithdrawalsResponse = {
25
items: [
36
{
47
amount: '192175000000000',
@@ -10,7 +13,7 @@ export const data = {
1013
is_contract: false,
1114
is_verified: null,
1215
name: null,
13-
},
16+
} as AddressParam,
1417
timestamp: '2022-06-07T18:12:24.000000Z',
1518
validator_index: 49622,
1619
},
@@ -24,7 +27,7 @@ export const data = {
2427
is_contract: false,
2528
is_verified: null,
2629
name: null,
27-
},
30+
} as AddressParam,
2831
timestamp: '2022-05-07T18:12:24.000000Z',
2932
validator_index: 49621,
3033
},
@@ -38,7 +41,7 @@ export const data = {
3841
is_contract: false,
3942
is_verified: null,
4043
name: null,
41-
},
44+
} as AddressParam,
4245
timestamp: '2022-04-07T18:12:24.000000Z',
4346
validator_index: 49620,
4447
},

playwright/fixtures/mockEnvs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const fixture: TestFixture<MockEnvsFixture, { page: Page }> = async({ page }, us
1616
export default fixture;
1717

1818
export const ENVS_MAP: Record<string, Array<[string, string]>> = {
19+
optimisticRollup: [
20+
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'optimistic' ],
21+
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ],
22+
[ 'NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL', 'https://localhost:3102' ],
23+
],
1924
shibariumRollup: [
2025
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'shibarium' ],
2126
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ],
@@ -24,6 +29,10 @@ export const ENVS_MAP: Record<string, Array<[string, string]>> = {
2429
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'zkEvm' ],
2530
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ],
2631
],
32+
zkSyncRollup: [
33+
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'zkSync' ],
34+
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ],
35+
],
2736
bridgedTokens: [
2837
[ 'NEXT_PUBLIC_BRIDGED_TOKENS_CHAINS', '[{"id":"1","title":"Ethereum","short_title":"ETH","base_url":"https://eth.blockscout.com/token/"},{"id":"56","title":"Binance Smart Chain","short_title":"BSC","base_url":"https://bscscan.com/token/"},{"id":"99","title":"POA","short_title":"POA","base_url":"https://blockscout.com/poa/core/token/"}]' ],
2938
[ 'NEXT_PUBLIC_BRIDGED_TOKENS_BRIDGES', '[{"type":"omni","title":"OmniBridge","short_title":"OMNI"},{"type":"amb","title":"Arbitrary Message Bridge","short_title":"AMB"}]' ],
@@ -37,6 +46,16 @@ export const ENVS_MAP: Record<string, Array<[string, string]>> = {
3746
blockHiddenFields: [
3847
[ 'NEXT_PUBLIC_VIEWS_BLOCK_HIDDEN_FIELDS', '["burnt_fees", "total_reward", "nonce"]' ],
3948
],
49+
stabilityEnvs: [
50+
[ 'NEXT_PUBLIC_VIEWS_ADDRESS_HIDDEN_VIEWS', '["top_accounts"]' ],
51+
[ 'NEXT_PUBLIC_VIEWS_TX_HIDDEN_FIELDS', '["value","fee_currency","gas_price","gas_fees","burnt_fees"]' ],
52+
[ 'NEXT_PUBLIC_VIEWS_TX_ADDITIONAL_FIELDS', '["fee_per_gas"]' ],
53+
],
54+
beaconChain: [
55+
[ 'NEXT_PUBLIC_HAS_BEACON_CHAIN', 'true' ],
56+
],
57+
txInterpretation: [
58+
[ 'NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER', 'blockscout' ],
4059
noWalletClient: [
4160
[ 'NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID', '' ],
4261
],

playwright/utils/configs.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,3 @@ export const viewport = {
1010
export const maskColor = '#4299E1'; // blue.400
1111

1212
export const adsBannerSelector = '.adsbyslise';
13-
14-
export const featureEnvs = {
15-
beaconChain: [
16-
{ name: 'NEXT_PUBLIC_HAS_BEACON_CHAIN', value: 'true' },
17-
],
18-
optimisticRollup: [
19-
{ name: 'NEXT_PUBLIC_ROLLUP_TYPE', value: 'optimistic' },
20-
{ name: 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', value: 'https://localhost:3101' },
21-
{ name: 'NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL', value: 'https://localhost:3102' },
22-
],
23-
txInterpretation: [
24-
{ name: 'NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER', value: 'blockscout' },
25-
],
26-
zkEvmRollup: [
27-
{ name: 'NEXT_PUBLIC_ROLLUP_TYPE', value: 'zkEvm' },
28-
{ name: 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', value: 'https://localhost:3101' },
29-
],
30-
zkSyncRollup: [
31-
{ name: 'NEXT_PUBLIC_ROLLUP_TYPE', value: 'zkSync' },
32-
{ name: 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', value: 'https://localhost:3101' },
33-
],
34-
userOps: [
35-
{ name: 'NEXT_PUBLIC_HAS_USER_OPS', value: 'true' },
36-
],
37-
validators: [
38-
{ name: 'NEXT_PUBLIC_VALIDATORS_CHAIN_TYPE', value: 'stability' },
39-
],
40-
};
41-
42-
export const viewsEnvs = {
43-
block: {
44-
hiddenFields: [
45-
{ name: 'NEXT_PUBLIC_VIEWS_BLOCK_HIDDEN_FIELDS', value: '["burnt_fees", "total_reward", "nonce"]' },
46-
],
47-
},
48-
};
49-
50-
export const stabilityEnvs = [
51-
{ name: 'NEXT_PUBLIC_VIEWS_ADDRESS_HIDDEN_VIEWS', value: '["top_accounts"]' },
52-
{ name: 'NEXT_PUBLIC_VIEWS_TX_HIDDEN_FIELDS', value: '["value","fee_currency","gas_price","gas_fees","burnt_fees"]' },
53-
{ name: 'NEXT_PUBLIC_VIEWS_TX_ADDITIONAL_FIELDS', value: '["fee_per_gas"]' },
54-
];

ui/block/BlockDetails.pw.tsx

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import React from 'react';
22

33
import * as blockMock from 'mocks/blocks/block';
4-
import contextWithEnvs from 'playwright/fixtures/contextWithEnvs';
4+
import { ENVS_MAP } from 'playwright/fixtures/mockEnvs';
55
import { test, expect } from 'playwright/lib';
6-
import TestApp from 'playwright/TestApp';
7-
import * as configs from 'playwright/utils/configs';
86

97
import BlockDetails from './BlockDetails';
108
import type { BlockQuery } from './useBlockQuery';
@@ -15,43 +13,33 @@ const hooksConfig = {
1513
},
1614
};
1715

18-
test('regular block +@mobile +@dark-mode', async({ mount, page }) => {
16+
test('regular block +@mobile +@dark-mode', async({ render, page }) => {
1917
const query = {
2018
data: blockMock.base,
2119
isPending: false,
2220
} as BlockQuery;
2321

24-
const component = await mount(
25-
<TestApp>
26-
<BlockDetails query={ query }/>
27-
</TestApp>,
28-
{ hooksConfig },
29-
);
22+
const component = await render(<BlockDetails query={ query }/>, { hooksConfig });
3023

3124
await page.getByText('View details').click();
3225

3326
await expect(component).toHaveScreenshot();
3427
});
3528

36-
test('genesis block', async({ mount, page }) => {
29+
test('genesis block', async({ render, page }) => {
3730
const query = {
3831
data: blockMock.genesis,
3932
isPending: false,
4033
} as BlockQuery;
4134

42-
const component = await mount(
43-
<TestApp>
44-
<BlockDetails query={ query }/>
45-
</TestApp>,
46-
{ hooksConfig },
47-
);
35+
const component = await render(<BlockDetails query={ query }/>, { hooksConfig });
4836

4937
await page.getByText('View details').click();
5038

5139
await expect(component).toHaveScreenshot();
5240
});
5341

54-
test('with blob txs', async({ mount, page, mockEnvs }) => {
42+
test('with blob txs', async({ render, page, mockEnvs }) => {
5543
await mockEnvs([
5644
[ 'NEXT_PUBLIC_DATA_AVAILABILITY_ENABLED', 'true' ],
5745
]);
@@ -60,35 +48,21 @@ test('with blob txs', async({ mount, page, mockEnvs }) => {
6048
isPending: false,
6149
} as BlockQuery;
6250

63-
const component = await mount(
64-
<TestApp>
65-
<BlockDetails query={ query }/>
66-
</TestApp>,
67-
{ hooksConfig },
68-
);
51+
const component = await render(<BlockDetails query={ query }/>, { hooksConfig });
6952

7053
await page.getByText('View details').click();
7154

7255
await expect(component).toHaveScreenshot();
7356
});
7457

75-
const customFieldsTest = test.extend({
76-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77-
context: contextWithEnvs(configs.viewsEnvs.block.hiddenFields) as any,
78-
});
79-
80-
customFieldsTest('rootstock custom fields', async({ mount, page }) => {
58+
test('rootstock custom fields', async({ render, page, mockEnvs }) => {
59+
await mockEnvs(ENVS_MAP.blockHiddenFields);
8160
const query = {
8261
data: blockMock.rootstock,
8362
isPending: false,
8463
} as BlockQuery;
8564

86-
const component = await mount(
87-
<TestApp>
88-
<BlockDetails query={ query }/>
89-
</TestApp>,
90-
{ hooksConfig },
91-
);
65+
const component = await render(<BlockDetails query={ query }/>, { hooksConfig });
9266

9367
await page.getByText('View details').click();
9468

0 commit comments

Comments
 (0)