Skip to content
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

#1367: Added Recent Artists Pie Chart to ListeningHistory #1599

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alicemmartinez
Copy link

Have not written test cases, or completely implemented filtering algorithm for range of dates. I was hoping you could guide me to where I could write test cases for my added subcomponent?

@alicemmartinez alicemmartinez changed the base branch from feature/listening-history to master April 26, 2024 18:12
@nukeop
Copy link
Owner

nukeop commented Apr 26, 2024

  • You can try moving this component to the ui package, and creating a story for it (using storybook). Then we could see what it looks like in various scenarios easily.
  • In that package, there's an easy setup for snapshot tests (look for a function called makeSnapshotTest). If the chart is rendered in svg that's all we're going to need. You can also try adding more involved unit tests for any edge cases you can think of.
  • If you do it that way, then this component can be imported into the app package, in the ListeningHistoryView component, and fed data from there. No need IMO to write any additional tests there. Just update existing snapshots (jest -u).

];

// Function to get the top N items from the data based on a given key
const getTopN = (data: any[], key: string, n: number): any[] => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this function better by making it generic (<T>), instead if using any. That way we can ensure type safety for its input and output.

data: any[];
}

const timeframes = ['Last 7 days', 'Last 30 days', 'Last 90 days', 'Last 180 days', 'Last 365 days', 'All time'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nuclear is translated into more than 30 languages. So we should never use hardcoded strings like these, and instead use react-i18next. Try looking for the useTranslation hook to see how it's used.

If you decide to move this component to the ui package, you can simply feed it strings it needs to render its interface. For an example of how it can be done, you can look for TrackPopupStrings. The idea is that the component in ui takes a list of texts it's going to render, and in the app package, when we want to use that component, we look up the translated texts using the useTranslation hook. If you're unsure how to do this, let me know.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same comment applies to other instances of raw text, like Timeframe, etc.

</select>
</label>

<label style={{ marginLeft: '20px' }}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the style attribute, try using scss files and classes, it separates the styles from the markup.

@@ -0,0 +1,55 @@
import React from 'react';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention for tests is to use <container>.test.ts.

];

describe('PieChartTopArtists', () => {
test('renders without crashing', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced with a snapshot test, which gives us the same information, and also records what the component looks like in the HTML.

@nukeop nukeop added the needs changes The author needs to make changes to this pull request. label Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs changes The author needs to make changes to this pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants