Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lubej committed Sep 8, 2023
1 parent 4f2c9b2 commit 3290be0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 76 deletions.
9 changes: 7 additions & 2 deletions src/app/lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ export async function canAccessNavigatorUsb(): Promise<boolean> {
}

export async function canAccessBle(): Promise<boolean> {
// Returns always true on web
const isSupportedOnMobile = await BleTransport.isEnabled()
let isSupportedOnMobile = false
try {
// Returns always true on web
isSupportedOnMobile = await BleTransport.isEnabled()
} catch (ex) {
/* ignore */
}
// Scan depends on requestLEScan method, which is not available on the web(feature flag)
const isSupportedOnDesktop = !!navigator?.bluetooth?.requestLEScan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,75 +65,6 @@ exports[`<FromLedger /> should render component 1`] = `
text-align: center;
}
.c6 {
display: inline-block;
box-sizing: border-box;
cursor: pointer;
font: inherit;
-webkit-text-decoration: none;
text-decoration: none;
margin: 0;
background: transparent;
overflow: visible;
text-transform: none;
border: 2px solid #7D4CDB;
border-radius: 18px;
color: #444444;
padding: 4px 22px;
font-size: 18px;
line-height: 24px;
background-color: #7D4CDB;
color: #f8f8f8;
border-radius: 18px;
-webkit-transition-property: color,background-color,border-color,box-shadow;
transition-property: color,background-color,border-color,box-shadow;
-webkit-transition-duration: 0.1s;
transition-duration: 0.1s;
-webkit-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
}
.c6:hover {
box-shadow: 0px 0px 0px 2px #7D4CDB;
}
.c6:focus {
outline: none;
box-shadow: 0 0 2px 2px #6FFFB0;
}
.c6:focus > circle,
.c6:focus > ellipse,
.c6:focus > line,
.c6:focus > path,
.c6:focus > polygon,
.c6:focus > polyline,
.c6:focus > rect {
outline: none;
box-shadow: 0 0 2px 2px #6FFFB0;
}
.c6:focus::-moz-focus-inner {
border: 0;
}
.c6:focus:not(:focus-visible) {
outline: none;
box-shadow: none;
}
.c6:focus:not(:focus-visible) > circle,.c6:focus:not(:focus-visible) > ellipse,
.c6:focus:not(:focus-visible) > line,.c6:focus:not(:focus-visible) > path,
.c6:focus:not(:focus-visible) > polygon,.c6:focus:not(:focus-visible) > polyline,
.c6:focus:not(:focus-visible) > rect {
outline: none;
box-shadow: none;
}
.c6:focus:not(:focus-visible)::-moz-focus-inner {
border: 0;
}
.c3 {
display: inline-block;
box-sizing: border-box;
Expand Down Expand Up @@ -305,19 +236,25 @@ exports[`<FromLedger /> should render component 1`] = `
class="c5"
/>
<div>
<span>
<div>
<a
aria-label="openWallet.importAccounts.bleLedger"
href="/ble"
>
<button
class="c6"
class="c3"
disabled=""
tabindex="-1"
type="button"
>
openWallet.importAccounts.bleLedger
</button>
</a>
</div>
<span
class="c4"
>
errors.bleTransportNotSupported
</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ jest.mock('react-router-dom', () => ({
useNavigate: () => jest.fn(),
}))

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => jest.fn(),
}))

jest.mock('../../../../../lib/ledger', () => ({
...jest.requireActual('../../../../../lib/ledger'),
// Throws BLE not supported
canAccessBle: () => jest.fn().mockReturnValue(false),
}))

const renderComponent = () =>
render(
<MemoryRouter>
Expand All @@ -29,6 +40,7 @@ describe('<FromLedger />', () => {
expect(container).toMatchSnapshot()

expect(screen.getByText('errors.usbTransportNotSupported')).toBeInTheDocument()
expect(screen.getByText('errors.bleTransportNotSupported')).toBeInTheDocument()
})

it('should render component with an ledger access button', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/state/importaccounts/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ describe('importAccounts Sagas', () => {
for (let i = 0; i < 3; i++) {
bleDevices.push({
device: {
deviceId: 'XX:XX:XX:XX:XX:XX',
name: 'Nano X BXAX',
deviceId: `${i}${i}:${i}${i}:${i}${i}:${i}${i}:${i}${i}:${i}${i}`,
name: `Nano X ABC${i}`,
},
localName: 'Nano X BXAX',
localName: `Nano X ABC${i}`,
rssi: -50,
txPower: 100,
})
Expand Down

0 comments on commit 3290be0

Please sign in to comment.