-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace the ledger username with ledger hsm (#230)
- Loading branch information
Showing
4 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { afterEach, test, expect, describe } from 'bun:test'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import React from 'react'; | ||
import { Username } from './username'; | ||
|
||
expect.extend(matchers); | ||
|
||
// Test the happy path of the username component | ||
describe('Username', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
test('renders Ledger correctly', () => { | ||
render(<Username walletName="Ledger" username="NOT LEDGER" />); | ||
expect(screen.getByText('Ledger HSM')).toBeInTheDocument(); | ||
// This will be a title attribute. | ||
expect(screen.queryByText('NOT LEDGER')).not.toBeInTheDocument(); | ||
expect(screen.queryByTitle('NOT LEDGER')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
render(<Username walletName="AnyOther" username="Some Username" />); | ||
expect(screen.getByText('Some Username')).toBeInTheDocument(); | ||
expect(screen.getByTitle('Some Username')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly with truncated', () => { | ||
render(<Username walletName="AnyOther" username="Some Username" truncated />); | ||
expect(screen.getByText('Some U...ername')).toBeInTheDocument(); | ||
expect(screen.getByTitle('Some Username')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly with no username', () => { | ||
render(<Username />); | ||
expect(screen.getByText('Anonymous')).toBeInTheDocument(); | ||
expect(screen.getByTitle('Anonymous')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly with no walletName', () => { | ||
render(<Username username="Some Username" />); | ||
expect(screen.getByText('Some Username')).toBeInTheDocument(); | ||
expect(screen.getByTitle('Some Username')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly with no username and truncated', () => { | ||
render(<Username truncated />); | ||
expect(screen.getByText('Anonymous')).toBeInTheDocument(); | ||
expect(screen.getByTitle('Anonymous')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders correctly with no walletName and truncated', () => { | ||
render(<Username username="Some Very Very Long Username" truncated />); | ||
expect(screen.getByText('Some V...ername')).toBeInTheDocument(); | ||
expect(screen.queryByText('Some Very Very Long Username')).not.toBeInTheDocument(); | ||
expect(screen.getByTitle('Some Very Very Long Username')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { truncateString } from '@/utils'; | ||
|
||
/** | ||
* Special list of names for accounts based on the name of the service. | ||
*/ | ||
enum WalletDisplayNames { | ||
LEDGER = 'Ledger HSM', | ||
} | ||
|
||
export const Username = ({ | ||
className, | ||
truncated, | ||
username, | ||
walletName, | ||
}: { | ||
className?: string; | ||
truncated?: boolean; | ||
username?: string; | ||
walletName?: string; | ||
}) => { | ||
let name = username || 'Anonymous'; | ||
if (walletName !== undefined) { | ||
const walletDisplayName = walletName.toUpperCase() as keyof typeof WalletDisplayNames; | ||
name = WalletDisplayNames[walletDisplayName] ?? (username || 'Anonymous'); | ||
} | ||
if (truncated) { | ||
name = truncateString(name); | ||
} | ||
|
||
return ( | ||
<p className={className} title={username || 'Anonymous'}> | ||
{name} | ||
</p> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters