forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typo in unit test description (#45)
- Loading branch information
1 parent
63886a9
commit 256e1c6
Showing
3 changed files
with
78 additions
and
82 deletions.
There are no files selected for viewing
68 changes: 33 additions & 35 deletions
68
...rset-ui/packages/superset-ui-number-format/test/factories/createD3NumberFormatter.test.js
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 |
---|---|---|
@@ -1,49 +1,47 @@ | ||
import createD3NumberFormatter from '../../src/factories/createD3NumberFormatter'; | ||
|
||
describe('D3NumberFormatter', () => { | ||
describe('new D3NumberFormatter(config)', () => { | ||
it('requires config.formatString', () => { | ||
expect(() => createD3NumberFormatter()).toThrow(); | ||
describe('createD3NumberFormatter(config)', () => { | ||
it('requires config.formatString', () => { | ||
expect(() => createD3NumberFormatter()).toThrow(); | ||
}); | ||
describe('config.formatString', () => { | ||
it('creates a NumberFormatter with the formatString as id', () => { | ||
const formatter = createD3NumberFormatter({ formatString: '.2f' }); | ||
expect(formatter.id).toEqual('.2f'); | ||
}); | ||
describe('config.formatString', () => { | ||
it('creates a NumberFormatter with the formatString as id', () => { | ||
describe('if it is valid d3 formatString', () => { | ||
it('uses d3.format(config.formatString) as format function', () => { | ||
const formatter = createD3NumberFormatter({ formatString: '.2f' }); | ||
expect(formatter.id).toEqual('.2f'); | ||
expect(formatter.format(100)).toEqual('100.00'); | ||
}); | ||
describe('if it is valid d3 formatString', () => { | ||
it('uses d3.format(config.formatString) as format function', () => { | ||
const formatter = createD3NumberFormatter({ formatString: '.2f' }); | ||
expect(formatter.format(100)).toEqual('100.00'); | ||
}); | ||
}); | ||
describe('if it is invalid d3 formatString', () => { | ||
it('The format function displays error message', () => { | ||
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' }); | ||
expect(formatter.format(12345.67)).toEqual('12345.67 (Invalid format: i-am-groot)'); | ||
}); | ||
describe('if it is invalid d3 formatString', () => { | ||
it('The format function displays error message', () => { | ||
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' }); | ||
expect(formatter.format(12345.67)).toEqual('12345.67 (Invalid format: i-am-groot)'); | ||
}); | ||
it('also set formatter.isInvalid to true', () => { | ||
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' }); | ||
expect(formatter.isInvalid).toEqual(true); | ||
}); | ||
it('also set formatter.isInvalid to true', () => { | ||
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' }); | ||
expect(formatter.isInvalid).toEqual(true); | ||
}); | ||
}); | ||
describe('config.label', () => { | ||
it('set label if specified', () => { | ||
const formatter = createD3NumberFormatter({ | ||
formatString: '.2f', | ||
label: 'float formatter', | ||
}); | ||
expect(formatter.label).toEqual('float formatter'); | ||
}); | ||
describe('config.label', () => { | ||
it('set label if specified', () => { | ||
const formatter = createD3NumberFormatter({ | ||
formatString: '.2f', | ||
label: 'float formatter', | ||
}); | ||
expect(formatter.label).toEqual('float formatter'); | ||
}); | ||
describe('config.description', () => { | ||
it('set decription if specified', () => { | ||
const formatter = createD3NumberFormatter({ | ||
description: 'lorem ipsum', | ||
formatString: '.2f', | ||
}); | ||
expect(formatter.description).toEqual('lorem ipsum'); | ||
}); | ||
describe('config.description', () => { | ||
it('set decription if specified', () => { | ||
const formatter = createD3NumberFormatter({ | ||
description: 'lorem ipsum', | ||
formatString: '.2f', | ||
}); | ||
expect(formatter.description).toEqual('lorem ipsum'); | ||
}); | ||
}); | ||
}); |
90 changes: 44 additions & 46 deletions
90
...i/packages/superset-ui-number-format/test/factories/createSiAtMostNDigitFormatter.test.js
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 |
---|---|---|
@@ -1,51 +1,49 @@ | ||
import NumberFormatter from '../../src/NumberFormatter'; | ||
import createSiAtMostNDigitFormatter from '../../src/factories/createSiAtMostNDigitFormatter'; | ||
|
||
describe('SiAtMostNDigitFormatter', () => { | ||
describe('new SiAtMostNDigitFormatter(n)', () => { | ||
it('creates an instance of NumberFormatter', () => { | ||
const formatter = createSiAtMostNDigitFormatter({ n: 4 }); | ||
expect(formatter).toBeInstanceOf(NumberFormatter); | ||
}); | ||
it('when n is specified, it formats number in SI format with at most n significant digits', () => { | ||
const formatter = createSiAtMostNDigitFormatter({ n: 2 }); | ||
expect(formatter(10)).toBe('10'); | ||
expect(formatter(1)).toBe('1'); | ||
expect(formatter(1.0)).toBe('1'); | ||
expect(formatter(10.0)).toBe('10'); | ||
expect(formatter(10001)).toBe('10k'); | ||
expect(formatter(10100)).toBe('10k'); | ||
expect(formatter(111000000)).toBe('110M'); | ||
expect(formatter(0.23)).toBe('230m'); | ||
expect(formatter(0)).toBe('0'); | ||
expect(formatter(-10)).toBe('-10'); | ||
expect(formatter(-1)).toBe('-1'); | ||
expect(formatter(-1.0)).toBe('-1'); | ||
expect(formatter(-10.0)).toBe('-10'); | ||
expect(formatter(-10001)).toBe('-10k'); | ||
expect(formatter(-10101)).toBe('-10k'); | ||
expect(formatter(-111000000)).toBe('-110M'); | ||
expect(formatter(-0.23)).toBe('-230m'); | ||
}); | ||
it('when n is not specified, it defaults to n=3', () => { | ||
const formatter = createSiAtMostNDigitFormatter(); | ||
expect(formatter(10)).toBe('10'); | ||
expect(formatter(1)).toBe('1'); | ||
expect(formatter(1.0)).toBe('1'); | ||
expect(formatter(10.0)).toBe('10'); | ||
expect(formatter(10001)).toBe('10.0k'); | ||
expect(formatter(10100)).toBe('10.1k'); | ||
expect(formatter(111000000)).toBe('111M'); | ||
expect(formatter(0.23)).toBe('230m'); | ||
expect(formatter(0)).toBe('0'); | ||
expect(formatter(-10)).toBe('-10'); | ||
expect(formatter(-1)).toBe('-1'); | ||
expect(formatter(-1.0)).toBe('-1'); | ||
expect(formatter(-10.0)).toBe('-10'); | ||
expect(formatter(-10001)).toBe('-10.0k'); | ||
expect(formatter(-10101)).toBe('-10.1k'); | ||
expect(formatter(-111000000)).toBe('-111M'); | ||
expect(formatter(-0.23)).toBe('-230m'); | ||
}); | ||
describe('createSiAtMostNDigitFormatter({ n })', () => { | ||
it('creates an instance of NumberFormatter', () => { | ||
const formatter = createSiAtMostNDigitFormatter({ n: 4 }); | ||
expect(formatter).toBeInstanceOf(NumberFormatter); | ||
}); | ||
it('when n is specified, it formats number in SI format with at most n significant digits', () => { | ||
const formatter = createSiAtMostNDigitFormatter({ n: 2 }); | ||
expect(formatter(10)).toBe('10'); | ||
expect(formatter(1)).toBe('1'); | ||
expect(formatter(1.0)).toBe('1'); | ||
expect(formatter(10.0)).toBe('10'); | ||
expect(formatter(10001)).toBe('10k'); | ||
expect(formatter(10100)).toBe('10k'); | ||
expect(formatter(111000000)).toBe('110M'); | ||
expect(formatter(0.23)).toBe('230m'); | ||
expect(formatter(0)).toBe('0'); | ||
expect(formatter(-10)).toBe('-10'); | ||
expect(formatter(-1)).toBe('-1'); | ||
expect(formatter(-1.0)).toBe('-1'); | ||
expect(formatter(-10.0)).toBe('-10'); | ||
expect(formatter(-10001)).toBe('-10k'); | ||
expect(formatter(-10101)).toBe('-10k'); | ||
expect(formatter(-111000000)).toBe('-110M'); | ||
expect(formatter(-0.23)).toBe('-230m'); | ||
}); | ||
it('when n is not specified, it defaults to n=3', () => { | ||
const formatter = createSiAtMostNDigitFormatter(); | ||
expect(formatter(10)).toBe('10'); | ||
expect(formatter(1)).toBe('1'); | ||
expect(formatter(1.0)).toBe('1'); | ||
expect(formatter(10.0)).toBe('10'); | ||
expect(formatter(10001)).toBe('10.0k'); | ||
expect(formatter(10100)).toBe('10.1k'); | ||
expect(formatter(111000000)).toBe('111M'); | ||
expect(formatter(0.23)).toBe('230m'); | ||
expect(formatter(0)).toBe('0'); | ||
expect(formatter(-10)).toBe('-10'); | ||
expect(formatter(-1)).toBe('-1'); | ||
expect(formatter(-1.0)).toBe('-1'); | ||
expect(formatter(-10.0)).toBe('-10'); | ||
expect(formatter(-10001)).toBe('-10.0k'); | ||
expect(formatter(-10101)).toBe('-10.1k'); | ||
expect(formatter(-111000000)).toBe('-111M'); | ||
expect(formatter(-0.23)).toBe('-230m'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
.../superset-ui/packages/superset-ui-time-format/test/factories/createMultiFormatter.test.js
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