Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 23, 2024
1 parent e441edc commit 66cd67b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
}

.gridContainer.conflictGroup {
grid-template-columns: var(--grid-type) var(--grid-info) var(--grid-date) var(--grid-confirmations) var(--grid-status) var(
--grid-actions
);
grid-template-columns:
var(--grid-type) var(--grid-info) var(--grid-date) var(--grid-confirmations) var(--grid-status)
var(--grid-actions);
grid-template-areas: 'type info date confirmations status actions';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { _UpdateSafe as UpdateSafe } from './index'
import { render } from '@/tests/test-utils'

const chain = {
recommendedMasterCopyVersion: '1.4.1',
} as ChainInfo

const warningText = 'This upgrade will invalidate all queued transactions!'

describe('Container', () => {
it('renders correctly with a queue warning', async () => {
const container = render(<UpdateSafe safeVersion="1.1.1" queueSize="10+" chain={chain} />)
await expect(container.findByText(warningText)).resolves.not.toBeNull()
})

it('renders correctly without a queue warning because no queue', async () => {
const container = render(<UpdateSafe safeVersion="1.1.1" queueSize="" chain={chain} />)
await expect(container.findByText(warningText)).rejects.toThrowError(Error)
})

it('renders correctly without a queue warning because of compatible Safe version', async () => {
const container = render(<UpdateSafe safeVersion="1.3.0" queueSize="10" chain={chain} />)
await expect(container.findByText(warningText)).rejects.toThrowError(Error)
})
})
26 changes: 21 additions & 5 deletions apps/web/src/components/tx/confirmation-views/UpdateSafe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useSafeInfo from '@/hooks/useSafeInfo'
import { useQueuedTxsLength } from '@/hooks/useTxQueue'
import ExternalLink from '@/components/common/ExternalLink'
import { maybePlural } from '@/utils/formatters'
import madProps from '@/utils/mad-props'

const QUEUE_WARNING_VERSION = '<1.3.0'

Expand All @@ -26,11 +27,15 @@ function BgBox({ children, light }: { children: ReactNode; light?: boolean }) {
)
}

function UpdateSafe() {
const { safe } = useSafeInfo()
const chain = useCurrentChain()
const queueSize = useQueuedTxsLength()
const safeVersion = safe?.version || ''
export function _UpdateSafe({
safeVersion,
queueSize,
chain,
}: {
safeVersion: string
queueSize: string
chain: ReturnType<typeof useCurrentChain>
}) {
const showQueueWarning = queueSize && semverSatisfies(safeVersion, QUEUE_WARNING_VERSION)
const latestSafeVersion = chain?.recommendedMasterCopyVersion || LATEST_SAFE_VERSION

Expand Down Expand Up @@ -62,4 +67,15 @@ function UpdateSafe() {
)
}

function useSafeVersion() {
const { safe } = useSafeInfo()
return safe?.version || ''
}

const UpdateSafe = madProps(_UpdateSafe, {
chain: useCurrentChain,
safeVersion: useSafeVersion,
queueSize: useQueuedTxsLength,
})

export default UpdateSafe

0 comments on commit 66cd67b

Please sign in to comment.