From f8da10fa0f5129aa3ce28cbadd5593cd7e0f220d Mon Sep 17 00:00:00 2001 From: eduardo aleixo Date: Thu, 23 Sep 2021 12:48:22 -0300 Subject: [PATCH] Fix reset view (#414) * frontend: fix reset view function * cypress: add test for 'Reset View' button --- cypress/fixtures/simple-golang-app-cpu.json | 74 +++++++++++++++++++ cypress/integration/basic.ts | 15 ++++ .../__snapshots__/ProfilerHeader.spec.js.snap | 1 + .../FlameGraph/FlameGraphComponent/index.jsx | 8 +- .../FlameGraph/FlameGraphRenderer.jsx | 39 +++------- .../javascript/components/ProfilerHeader.jsx | 1 + 6 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 cypress/fixtures/simple-golang-app-cpu.json diff --git a/cypress/fixtures/simple-golang-app-cpu.json b/cypress/fixtures/simple-golang-app-cpu.json new file mode 100644 index 0000000000..d990b248df --- /dev/null +++ b/cypress/fixtures/simple-golang-app-cpu.json @@ -0,0 +1,74 @@ +{ + "flamebearer": { + "names": [ + "total", + "runtime.main", + "main.slowFunction", + "main.work", + "main.main", + "main.fastFunction" + ], + "levels": [ + [ + 0, + 988, + 0, + 0 + ], + [ + 0, + 988, + 0, + 1 + ], + [ + 0, + 214, + 0, + 5, + 0, + 3, + 2, + 4, + 0, + 771, + 0, + 2 + ], + [ + 0, + 214, + 214, + 3, + 2, + 1, + 1, + 5, + 0, + 771, + 771, + 3 + ] + ], + "numTicks": 988, + "maxSelf": 771, + "spyName": "gospy", + "sampleRate": 100, + "units": "samples", + "format": "single" + }, + "metadata": { + "format": "single", + "sampleRate": 100, + "spyName": "gospy", + "units": "samples" + }, + "timeline": { + "startTime": 1632335270, + "samples": [ + 989 + ], + "durationDelta": 10 + } +} + diff --git a/cypress/integration/basic.ts b/cypress/integration/basic.ts index d1c0abf490..93dcc64564 100644 --- a/cypress/integration/basic.ts +++ b/cypress/integration/basic.ts @@ -1,3 +1,4 @@ +import { BAR_HEIGHT } from '../../webapp/javascript/components/FlameGraph/FlameGraphComponent/index.jsx' /// describe('basic test', () => { it('successfully loads', () => { @@ -156,5 +157,19 @@ describe('basic test', () => { }) }); + it('validates "Reset View" works', () => { + cy.intercept('**/render*', { + fixture: 'simple-golang-app-cpu.json', + }).as('render') + + cy.visit('/') + + cy.findByTestId('reset-view').should('not.be.visible'); + cy.findByTestId('flamegraph-canvas') + .click(0, BAR_HEIGHT) + cy.findByTestId('reset-view').should('be.visible'); + cy.findByTestId('reset-view').click(); + cy.findByTestId('reset-view').should('not.be.visible'); + }); }) diff --git a/webapp/__tests__/__snapshots__/ProfilerHeader.spec.js.snap b/webapp/__tests__/__snapshots__/ProfilerHeader.spec.js.snap index fda1cf59a0..515141917f 100644 --- a/webapp/__tests__/__snapshots__/ProfilerHeader.spec.js.snap +++ b/webapp/__tests__/__snapshots__/ProfilerHeader.spec.js.snap @@ -33,6 +33,7 @@ exports[`ProfilerHeader render correctly ProfilerHeader component 1`] = `