-
-
Notifications
You must be signed in to change notification settings - Fork 142
Update Profile TrackSwitcher Icon onChange #830
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ module.exports = { | |
'plugin:react-hooks/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:testing-library/react', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
|
@@ -21,11 +22,32 @@ module.exports = { | |
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['jest', 'react', '@typescript-eslint'], | ||
plugins: ['jest', 'react', '@typescript-eslint', 'testing-library'], | ||
rules: {}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
rules: { | ||
'react/prop-types': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['*.test.ts', '*.test.tsx'], | ||
rules: { | ||
'@typescript-eslint/no-empty-function': 'off', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is sometimes easy to use an empty function for testing without creating a complex requirement |
||
'@typescript-eslint/no-unused-vars': 'off', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just my opnion here but in test files I don't think this matters too much. Maybe downgrading it to a warning rather than an error? |
||
}, | ||
}, | ||
{ | ||
files: ['*.test.tsx'], | ||
rules: { | ||
'jest/expect-expect': 'off', // testing-library's getBy___ queries are in themselves assertions | ||
}, | ||
}, | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from 'react' | ||
|
||
import { render, fireEvent, act, screen, within } from '@testing-library/react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
import { TrackSwitcher } from '../../../../../app/javascript/components/profile/contributions-summary/TrackSwitcher' | ||
|
||
import { | ||
createTrack, | ||
totalTrackReputation, | ||
} from '../../../factories/ContributionSummaryFactory' | ||
|
||
const setup = () => { | ||
const tracks = [ | ||
createTrack(), | ||
createTrack({ | ||
id: 'elixir', | ||
title: 'Elixir', | ||
iconUrl: '/icons/elixir.svg', | ||
}), | ||
] | ||
|
||
return { | ||
tracks, | ||
} | ||
} | ||
|
||
describe('TrackSwitcher', () => { | ||
test('shows value on render', () => { | ||
const { tracks } = setup() | ||
|
||
const currentTrack = tracks[0] | ||
|
||
render( | ||
<TrackSwitcher tracks={tracks} value={currentTrack} setValue={() => {}} /> | ||
) | ||
|
||
screen.getByAltText(`icon for ${currentTrack.title} track`) | ||
screen.getByText(currentTrack.title) | ||
screen.getByText(`${totalTrackReputation(currentTrack)} rep`) | ||
}) | ||
|
||
test('shows dropdown on click', async () => { | ||
const { tracks } = setup() | ||
|
||
const currentTrack = tracks[0] | ||
|
||
render( | ||
<TrackSwitcher tracks={tracks} value={currentTrack} setValue={() => {}} /> | ||
) | ||
|
||
const button = screen.getByLabelText('Open the track switcher') | ||
|
||
await act(async () => { | ||
await fireEvent.click(button) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use fireEvent because that's what I know, but looking for a reference to think points out that using userEvent might be a better way to go about this. Reference: testing-library/eslint-plugin-testing-library#162 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @neenjaw Want to change or should I merge? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are essentially the same thing, so this works and covers it, but if I'm in this piece of code again I would change it. I think good to merge |
||
}) | ||
|
||
const menu = screen.getByRole('menu') | ||
const menuItems = within(menu).queryAllByRole('menuitem') | ||
expect(menuItems).toHaveLength(tracks.length) | ||
menuItems.forEach((menuItem, index) => { | ||
within(menuItem).getByAltText(`icon for ${tracks[index].title} track`) | ||
within(menuItem).getByText(tracks[index].title) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { RepresenterFeedback } from '../../../app/javascript/components/mentoring/session/RepresenterFeedback' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :) I should do something like this from now on. |
||
import { | ||
Category, | ||
CategoryId, | ||
Track, | ||
} from '../../../app/javascript/components/profile/ContributionsSummary' | ||
|
||
export const createCategoryId = (categoryId?: CategoryId): CategoryId => | ||
categoryId ? categoryId : 'publishing' | ||
|
||
export const createCategory = (category?: Partial<Category>): Category => ({ | ||
id: createCategoryId(), | ||
reputation: 140, | ||
metricFull: '1 solution published', | ||
metricShort: '1 solution', | ||
...category, | ||
}) | ||
|
||
export const createTrack = (track?: Partial<Track>): Track => ({ | ||
id: 'javascript', | ||
title: 'JavaScript', | ||
iconUrl: '/icons/javascript.svg', | ||
categories: [ | ||
{ | ||
id: 'publishing', | ||
metricFull: 'No solutions published', | ||
metricShort: 'No solutions', | ||
reputation: 0, | ||
}, | ||
{ | ||
id: 'mentoring', | ||
metricFull: 'No students mentored', | ||
metricShort: 'No students', | ||
reputation: 0, | ||
}, | ||
{ | ||
id: 'authoring', | ||
metricFull: '3 exercises contributed', | ||
metricShort: '3 exercises', | ||
reputation: 50, | ||
}, | ||
{ | ||
id: 'building', | ||
metricFull: '2 PRs accepted', | ||
metricShort: '2 PRs accepted', | ||
reputation: 24, | ||
}, | ||
{ | ||
id: 'maintaining', | ||
metricFull: '6 PRs reviewed', | ||
metricShort: '6 PRs reviewed', | ||
reputation: 35, | ||
}, | ||
{ | ||
id: 'other', | ||
reputation: 0, | ||
}, | ||
], | ||
...track, | ||
}) | ||
|
||
export const totalTrackReputation = (track: Track): number => { | ||
return track.categories.reduce((sum: number, category: Category) => { | ||
return sum + category.reputation | ||
}, 0) | ||
} |
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.
prop-types aren't used in typescript. I think this is raising an error just because we have a mix of js and ts in the project