Skip to content

Conversation

@rogermparent
Copy link
Contributor

@rogermparent rogermparent commented Jul 6, 2022

#2005 <- this

fixes #1954

This PR adds a new test fixture whose purpose is to contain all data types that we support, so we can ensure they work correctly.
There is also a unit tests that loads this fixture and tests each cell's tooltip content. There is also a Storybook using the fixture so it can be seen in a real browser.

The original purpose of this PR was to fix a regression I made within #1967 while adding stopPropagation to the tooltips where I forgot to re-add the String conversion.

Also refactored other parts of the tooltip to be slightly more efficient.

tooltip-data-types-fix-demo.mp4

@rogermparent rogermparent changed the title Fix tooltip casting Fix non-standard data type tooltips Jul 6, 2022
@rogermparent rogermparent self-assigned this Jul 6, 2022
@rogermparent rogermparent added the bug Something isn't working label Jul 6, 2022
@rogermparent rogermparent marked this pull request as draft July 6, 2022 04:51
@rogermparent rogermparent changed the title Fix non-standard data type tooltips Fix non-standard data type tooltips and add tests Jul 6, 2022
@mattseddon
Copy link
Contributor

Consider: #1814 (this may already be catered for but just popped into my head when watching the video)

@rogermparent rogermparent marked this pull request as ready for review July 8, 2022 04:29
Comment on lines -52 to +53
export type Value =
| string
| number
| boolean
| null
| number[]
| string[]
| boolean[]
type SingleValue = string | number | boolean | null
export type Value = SingleValue | SingleValue[]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows the Value type to hold mixed but not nested lists.

TableData
} from '../../../experiments/webview/contract'

export const dataTypesOutput: ExperimentsOutput = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll probably add more types here, I just included what has been asked for and we can work from there- I haven't tried nested lists or objects, and null breaks the table when given but it doesn't occur in JSON.

Comment on lines 646 to 692
it('should show the expected tooltip for all data types', () => {
const expectTooltipValue: (args: {
cellLabel: string
expectedTooltipResult: string
}) => void = ({ cellLabel, expectedTooltipResult }) => {
const testParamCell = screen.getByText(cellLabel)
expect(testParamCell).toBeInTheDocument()

fireEvent.mouseEnter(testParamCell, { bubbles: true })

jest.advanceTimersByTime(CELL_TOOLTIP_DELAY)
const tooltip = screen.queryByRole('tooltip')
expect(tooltip).toHaveTextContent(expectedTooltipResult)

fireEvent.mouseLeave(testParamCell, { bubbles: true })

jest.advanceTimersByTime(CELL_TOOLTIP_DELAY)
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
}

render(<App />)
fireEvent(
window,
new MessageEvent('message', {
data: {
data: testData,
data: dataTypesTableData,
type: MessageToWebviewType.SET_DATA
}
})
)

const testMetricCell = screen.getByText('1.9293')
fireEvent.mouseEnter(testMetricCell, { bubbles: true })

jest.advanceTimersByTime(CELL_TOOLTIP_DELAY)
const tooltip = screen.getByRole('tooltip')
expect(tooltip).toBeInTheDocument()
expect(tooltip).toHaveTextContent(String(testMetricNumberValue))
expectTooltipValue({
cellLabel: '1.9293',
expectedTooltipResult: '1.9293040037155151'
})
expectTooltipValue({
cellLabel: 'true',
expectedTooltipResult: 'true'
})
expectTooltipValue({
cellLabel: 'false',
expectedTooltipResult: 'false'
})
expectTooltipValue({
cellLabel: '[true, false, string, 2]',
expectedTooltipResult: '[true, false, string, 2]'
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Multiple test titles would have more clean messages, but I don't have the heart to re-render the same fixture 3+ more times to do it.

Comment on lines -60 to +56
className={tooltipStyles.padded}
content={<CellTooltip cell={cell} />}
content={<CellTooltip stringValue={stringValue} />}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Padding style moved into the base element

This should make writing play functions easier, since we can use the
full testing-library query suite
@rogermparent rogermparent changed the base branch from main to storybook-testing-library July 8, 2022 15:14
@mattseddon
Copy link
Contributor

Looks like the breakage in Storybook is from this PR: #2005 (comment)

@mattseddon
Copy link
Contributor

Did you reshuffle the PRs and not update the description titles? #2005-> this is the wrong way round, right?

Base automatically changed from storybook-testing-library to main July 12, 2022 11:59
@rogermparent
Copy link
Contributor Author

I just messed up the direction of arrows, I usually just read the ticket numbers left-to-right and don't really look at the arrows enough to even remember the usual direction apparently.

@rogermparent rogermparent enabled auto-merge (squash) July 12, 2022 12:42
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 359008a and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 96.6% (0.0% change).

View more on Code Climate.

@rogermparent rogermparent merged commit 436a1ab into main Jul 12, 2022
@rogermparent rogermparent deleted the minor-cell-fix branch July 12, 2022 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Small issues with the table tooltips

2 participants