2020-01-28 18:15:31 -05:00
|
|
|
import { computeMaxFontSize } from '../src';
|
|
|
|
import { addDummyFill, removeDummyFill, SAMPLE_TEXT } from './getBBoxDummyFill';
|
2019-02-05 13:51:27 -05:00
|
|
|
|
|
|
|
describe('computeMaxFontSize(input)', () => {
|
|
|
|
describe('returns dimension of the given text', () => {
|
2019-08-06 13:47:32 -04:00
|
|
|
beforeEach(addDummyFill);
|
|
|
|
afterEach(removeDummyFill);
|
2019-02-05 13:51:27 -05:00
|
|
|
|
|
|
|
it('requires either idealFontSize or maxHeight', () => {
|
|
|
|
expect(() =>
|
|
|
|
computeMaxFontSize({
|
2020-01-28 18:15:31 -05:00
|
|
|
text: SAMPLE_TEXT[0],
|
2019-02-05 13:51:27 -05:00
|
|
|
}),
|
2020-01-28 18:15:31 -05:00
|
|
|
).toThrow();
|
2019-02-05 13:51:27 -05:00
|
|
|
});
|
|
|
|
it('computes maximum font size for given maxWidth and maxHeight', () => {
|
|
|
|
expect(
|
|
|
|
computeMaxFontSize({
|
|
|
|
maxWidth: 400,
|
|
|
|
maxHeight: 30,
|
|
|
|
text: 'sample text',
|
|
|
|
}),
|
|
|
|
).toEqual(30);
|
|
|
|
});
|
|
|
|
it('computes maximum font size for given idealFontSize and maxHeight', () => {
|
|
|
|
expect(
|
|
|
|
computeMaxFontSize({
|
|
|
|
maxHeight: 20,
|
|
|
|
idealFontSize: 40,
|
2020-01-28 18:15:31 -05:00
|
|
|
text: SAMPLE_TEXT[0],
|
2019-02-05 13:51:27 -05:00
|
|
|
}),
|
|
|
|
).toEqual(20);
|
|
|
|
});
|
|
|
|
it('computes maximum font size for given maxWidth and idealFontSize', () => {
|
|
|
|
expect(
|
|
|
|
computeMaxFontSize({
|
|
|
|
maxWidth: 250,
|
|
|
|
idealFontSize: 40,
|
2020-01-28 18:15:31 -05:00
|
|
|
text: SAMPLE_TEXT[0],
|
2019-02-05 13:51:27 -05:00
|
|
|
}),
|
|
|
|
).toEqual(25);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|