Skip to content

Commit fbdd476

Browse files
Refactor Jest configuration and remove unused mocks (#414)
* Refactor Jest configuration and remove unused mocks * Simplified Jest configuration by removing unnecessary module mappings for @multiversx/sdk-dapp-ui. * Added network configuration to initConfig for local wallet address. * Enhanced setupTests to support BigInt serialization in snapshots. * Refactored PingPongService to use helper functions and removed unused hooks and tests for improved clarity and maintainability. * Remove network configuration from initConfig for local wallet address * Fix tests --------- Co-authored-by: Tudor Morar <[email protected]>
1 parent 84b244c commit fbdd476

18 files changed

+126
-117
lines changed

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module.exports = {
1515
},
1616
transformIgnorePatterns: ['node_modules/(^.+\\\\.(ts|js)$)'],
1717
testMatch: ['**/src/**/?(*.)+(spec|test|bgTest).ts?(x)'],
18-
18+
moduleNameMapper: {
19+
'\\.(css|sass|scss)$': 'identity-obj-proxy'
20+
},
1921
moduleFileExtensions: [
2022
// Place tsx and ts to beginning as suggestion from Jest team
2123
// https://jestjs.io/docs/configuration#modulefileextensions-arraystring

src/config/config.devnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentsEnum } from 'lib';
1+
import { EnvironmentsEnum } from 'lib/sdkDapp/sdkDapp.types';
22

33
export * from './sharedConfig';
44

src/config/config.mainnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentsEnum } from 'lib';
1+
import { EnvironmentsEnum } from 'lib/sdkDapp/sdkDapp.types';
22

33
export * from './sharedConfig';
44

src/config/config.testnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentsEnum } from 'lib';
1+
import { EnvironmentsEnum } from 'lib/sdkDapp/sdkDapp.types';
22

33
export * from './sharedConfig';
44

src/pages/Dashboard/widgets/PingPongAbi/PingPongAbi.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
PingTransactionPayloadType
44
} from 'components/PingPongComponent';
55
import { useSendPingPongTransaction } from 'hooks';
6-
import { useGetPingAmount, useGetTimeToPong } from './hooks';
6+
import { getTimeToPong } from '../PingPongService/helpers/getTimeToPong';
7+
import { useGetPingAmount } from './hooks';
78

89
export const PingPongAbi = () => {
9-
const getTimeToPong = useGetTimeToPong();
1010
const { sendPingTransactionFromAbi, sendPongTransactionFromAbi } =
1111
useSendPingPongTransaction();
1212
const pingAmount = useGetPingAmount();

src/pages/Dashboard/widgets/PingPongService/PingPongService.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useGetPingTransaction,
99
useGetPongTransaction,
1010
useGetTimeToPong
11-
} from './hooks';
11+
} from './helpers';
1212

1313
// The transactions are being done by directly requesting to template-dapp service
1414
export const PingPongService = () => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import axios from 'axios';
2+
import { API_URL } from 'config';
3+
import { Transaction } from 'lib/sdkCore';
4+
5+
export const getPingTransaction = async () => {
6+
try {
7+
const { data } = await axios.post(
8+
'/ping-pong/abi/ping',
9+
{},
10+
{
11+
baseURL: API_URL
12+
}
13+
);
14+
15+
const pingTransaction = Transaction.newFromPlainObject(data);
16+
17+
return pingTransaction;
18+
} catch (err) {
19+
console.error('Unable to get Ping Transaction', err);
20+
return null;
21+
}
22+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import axios from 'axios';
2+
import { API_URL } from 'config';
3+
import { Transaction } from 'lib/sdkCore';
4+
5+
export const getPongTransaction = async () => {
6+
try {
7+
const { data } = await axios.post(
8+
'/ping-pong/abi/pong',
9+
{},
10+
{
11+
baseURL: API_URL
12+
}
13+
);
14+
15+
const pongTransaction = Transaction.newFromPlainObject(data);
16+
17+
return pongTransaction;
18+
} catch (err) {
19+
console.error('Unable to get Pong Transaction', err);
20+
return null;
21+
}
22+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import axios from 'axios';
2+
import { API_URL } from 'config';
3+
import { TimeToPongResponseType } from '../types';
4+
5+
export const getTimeToPong = async () => {
6+
try {
7+
const { data } = await axios.get<TimeToPongResponseType>(
8+
'/ping-pong/abi/time-to-pong',
9+
{
10+
baseURL: API_URL
11+
}
12+
);
13+
14+
return data.timeToPong;
15+
} catch (err) {
16+
console.error(err);
17+
return null;
18+
}
19+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './getPingTransaction';
2+
export * from './getPongTransaction';
3+
export * from './getTimeToPong';

0 commit comments

Comments
 (0)