@@ -11,6 +11,7 @@ import {
1111 fireEvent ,
1212 screen ,
1313 act ,
14+ within ,
1415} from 'firefox-profiler/test/fixtures/testing-library' ;
1516import * as UrlStateSelectors from '../../selectors/url-state' ;
1617
@@ -32,6 +33,7 @@ import {
3233 commitRange ,
3334 changeImplementationFilter ,
3435 changeCallTreeSummaryStrategy ,
36+ updatePreviewSelection ,
3537} from '../../actions/profile-view' ;
3638import { changeSelectedTab } from '../../actions/app' ;
3739import { selectedThreadSelectors } from '../../selectors/per-thread' ;
@@ -89,6 +91,72 @@ describe('StackChart', function () {
8991 expect ( getTooltip ( ) ) . toMatchSnapshot ( 'tooltip' ) ;
9092 } ) ;
9193
94+ it ( 'matches the snapshot and can display a tooltip with the same widths option' , ( ) => {
95+ const samples = `
96+ A[cat:DOM] A[cat:DOM] A[cat:DOM] A[cat:DOM]
97+ B[cat:DOM] B[cat:DOM] B[cat:DOM] B[cat:DOM]
98+ C[cat:Graphics] C[cat:Graphics] C[cat:Graphics] H[cat:Network]
99+ D[cat:Graphics] F[cat:Graphics] F[cat:Graphics] I[cat:Network]
100+ E[cat:Graphics] G[cat:Graphics] G[cat:Graphics]
101+ ` ;
102+ const { getTooltip, moveMouse, flushRafCalls, dispatch } =
103+ setupSamples ( samples ) ;
104+ useSameWidthsStackChart ( { flushRafCalls } ) ;
105+
106+ let drawCalls = flushDrawLog ( ) ;
107+ expect ( document . body ) . toMatchSnapshot ( 'dom' ) ;
108+ expect ( getDrawnFrames ( drawCalls ) ) . toEqual ( [
109+ 'A' ,
110+ 'B' ,
111+ 'C' ,
112+ 'H' ,
113+ 'D' ,
114+ 'F' ,
115+ 'I' ,
116+ 'E' ,
117+ 'G' ,
118+ ] ) ;
119+ expect ( drawCalls ) . toMatchSnapshot ( 'draw calls' ) ;
120+
121+ // It can also display a tooltip when hovering a stack.
122+ expect ( getTooltip ( ) ) . toBe ( null ) ;
123+
124+ moveMouse ( findFillTextPositionFromDrawLog ( drawCalls , 'I' ) ) ;
125+ expect ( getTooltip ( ) ) . toBeTruthy ( ) ;
126+ expect ( getTooltip ( ) ) . toMatchSnapshot ( 'tooltip' ) ;
127+
128+ // Let's add a preview selection and do it again.
129+ flushDrawLog ( ) ;
130+ act ( ( ) =>
131+ dispatch (
132+ updatePreviewSelection ( {
133+ hasSelection : true ,
134+ isModifying : false ,
135+ selectionStart : 2.1 ,
136+ selectionEnd : 3.1 ,
137+ } )
138+ )
139+ ) ;
140+
141+ flushRafCalls ( ) ;
142+ drawCalls = flushDrawLog ( ) ;
143+ expect ( getDrawnFrames ( drawCalls ) ) . toEqual ( [
144+ 'A' ,
145+ 'B' ,
146+ 'C' ,
147+ 'H' ,
148+ 'F' ,
149+ 'I' ,
150+ 'G' ,
151+ ] ) ;
152+ expect ( drawCalls ) . toMatchSnapshot ( 'draw calls for preview selection' ) ;
153+
154+ // It can also display a tooltip when hovering a new stack.
155+ moveMouse ( findFillTextPositionFromDrawLog ( drawCalls , 'H' ) ) ;
156+ expect ( getTooltip ( ) ) . toBeTruthy ( ) ;
157+ expect ( getTooltip ( ) ) . toMatchSnapshot ( 'tooltip after preview selection' ) ;
158+ } ) ;
159+
92160 it ( 'can select a call node when clicking the chart' , function ( ) {
93161 const { dispatch, getState, leftClick, findFillTextPosition } =
94162 setupSamples ( ) ;
@@ -163,11 +231,6 @@ describe('StackChart', function () {
163231 expect ( copy ) . toHaveBeenLastCalledWith ( 'B' ) ;
164232 } ) ;
165233
166- function getDrawnFrames ( ) {
167- const drawCalls = flushDrawLog ( ) ;
168- return drawCalls . filter ( ( [ fn ] ) => fn === 'fillText' ) . map ( ( [ , arg ] ) => arg ) ;
169- }
170-
171234 it ( 'can scroll into view when selecting a node' , function ( ) {
172235 // Create a stack deep enough to not have all its rendered frames
173236 // fit within GRAPH_HEIGHT.
@@ -284,15 +347,28 @@ describe('MarkerChart', function () {
284347 it . todo ( 'can right click a marker and show a context menu' ) ;
285348
286349 it ( 'shows a tooltip when hovering' , ( ) => {
287- const { getTooltip, moveMouse, findFillTextPosition } = setupUserTimings ( {
288- isShowUserTimingsClicked : true ,
289- } ) ;
350+ const { getTooltip, moveMouse, findFillTextPosition, flushRafCalls } =
351+ setupUserTimings ( {
352+ isShowUserTimingsClicked : true ,
353+ } ) ;
290354
291355 expect ( getTooltip ( ) ) . toBe ( null ) ;
292356
293357 moveMouse ( findFillTextPosition ( 'componentB' ) ) ;
294- expect ( getTooltip ( ) ) . toBeTruthy ( ) ;
295- expect ( getTooltip ( ) ) . toMatchSnapshot ( ) ;
358+ let tooltip = getTooltip ( ) ;
359+ expect (
360+ within ( ensureExists ( tooltip ) ) . getByText ( 'componentB' )
361+ ) . toBeInTheDocument ( ) ;
362+ expect ( tooltip ) . toMatchSnapshot ( ) ;
363+
364+ // This still matches markers with the same widths option
365+ useSameWidthsStackChart ( { flushRafCalls } ) ;
366+ moveMouse ( findFillTextPosition ( 'componentA' ) ) ;
367+ tooltip = getTooltip ( ) ;
368+ expect (
369+ within ( ensureExists ( tooltip ) ) . getByText ( 'componentA' )
370+ ) . toBeInTheDocument ( ) ;
371+ expect ( tooltip ) . toMatchSnapshot ( ) ;
296372 } ) ;
297373} ) ;
298374
@@ -312,6 +388,17 @@ function showUserTimings({ getByLabelText, flushRafCalls }) {
312388 flushRafCalls ( ) ;
313389}
314390
391+ function useSameWidthsStackChart ( { flushRafCalls } ) {
392+ flushDrawLog ( ) ;
393+ const checkbox = screen . getByLabelText ( 'Use the same width for each stack' ) ;
394+ fireFullClick ( checkbox ) ;
395+ flushRafCalls ( ) ;
396+ }
397+
398+ function getDrawnFrames ( drawCalls = flushDrawLog ( ) ) {
399+ return drawCalls . filter ( ( [ fn ] ) => fn === 'fillText' ) . map ( ( [ , arg ] ) => arg ) ;
400+ }
401+
315402function setupCombinedTimings ( ) {
316403 const userTimingsProfile = getProfileWithMarkers ( [
317404 getUserTiming ( 'renderFunction' , 0 , 10 ) ,
@@ -467,6 +554,7 @@ function setup(store, funcNames: string[] = []) {
467554
468555 function moveMouse ( where ) {
469556 fireMouseEvent ( 'mousemove' , getPositioningOptions ( where ) ) ;
557+ flushRafCalls ( ) ;
470558 }
471559
472560 // Context menu tools
0 commit comments