fix(editor): Add telemetry to workflow history (#7811)
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
} from '@/stores/__tests__/utils/workflowHistoryTestUtils';
|
||||
import type { WorkflowVersion } from '@/types/workflowHistory';
|
||||
import type { IWorkflowDb } from '@/Interface';
|
||||
import { telemetry } from '@/plugins/telemetry';
|
||||
|
||||
vi.mock('vue-router', () => {
|
||||
const params = {};
|
||||
@@ -56,7 +57,9 @@ const renderComponent = createComponentRenderer(WorkflowHistoryPage, {
|
||||
},
|
||||
template: `<div>
|
||||
<button data-test-id="stub-preview-button" @click="event => $emit('preview', {id, event})" />
|
||||
<button data-test-id="stub-open-button" @click="() => $emit('action', { action: 'open', id })" />
|
||||
<button data-test-id="stub-clone-button" @click="() => $emit('action', { action: 'clone', id })" />
|
||||
<button data-test-id="stub-download-button" @click="() => $emit('action', { action: 'download', id })" />
|
||||
</div>`,
|
||||
}),
|
||||
},
|
||||
@@ -85,6 +88,7 @@ describe('WorkflowHistory', () => {
|
||||
vi.spyOn(workflowsStore, 'fetchWorkflow').mockResolvedValue({} as IWorkflowDb);
|
||||
vi.spyOn(workflowHistoryStore, 'getWorkflowHistory').mockResolvedValue(historyData);
|
||||
vi.spyOn(workflowHistoryStore, 'getWorkflowVersion').mockResolvedValue(versionData);
|
||||
vi.spyOn(telemetry, 'track').mockImplementation(() => {});
|
||||
windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
|
||||
});
|
||||
|
||||
@@ -97,12 +101,15 @@ describe('WorkflowHistory', () => {
|
||||
|
||||
renderComponent({ pinia });
|
||||
|
||||
await waitFor(() =>
|
||||
await waitFor(() => {
|
||||
expect(router.replace).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW_HISTORY,
|
||||
params: { workflowId, versionId: versionData.versionId },
|
||||
}),
|
||||
);
|
||||
});
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User opened workflow history', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should load version data if path contains /:versionId', async () => {
|
||||
@@ -113,8 +120,13 @@ describe('WorkflowHistory', () => {
|
||||
|
||||
renderComponent({ pinia });
|
||||
|
||||
await waitFor(() => expect(router.replace).not.toHaveBeenCalled());
|
||||
expect(getWorkflowVersionSpy).toHaveBeenCalledWith(workflowId, versionData.versionId);
|
||||
await waitFor(() => {
|
||||
expect(router.replace).not.toHaveBeenCalled();
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User selected version', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should change path on preview', async () => {
|
||||
@@ -124,12 +136,33 @@ describe('WorkflowHistory', () => {
|
||||
|
||||
await userEvent.click(getByTestId('stub-preview-button'));
|
||||
|
||||
await waitFor(() =>
|
||||
await waitFor(() => {
|
||||
expect(router.push).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW_HISTORY,
|
||||
params: { workflowId, versionId },
|
||||
}),
|
||||
);
|
||||
});
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User selected version', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should open preview in new tab if open action is dispatched', async () => {
|
||||
route.params.workflowId = workflowId;
|
||||
const { getByTestId } = renderComponent({ pinia });
|
||||
|
||||
await userEvent.click(getByTestId('stub-open-button'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(router.resolve).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW_HISTORY,
|
||||
params: { workflowId, versionId },
|
||||
});
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User opened version in new tab', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
expect(windowOpenSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should open preview in new tab if meta key used', async () => {
|
||||
@@ -141,12 +174,15 @@ describe('WorkflowHistory', () => {
|
||||
await user.keyboard('[ControlLeft>]');
|
||||
await user.click(getByTestId('stub-preview-button'));
|
||||
|
||||
await waitFor(() =>
|
||||
await waitFor(() => {
|
||||
expect(router.resolve).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW_HISTORY,
|
||||
params: { workflowId, versionId },
|
||||
}),
|
||||
);
|
||||
});
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User opened version in new tab', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
expect(windowOpenSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -160,13 +196,29 @@ describe('WorkflowHistory', () => {
|
||||
const { getByTestId, getByRole } = renderComponent({ pinia });
|
||||
await userEvent.click(getByTestId('stub-clone-button'));
|
||||
|
||||
await waitFor(() =>
|
||||
await waitFor(() => {
|
||||
expect(router.resolve).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW,
|
||||
params: { name: newWorkflowId },
|
||||
}),
|
||||
);
|
||||
});
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User cloned version', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
|
||||
expect(within(getByRole('alert')).getByRole('link')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should download workflow version', async () => {
|
||||
route.params.workflowId = workflowId;
|
||||
|
||||
const { getByTestId } = renderComponent({ pinia });
|
||||
await userEvent.click(getByTestId('stub-download-button'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(telemetry.track).toHaveBeenCalledWith('User downloaded version', {
|
||||
workflow_id: workflowId,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user