Skip to content

Commit

Permalink
Added a copy icon for the alert's ID in Graphs View.
Browse files Browse the repository at this point in the history
  • Loading branch information
florinbilt committed Apr 2, 2024
1 parent 4b0d131 commit 713dbc5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 28 deletions.
8 changes: 8 additions & 0 deletions tests/ui/mock/performance_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
"push_timestamp": "2019-08-11T09:56:40",
"push_id": 530521,
"revision": "e8fe8b0af1a7a0c64d28b4e08a9c5509d916759f"
},
{
"job_id": 260895769,
"id": 887279309,
"value": 211.24042970178886,
"push_timestamp": "2019-08-09T21:57:48",
"push_id": 477720,
"revision": "3afb892abb74c6d281f3e66431408cbb2e16b8c5"
}
]
}
Expand Down
97 changes: 69 additions & 28 deletions tests/ui/perfherder/graphs-view/graphs_view_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import fetchMock from 'fetch-mock';
import queryString from 'query-string';

Expand All @@ -17,6 +18,7 @@ import {
import GraphsViewControls from '../../../../ui/perfherder/graphs/GraphsViewControls';
import repos from '../../mock/repositories';
import testData from '../../mock/performance_summary.json';
import alertSummaries from '../../mock/alert_summaries.json';
import changelogData from '../../mock/infra_changelog.json';
import seriesData from '../../mock/performance_signature_formatted.json';
import seriesData2 from '../../mock/performance_signature_formatted2.json';
Expand All @@ -33,7 +35,7 @@ fetchMock.mock(`begin:${getApiUrl(endpoints.changelog)}`, changelogData);

const graphData = createGraphData(
testData,
[],
alertSummaries,
[...graphColors],
[...graphSymbols],
[...commonAlerts],
Expand Down Expand Up @@ -76,37 +78,40 @@ const graphsViewControls = (
hasNoData = true,
replicates = false,
handleUpdateStateParams,
selectedDataPoint = {
signature_id: testData[0].signature_id,
dataPointId: testData[0].data[1].id,
},
) => {
const updateStateParams = () => {};

return render(
<GraphsViewControls
updateStateParams={handleUpdateStateParams || updateStateParams}
highlightAlerts={false}
highlightChangelogData
highlightedRevisions={['', '']}
updateTimeRange={() => {}}
hasNoData={hasNoData}
frameworks={frameworks}
projects={repos}
timeRange={{ value: 172800, text: 'Last two days' }}
options={{}}
getTestData={() => {}}
testData={data}
getInitialData={() => ({
platforms,
})}
getSeriesData={mockGetSeriesData}
showModal={Boolean(mockShowModal)}
toggle={mockShowModal}
selectedDataPoint={{
signature_id: testData[0].signature_id,
dataPointId: testData[0].data[1].id,
}}
user={{ isStaff: true }}
updateData={() => {}}
replicates={replicates}
/>,
<Router>
<GraphsViewControls
updateStateParams={handleUpdateStateParams || updateStateParams}
highlightAlerts={false}
highlightChangelogData
highlightedRevisions={['', '']}
updateTimeRange={() => {}}
hasNoData={hasNoData}
frameworks={frameworks}
projects={repos}
timeRange={{ value: 172800, text: 'Last two days' }}
options={{}}
getTestData={() => {}}
testData={data}
getInitialData={() => ({
platforms,
})}
getSeriesData={mockGetSeriesData}
showModal={Boolean(mockShowModal)}
toggle={mockShowModal}
selectedDataPoint={selectedDataPoint}
user={{ isStaff: true }}
updateData={() => {}}
replicates={replicates}
/>
</Router>,
);
};
afterEach(cleanup);
Expand Down Expand Up @@ -216,6 +221,42 @@ test('Using select query param displays tooltip for correct datapoint', async ()
expect(platform).toHaveTextContent(testData[0].platform);
});

test("Alert's ID can be copied to clipboard from tooltip", async () => {
const selectedDataPoint = {
signature_id: testData[0].signature_id,
dataPointId: testData[0].data[5].id,
};

Object.assign(navigator, {
clipboard: {
writeText: jest.fn(),
},
});
const { getByTestId, queryByTitle } = graphsViewControls(
graphData,
false,
undefined,
undefined,
selectedDataPoint,
);

const graphContainer = await waitFor(() => getByTestId('graphContainer'));
expect(graphContainer).toBeInTheDocument();

const graphTooltip = await waitFor(() => getByTestId('graphTooltip'));
expect(graphTooltip).toBeInTheDocument();

const copyIdButton = await waitFor(() =>
queryByTitle('Copy Alert Summary id'),
);
expect(copyIdButton).toBeInTheDocument();

fireEvent.click(copyIdButton);

const alertID = alertSummaries[0].id;
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(`${alertID}`);
});

test('Using select query param displays tooltip for correct datapoint with replicates', async () => {
const { getByTestId, getByText } = graphsViewControls(graphData, false, true);

Expand Down
5 changes: 5 additions & 0 deletions ui/perfherder/graphs/GraphTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ const GraphTooltip = ({
{` Alert # ${datum.commonAlert.id}`}
</Link>
<span className="text-muted">{` - ${commonAlertStatus} `}</span>
<Clipboard
text={datum.commonAlert.id.toString()}
description="Alert Summary id"
outline
/>
<p className="small text-danger">Common alert</p>
</p>
)}
Expand Down

0 comments on commit 713dbc5

Please sign in to comment.