-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved Comparative Formula UI #573
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
abe5bd6
fix: change properties interface
c911445
test: add ComparativeFormulaUI test
ca50a69
test: remove log
9184a34
fix: bold reference status
5335bf4
test: add test
6700e28
docs: improve documentation
50f1286
Merge branch 'master' into fix/ComparativeFormulaUI
3fdb9fe
chore: add entry to changelog
a89d577
Merge branch 'fix/ComparativeFormulaUI' of github.com:CartoDB/carto-r…
05654a1
apply animated number bugfix from PR #575
juandjara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
61 changes: 61 additions & 0 deletions
61
packages/react-ui/__tests__/widgets/ComparativeFormulaWidgetUI.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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ComparativeFormulaWidgetUI from '../../src/widgets/comparative/ComparativeFormulaWidgetUI'; | ||
|
||
const SAMPLE_DATA = [ | ||
{ | ||
value: 1234 | ||
}, | ||
{ | ||
value: 12 | ||
}, | ||
{ | ||
value: 0 | ||
} | ||
]; | ||
|
||
describe('ComparativeFormulaWidgetUI', () => { | ||
test('empty', () => { | ||
const { container } = render( | ||
<ComparativeFormulaWidgetUI data={[]} animated={false} /> | ||
); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('simple', async () => { | ||
render(<ComparativeFormulaWidgetUI data={SAMPLE_DATA} animated={false} />); | ||
expect(await screen.findByText(SAMPLE_DATA[0].value)).toBeInTheDocument(); | ||
}); | ||
|
||
test('multiple', async () => { | ||
render(<ComparativeFormulaWidgetUI data={SAMPLE_DATA} animated={false} />); | ||
const data = await Promise.all( | ||
SAMPLE_DATA.map(async (d) => await screen.findByText(d.value)) | ||
); | ||
data.forEach((d) => expect(d).toBeInTheDocument()); | ||
}); | ||
|
||
test('simple - data as object', async () => { | ||
const DATA = { value: 1234 }; | ||
render(<ComparativeFormulaWidgetUI data={SAMPLE_DATA} animated={false} />); | ||
expect(await screen.findByText(DATA.value)).toBeInTheDocument(); | ||
}); | ||
|
||
test('with currency formatter', () => { | ||
render( | ||
<ComparativeFormulaWidgetUI | ||
data={SAMPLE_DATA} | ||
animated={false} | ||
formatter={(value) => { | ||
return Intl.NumberFormat('en-US', { | ||
maximumFractionDigits: 2, | ||
minimumFractionDigits: 2, | ||
notation: 'compact', | ||
compactDisplay: 'short' | ||
}).format(value); | ||
}} | ||
/> | ||
); | ||
expect(screen.getByText(/1\.23K/)).toBeInTheDocument(); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing here first .map and then .filter, vs previous .filter > .map. Is it intended @aaranadev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need to remove the undefined values, but we need to assign the correct color index before the element is removed it.
Example:
If the second value is undefined, we need the value after the first to have the third color and not the second.