Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
fix: made minimum font size 8px (#83)
Browse files Browse the repository at this point in the history
* fix: made minimum font size 8px

* test: added back changed unit test

* refactor: comments

Co-Authored-By: Max Gefvert <max.gefvert@gmail.com>

* refactor: changed to 0-1 instead of 0-100

* fix: change baseline picture

* fix: changed steps to step and updated integration test

* fix: change baseline image
  • Loading branch information
eliseeborn authored Dec 2, 2019
1 parent f3c5e92 commit 4e6d343
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
Binary file modified data/apps/Executive_Dashboard.qvf
100755 → 100644
Binary file not shown.
6 changes: 3 additions & 3 deletions src/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ export default function ext({ translator }) {
type: 'number',
ref: 'style.font.size',
translation: 'properties.fontSize',
min: 1,
steps: 1,
max: 100,
min: 0.2,
max: 1,
step: 0.01,
},
useFontColorExpression: {
ref: 'style.font.useColorExpression',
Expand Down
2 changes: 1 addition & 1 deletion src/object-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const properties = {
/**
* @type {number}
*/
size: 50,
size: 0.5,
/**
* @type {boolean}
*/
Expand Down
15 changes: 13 additions & 2 deletions src/utils/__tests__/style-formatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,26 @@ describe('style-formatter', () => {
expect(text.style.justifyContent).to.equal('center');
});

it('should set fontSize when text offsetWidth is bigger than button', () => {
it('should set fontSize to 8px for small font sizes', () => {
button.appendChild = child => {
child.setAttribute = sinon.spy();
child.offsetHeight = 400;
child.offsetWidth = 400;
button.children.push(child);
};
styleFormatter.createLabelAndIcon({ Theme, button, style });
expect(button.children[0].style.fontSize).to.equal('2.875px');
expect(button.children[0].style.fontSize).to.equal('8px');
});

it('should set fontSize when text offsetWidth is bigger than button', () => {
button.appendChild = child => {
child.setAttribute = sinon.spy();
child.offsetHeight = 400;
child.offsetWidth = 125;
button.children.push(child);
};
styleFormatter.createLabelAndIcon({ Theme, button, style });
expect(button.children[0].style.fontSize).to.equal('9.2px');
});

it('should place icon first then label inside text element', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/style-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
newFontsize *= (button.clientWidth - 8) / text.offsetWidth;
}
// 4. Setting final font size by scaling with the font size from the layout + other font styling
text.style.fontSize = `${(newFontsize * style.font.size) / 100}px`;
text.style.fontSize = `${Math.max((newFontsize * style.font.size), 8)}px`;
text.style.display = 'flex';
text.style.alignItems = 'center';
text.style.justifyContent =
Expand Down
Binary file modified test/integration/__artifacts__/baseline/action-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/integration/rendering.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('should render an', () => {
const app = encodeURIComponent(process.env.APP_ID || '/apps/Executive_Dashboard.qvf');

before(async () => {
await page.goto(`${process.testServer.url}/render/app/${app}?object=mtd`);
await page.goto(`${process.testServer.url}/render/app/${app}?object=CNaxMh`);
await page.waitForSelector(content, { visible: true });
});

Expand Down

0 comments on commit 4e6d343

Please sign in to comment.