-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
13 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
56 changes: 56 additions & 0 deletions
56
components/test/brave_rewards/extension/brave_rewards/utils_test.ts
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,56 @@ | ||
/* global describe, it */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { convertBalance, convertProbiToFixed } from '../../../../brave_rewards/extension/brave_rewards/utils' | ||
|
||
describe('Rewards Panel extension - Utils', () => { | ||
describe('convertBalance', () => { | ||
it('token has letters', () => { | ||
expect(convertBalance('test', { 'USD': 10 })).toBe('0.00') | ||
}) | ||
|
||
it('rates are empty', () => { | ||
expect(convertBalance('10', {})).toBe('0.00') | ||
}) | ||
|
||
it('rate is missing', () => { | ||
expect(convertBalance('10', { 'USD': 10 }, 'EUR')).toBe('0.00') | ||
}) | ||
|
||
it('all good', () => { | ||
expect(convertBalance('10', { 'USD': 10 })).toBe('100.00') | ||
}) | ||
|
||
it('currency is provided', () => { | ||
expect(convertBalance('10', { 'USD': 10, 'EUR': 4 }, 'EUR')).toBe('40.00') | ||
}) | ||
}) | ||
|
||
describe('convertProbiToFixed', () => { | ||
it('probi is not in correct format', () => { | ||
expect(convertProbiToFixed('sdfs')).toBe('0.0') | ||
}) | ||
|
||
it('probi is not 10^18', () => { | ||
expect(convertProbiToFixed('9')).toBe('0.0') | ||
}) | ||
|
||
it('we should always round down', () => { | ||
expect(convertProbiToFixed('0999999999999999999')).toBe('0.9') | ||
}) | ||
|
||
it('regular convert', () => { | ||
expect(convertProbiToFixed('1559999999999999990')).toBe('1.5') | ||
}) | ||
|
||
it('regular convert two places', () => { | ||
expect(convertProbiToFixed('1559999999999999990', 2)).toBe('1.55') | ||
}) | ||
|
||
it('big convert', () => { | ||
expect(convertProbiToFixed('150000000000000000000000000')).toBe('150000000.0') | ||
}) | ||
}) | ||
}) |
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
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
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,66 @@ | ||
/* global describe, it */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { convertBalance, formatConverted, convertProbiToFixed } from '../../../brave_rewards/ui/utils' | ||
|
||
describe('Rewards Settings - Utils', () => { | ||
describe('convertBalance', () => { | ||
it('token has letters', () => { | ||
expect(convertBalance('test', { 'USD': 10 })).toBe('0.00') | ||
}) | ||
|
||
it('rates are empty', () => { | ||
expect(convertBalance('10', {})).toBe('0.00') | ||
}) | ||
|
||
it('rate is missing', () => { | ||
expect(convertBalance('10', { 'USD': 10 }, 'EUR')).toBe('0.00') | ||
}) | ||
|
||
it('all good', () => { | ||
expect(convertBalance('10', { 'USD': 10 })).toBe('100.00') | ||
}) | ||
|
||
it('currency is provided', () => { | ||
expect(convertBalance('10', { 'USD': 10, 'EUR': 4 }, 'EUR')).toBe('40.00') | ||
}) | ||
}) | ||
|
||
describe('formatConverted', () => { | ||
it('currency is not provided', () => { | ||
expect(formatConverted('10.00')).toBe('10.00 USD') | ||
}) | ||
|
||
it('currency is provided', () => { | ||
expect(formatConverted('10.00', 'EUR')).toBe('10.00 EUR') | ||
}) | ||
}) | ||
|
||
describe('convertProbiToFixed', () => { | ||
it('probi is not in correct format', () => { | ||
expect(convertProbiToFixed('sdfs')).toBe('0.0') | ||
}) | ||
|
||
it('probi is not 10^18', () => { | ||
expect(convertProbiToFixed('9')).toBe('0.0') | ||
}) | ||
|
||
it('we should always round down', () => { | ||
expect(convertProbiToFixed('0999999999999999999')).toBe('0.9') | ||
}) | ||
|
||
it('regular convert', () => { | ||
expect(convertProbiToFixed('1559999999999999990')).toBe('1.5') | ||
}) | ||
|
||
it('regular convert two places', () => { | ||
expect(convertProbiToFixed('1559999999999999990', 2)).toBe('1.55') | ||
}) | ||
|
||
it('big convert', () => { | ||
expect(convertProbiToFixed('150000000000000000000000000')).toBe('150000000.0') | ||
}) | ||
}) | ||
}) |