Skip to content

Commit c7b8ba7

Browse files
authored
added data tests (#54)
* added data tests * empty state
1 parent 9ba4262 commit c7b8ba7

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

packages/ui/src/components/header.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Protocol } from '@protocols/shared';
22
import { CheckIcon, ChevronsUpDownIcon, ExternalLinkIcon, PanelRightIcon } from 'lucide-react';
3+
import { DataTests } from '../lib/data-tests';
34
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from './ui/dropdown-menu';
45
import { Toggle } from './ui/toggle';
56

@@ -26,7 +27,10 @@ export const Header = ({
2627
return (
2728
<div className="flex items-center justify-between p-3 bg-background/30 backdrop-blur-2xl sticky top-0 z-50 border-b border-border">
2829
<DropdownMenu>
29-
<DropdownMenuTrigger className="flex items-center text-xl gap-8 px-3 py-2">
30+
<DropdownMenuTrigger
31+
data-test={DataTests.protocol_dropdown_trigger}
32+
className="flex items-center text-xl gap-8 px-3 py-2"
33+
>
3034
<div className="flex items-center gap-1 leading-7 font-medium">
3135
{currentProtocol.icon && currentProtocol.icon} {currentProtocol.shortName || currentProtocol.name}
3236
<span className="text-xl text-muted-foreground">Minitel</span>

packages/ui/src/components/transaction-decoder.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Popover, PopoverContent, PopoverTrigger } from './ui/popover';
2828
import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs';
2929
import { Textarea } from './ui/textarea';
3030
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip';
31+
import { DataTests } from '../lib/data-tests';
3132

3233
const MAX_TRANSACTION_SIZE = 1048576; // 1MB
3334

@@ -99,10 +100,15 @@ export function TransactionDecoder<T>({
99100
<div className="relative flex flex-col gap-4 items-center justify-center px-4 w-full">
100101
<div className="flex flex-col items-center gap-y-8 py-8 w-full">
101102
<div className="gap-4 text-foreground flex flex-col items-center justify-center text-center">
102-
<h1 className="text-xl sm:text-2xl md:text-3xl lg:text-4xl font-semibold leading-tight tracking-tight">
103+
<h1
104+
data-test={DataTests.transaction_decoder_title}
105+
className="text-xl sm:text-2xl md:text-3xl lg:text-4xl font-semibold leading-tight tracking-tight"
106+
>
103107
{title}
104108
</h1>
105-
<p className="text-muted-foreground">{subtitle}</p>
109+
<p data-test={DataTests.transaction_decoder_subtitle} className="text-muted-foreground">
110+
{subtitle}
111+
</p>
106112
</div>
107113
<div className="flex flex-col gap-4 max-w-5xl w-full mx-auto">
108114
<Card>
@@ -113,7 +119,7 @@ export function TransactionDecoder<T>({
113119
</span>
114120
<div className="flex items-center gap-2">
115121
<Dialog>
116-
<DialogTrigger asChild>
122+
<DialogTrigger data-test={DataTests.transaction_decoder_info_trigger} asChild>
117123
<Button size="icon" variant="outline">
118124
<InfoIcon />
119125
</Button>
@@ -237,6 +243,7 @@ export function TransactionDecoder<T>({
237243
(rawTxInvalid || rawTxTooLarge) && 'border-destructive focus-visible:ring-destructive',
238244
)}
239245
aria-invalid={rawTxInvalid || rawTxTooLarge}
246+
data-test={DataTests.transaction_decoder_textarea}
240247
placeholder={placeholder}
241248
id={textareaId}
242249
value={rawTransaction}
@@ -280,6 +287,7 @@ export function TransactionDecoder<T>({
280287
<span className="text-xl font-semibold">Output</span>
281288
<div className="flex items-center justify-between gap-2 overflow-hidden">
282289
<div
290+
data-test={DataTests.transaction_decoder_transaction_hash}
283291
className={cn(
284292
'flex items-center gap-2 bg-transparent dark:bg-input/30 rounded-md p-2 text-sm border border-input min-w-0',
285293
hash ? 'text-foreground' : 'text-muted-foreground',
@@ -365,13 +373,21 @@ export function TransactionDecoderTabs<T>({
365373
</TabsList>
366374
{decodedTransaction ? (
367375
<>
368-
<TabsContent className="space-y-6 overflow-y-auto" value="summary">
376+
<TabsContent
377+
data-test={DataTests.transaction_decoder_tab_content}
378+
className="space-y-6 overflow-y-auto"
379+
value="summary"
380+
>
369381
<div className="space-y-3">
370382
{decodedTransaction && renderSummary && renderSummary(decodedTransaction)}
371383
</div>
372384
</TabsContent>
373385

374-
<TabsContent value="json" className="max-h-96 overflow-y-auto border-border border rounded-md p-2 relative">
386+
<TabsContent
387+
data-test={DataTests.transaction_decoder_tab_content}
388+
value="json"
389+
className="max-h-96 overflow-y-auto border-border border rounded-md p-2 relative"
390+
>
375391
<div className="flex items-center sticky right-0 top-0 justify-end gap-2 z-10">
376392
<CopyButtonIcon
377393
variant="outline"
@@ -401,7 +417,7 @@ export function TransactionDecoderTabs<T>({
401417
</TabsContent>
402418
</>
403419
) : (
404-
<TransactionDecoderEmptyState />
420+
<TransactionDecoderEmptyState data-test={DataTests.transaction_decoder_empty_state} />
405421
)}
406422
</Tabs>
407423
</div>

packages/ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export * from './components/ui/tooltip';
2424
export * from './hooks/useIsDarkMode';
2525
export * from './hooks/useTransactionDecoder';
2626
export * from './hooks/useUrlParam';
27+
export * from './lib/data-tests';
2728
export * from './lib/utils';

packages/ui/src/lib/data-tests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export enum DataTests {
2+
protocol_dropdown_trigger = 'protocol_dropdown_trigger',
3+
transaction_decoder_title = 'transaction_decoder_title',
4+
transaction_decoder_subtitle = 'transaction_decoder_subtitle',
5+
transaction_decoder_info_trigger = 'transaction_decoder_info_trigger',
6+
transaction_decoder_textarea = 'transaction_decoder_textarea',
7+
transaction_decoder_transaction_hash = 'transaction_decoder_transaction_hash',
8+
transaction_decoder_tab_content = 'transaction_decoder_tab_content',
9+
transaction_decoder_empty_state = 'transaction_decoder_empty_state',
10+
}

0 commit comments

Comments
 (0)