Skip to content

Commit

Permalink
fix: Lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Jan 31, 2024
1 parent 375d4bf commit 7acd10e
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'fake-indexeddb/auto'
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { toBeHex } from 'ethers'
import * as tracking from '@/services/analytics'
import { set } from 'idb-keyval'
import * as navigation from 'next/navigation'
import type { ChainInfo, SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

import { PushNotificationsBanner, _getSafesToRegister } from '.'
import { createPushNotificationPrefsIndexedDb } from '@/services/push-notifications/preferences'
Expand Down Expand Up @@ -95,6 +96,14 @@ describe('PushNotificationsBanner', () => {
})

describe('PushNotificationsBanner', () => {
const extendedSafeInfo = {
...extendedSafeInfoBuilder().build(),
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
}

beforeEach(() => {
// Reset indexedDB
indexedDB = new IDBFactory()
Expand Down Expand Up @@ -140,12 +149,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
})
Expand Down Expand Up @@ -187,12 +191,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
},
Expand Down Expand Up @@ -233,12 +232,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
},
Expand Down Expand Up @@ -277,12 +271,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
},
Expand Down Expand Up @@ -317,12 +306,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
},
Expand Down Expand Up @@ -366,12 +350,7 @@ describe('PushNotificationsBanner', () => {
safeInfo: {
loading: false,
error: undefined,
data: {
chainId: '1',
address: {
value: toBeHex('0x123', 20),
},
} as unknown as SafeInfo,
data: extendedSafeInfo,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { render, waitFor } from '@/tests/test-utils'
import * as useSafeInfoHook from '@/hooks/useSafeInfo'
import SafeModules from '..'
import type { AddressEx, SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { zeroPadValue } from 'ethers'

const MOCK_MODULE_1 = zeroPadValue('0x01', 20)
const MOCK_MODULE_2 = zeroPadValue('0x02', 20)

describe('SafeModules', () => {
const extendedSafeInfo = extendedSafeInfoBuilder().build()

it('should render placeholder label without any modules', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
modules: [] as AddressEx[],
chainId: '4',
} as SafeInfo,
safe: extendedSafeInfo,
safeAddress: '0x123',
safeError: undefined,
safeLoading: false,
Expand All @@ -26,7 +25,7 @@ describe('SafeModules', () => {

it('should render placeholder label if safe is loading', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {} as SafeInfo,
safe: extendedSafeInfo,
safeAddress: '',
safeError: undefined,
safeLoading: true,
Expand All @@ -39,6 +38,7 @@ describe('SafeModules', () => {
it('should render module addresses for defined modules', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
...extendedSafeInfo,
modules: [
{
value: MOCK_MODULE_1,
Expand All @@ -47,8 +47,7 @@ describe('SafeModules', () => {
value: MOCK_MODULE_2,
},
],
chainId: '4',
} as SafeInfo,
},
safeAddress: '0x123',
safeError: undefined,
safeLoading: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { render, waitFor } from '@/tests/test-utils'
import * as useSafeInfoHook from '@/hooks/useSafeInfo'
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { zeroPadValue } from 'ethers'
import TransactionGuards from '..'

const MOCK_GUARD = zeroPadValue('0x01', 20)
const EMPTY_LABEL = 'No transaction guard set'

describe('TransactionGuards', () => {
const extendedSafeInfo = extendedSafeInfoBuilder().build()

it('should render placeholder label without an tx guard', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
guard: null,
chainId: '4',
version: '1.3.0',
} as any as SafeInfo,
safe: extendedSafeInfo,
safeAddress: '0x123',
safeError: undefined,
safeLoading: false,
Expand All @@ -27,7 +25,7 @@ describe('TransactionGuards', () => {

it('should render null if safe is loading', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {} as SafeInfo,
safe: extendedSafeInfo,
safeAddress: '',
safeError: undefined,
safeLoading: true,
Expand All @@ -41,10 +39,11 @@ describe('TransactionGuards', () => {
it('should render null if safe version < 1.3.0', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
...extendedSafeInfo,
guard: null,
chainId: '4',
version: '1.2.0',
} as any as SafeInfo,
},
safeAddress: '0x123',
safeError: undefined,
safeLoading: false,
Expand All @@ -58,12 +57,11 @@ describe('TransactionGuards', () => {
it('should render tx guard address if defined', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
...extendedSafeInfo,
guard: {
value: MOCK_GUARD,
},
chainId: '4',
version: '1.3.0',
} as SafeInfo,
},
safeAddress: '0x123',
safeError: undefined,
safeLoading: false,
Expand Down
54 changes: 29 additions & 25 deletions src/components/transactions/SingleTx/SingleTx.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { fireEvent, render } from '@/tests/test-utils'
import SingleTx from '@/pages/transactions/tx'
import * as useSafeInfo from '@/hooks/useSafeInfo'
import type { SafeInfo, TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
import * as gatewaySDK from '@safe-global/safe-gateway-typescript-sdk'
import type { TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
import { waitFor } from '@testing-library/react'

const MOCK_SAFE_ADDRESS = '0x0000000000000000000000000000000000005AFE'
const SAFE_ADDRESS = '0x87a57cBf742CC1Fc702D0E9BF595b1E056693e2f'
Expand Down Expand Up @@ -30,23 +33,27 @@ jest.mock('next/router', () => ({
},
}))

jest.mock('@safe-global/safe-gateway-typescript-sdk', () => ({
...jest.requireActual('@safe-global/safe-gateway-typescript-sdk'),
getTransactionDetails: jest.fn(() => Promise.resolve(txDetails)),
}))
const extendedSafeInfo = extendedSafeInfoBuilder().build()

jest.spyOn(useSafeInfo, 'default').mockImplementation(() => ({
safeAddress: SAFE_ADDRESS,
safe: {
...extendedSafeInfo,
chainId: '5',
} as SafeInfo,
},
safeError: undefined,
safeLoading: false,
safeLoaded: true,
}))

describe('SingleTx', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('renders <SingleTx />', async () => {
jest.spyOn(gatewaySDK, 'getTransactionDetails').mockImplementation(() => Promise.resolve(txDetails))

const screen = render(<SingleTx />)

const button = screen.queryByText('Details')
Expand All @@ -56,28 +63,22 @@ describe('SingleTx', () => {
})

it('shows an error when the transaction has failed to load', async () => {
const getTransactionDetails = jest.spyOn(
require('@safe-global/safe-gateway-typescript-sdk'),
'getTransactionDetails',
)
getTransactionDetails.mockImplementation(() => Promise.reject(new Error('Server error')))
jest.spyOn(gatewaySDK, 'getTransactionDetails').mockImplementation(() => Promise.reject(new Error('Server error')))

const screen = render(<SingleTx />)

expect(await screen.findByText('Failed to load transaction')).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByText('Failed to load transaction')).toBeInTheDocument()
})

const button = screen.getByText('Details')
fireEvent.click(button!)

expect(screen.getByText('Server error')).toBeInTheDocument()
await waitFor(() => {
fireEvent.click(screen.getByText('Details'))
expect(screen.getByText('Server error')).toBeInTheDocument()
})
})

it('shows an error when transaction is not from the opened Safe', async () => {
const getTransactionDetails = jest.spyOn(
require('@safe-global/safe-gateway-typescript-sdk'),
'getTransactionDetails',
)
getTransactionDetails.mockImplementation(() =>
jest.spyOn(gatewaySDK, 'getTransactionDetails').mockImplementation(() =>
Promise.resolve({
...txDetails,
safeAddress: MOCK_SAFE_ADDRESS,
Expand All @@ -86,11 +87,14 @@ describe('SingleTx', () => {

const screen = render(<SingleTx />)

expect(await screen.findByText('Failed to load transaction')).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByText('Failed to load transaction')).toBeInTheDocument()
})

const button = screen.getByText('Details')
fireEvent.click(button!)
fireEvent.click(screen.getByText('Details'))

expect(screen.getByText('Transaction with this id was not found in this Safe Account')).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByText('Transaction with this id was not found in this Safe Account')).toBeInTheDocument()
})
})
})
39 changes: 15 additions & 24 deletions src/components/tx-flow/flows/SignMessage/SignMessage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { hexlify, zeroPadValue, toUtf8Bytes } from 'ethers'
import type { SafeInfo, SafeMessage, SafeMessageListPage } from '@safe-global/safe-gateway-typescript-sdk'
import { SafeMessageListItemType } from '@safe-global/safe-gateway-typescript-sdk'
Expand Down Expand Up @@ -90,19 +91,21 @@ describe('SignMessage', () => {
})

const mockUseSafeMessages = useSafeMessages as jest.Mock
const extendedSafeInfo = {
...extendedSafeInfoBuilder().build(),
version: '1.3.0',
address: {
value: zeroPadValue('0x01', 20),
},
chainId: '5',
threshold: 2,
}

beforeEach(() => {
jest.clearAllMocks()

jest.spyOn(useSafeInfoHook, 'default').mockImplementation(() => ({
safe: {
version: '1.3.0',
address: {
value: zeroPadValue('0x01', 20),
},
chainId: '5',
threshold: 2,
} as SafeInfo,
safe: extendedSafeInfo,
safeAddress: zeroPadValue('0x01', 20),
safeError: undefined,
safeLoading: false,
Expand Down Expand Up @@ -255,16 +258,10 @@ describe('SignMessage', () => {

expect(proposalSpy).toHaveBeenCalledWith(
expect.objectContaining({
safe: {
version: '1.3.0',
address: {
value: zeroPadValue('0x01', 20),
},
chainId: '5',
threshold: 2,
} as SafeInfo,
safe: extendedSafeInfo,
message: 'Hello world!',
safeAppId: 25,
//onboard: expect.anything(),
}),
)

Expand Down Expand Up @@ -363,15 +360,9 @@ describe('SignMessage', () => {

expect(confirmationSpy).toHaveBeenCalledWith(
expect.objectContaining({
safe: {
version: '1.3.0',
address: {
value: zeroPadValue('0x01', 20),
},
chainId: '5',
threshold: 2,
} as SafeInfo,
safe: extendedSafeInfo,
message: 'Hello world!',
onboard: expect.anything(),
}),
)

Expand Down
Loading

0 comments on commit 7acd10e

Please sign in to comment.