diff --git a/src/locales/en/main.json b/src/locales/en/main.json index eb8908140eb..7cf2d1aaef8 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -5058,27 +5058,16 @@ } }, "nudge": { - "title": "Your first output. Here's what's next.", - "body": "Each one starts from the image you just made.", - "animate": { - "title": "Animate it", - "detail": "Image to video · 5s" + "ran": { + "title": "That was one of hundreds", + "body": "You just made your first. Explore what else you can build." }, - "upscale": { - "title": "Upscale it", - "detail": "Same image, more detail", - "badge": "4x" - }, - "restyle": { - "title": "Restyle with Nano Banana", - "detail": "Partner model · Any paid plan" - }, - "fallback": { + "noTour": { "title": "Hundreds more where that came from", "body": "Browse the templates and pick something to build." }, - "loadFailed": "That template couldn't be loaded. Please try again.", - "explore": "Browse all templates" + "dismiss": "Not now", + "explore": "Explore templates" } } } diff --git a/src/platform/telemetry/TelemetryRegistry.ts b/src/platform/telemetry/TelemetryRegistry.ts index b2c2363dd83..209f3649e43 100644 --- a/src/platform/telemetry/TelemetryRegistry.ts +++ b/src/platform/telemetry/TelemetryRegistry.ts @@ -25,8 +25,6 @@ import type { OnboardingTourStage, OnboardingTourStepMetadata, OnboardingTourStepStage, - OnboardingTourSuggestionMetadata, - OnboardingTourSuggestionStage, SearchQueryMetadata, PageViewMetadata, PageVisibilityMetadata, @@ -205,10 +203,6 @@ export class TelemetryRegistry implements TelemetryDispatcher { stage: OnboardingTourNudgeStage, metadata: OnboardingTourNudgeMetadata ): void - trackOnboardingTour( - stage: OnboardingTourSuggestionStage, - metadata: OnboardingTourSuggestionMetadata - ): void trackOnboardingTour( stage: OnboardingTourStage, metadata: OnboardingTourMetadata diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index 1b939396ce6..d9bf95b1cd6 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -121,13 +121,9 @@ export type OnboardingTourNudgeStage = | 'nudge_shown' | 'explore_templates_clicked' -/** A continuation action on the nudge, which reports its own outcome. */ -export type OnboardingTourSuggestionStage = 'nudge_suggestion_clicked' - export type OnboardingTourStage = | OnboardingTourStepStage | OnboardingTourNudgeStage - | OnboardingTourSuggestionStage export type OnboardingTourSkipReason = | 'user' @@ -157,32 +153,21 @@ export interface OnboardingTourStepMetadata { not_started_reason?: OnboardingTourNotStartedReason } -/** The nudge is post-tour, so it reports no step and no step count. */ +/** The nudge is post-tour, so it reports no step and no count. */ export interface OnboardingTourNudgeMetadata { tour: string /** - * How many continuations the card could offer. Zero is the card falling back - * to the template browser — either the run produced no image, or the - * install's pinned template package serves none of them. Without it that - * case is indistinguishable from a nudge that never appeared. + * Whether the tour was walked to the end. Without it `nudge_shown` and + * `explore_templates_clicked` cannot be split by how the tour ended, so a + * conversion from a completed tour and one from a tour that never started + * land in the same bucket. */ - suggestion_count: number -} - -/** - * Which continuation the card converted on. `loaded` separates a chosen action - * from one that reached a template the install could not open, which otherwise - * reads as a successful conversion. - */ -export interface OnboardingTourSuggestionMetadata extends OnboardingTourNudgeMetadata { - suggestion: string - loaded: boolean + tour_completed?: boolean } export type OnboardingTourMetadata = | OnboardingTourStepMetadata | OnboardingTourNudgeMetadata - | OnboardingTourSuggestionMetadata export interface SurveyResponsesNormalized extends SurveyResponses { industry_normalized?: string @@ -964,10 +949,6 @@ export interface TelemetryProvider { stage: OnboardingTourNudgeStage, metadata: OnboardingTourNudgeMetadata ): void - trackOnboardingTour?( - stage: OnboardingTourSuggestionStage, - metadata: OnboardingTourSuggestionMetadata - ): void // Email verification events trackEmailVerification?(stage: 'opened' | 'requested' | 'completed'): void @@ -1119,8 +1100,6 @@ export const TelemetryEvents = { ONBOARDING_TOUR_COMPLETED: 'app:onboarding_tour_completed', ONBOARDING_TOUR_SKIPPED: 'app:onboarding_tour_skipped', ONBOARDING_TOUR_NUDGE_SHOWN: 'app:onboarding_tour_nudge_shown', - ONBOARDING_TOUR_NUDGE_SUGGESTION_CLICKED: - 'app:onboarding_tour_nudge_suggestion_clicked', ONBOARDING_TOUR_EXPLORE_TEMPLATES_CLICKED: 'app:onboarding_tour_explore_templates_clicked', @@ -1204,8 +1183,6 @@ export const OnboardingTourEvents: Record< completed: TelemetryEvents.ONBOARDING_TOUR_COMPLETED, skipped: TelemetryEvents.ONBOARDING_TOUR_SKIPPED, nudge_shown: TelemetryEvents.ONBOARDING_TOUR_NUDGE_SHOWN, - nudge_suggestion_clicked: - TelemetryEvents.ONBOARDING_TOUR_NUDGE_SUGGESTION_CLICKED, explore_templates_clicked: TelemetryEvents.ONBOARDING_TOUR_EXPLORE_TEMPLATES_CLICKED } diff --git a/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts b/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts index 7919912e3fb..b281104f6fc 100644 --- a/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts +++ b/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts @@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { useTemplateWorkflows } from '@/platform/workflow/templates/composables/useTemplateWorkflows' import { useWorkflowTemplatesStore } from '@/platform/workflow/templates/repositories/workflowTemplatesStore' -import { app } from '@/scripts/app' async function flushPromises() { await new Promise((r) => setTimeout(r, 0)) @@ -75,27 +74,6 @@ describe('useTemplateWorkflows', () => { mockWorkflowTemplatesStore = { isLoaded: false, loadWorkflowTemplates: vi.fn().mockResolvedValue(true), - getTemplateByName: vi.fn((name: string) => - name === 'template1' - ? { - name, - mediaType: 'image', - mediaSubtype: 'jpg', - sourceModule: 'default', - description: 'Template 1 description', - io: { - inputs: [ - { - nodeId: 2, - nodeType: 'LoadImage', - file: 'starter.png', - mediaType: 'image' - } - ] - } - } - : undefined - ), groupedTemplates: [ { label: 'ComfyUI Examples', @@ -148,7 +126,6 @@ describe('useTemplateWorkflows', () => { // Mock fetch response vi.mocked(fetch).mockResolvedValue({ - ok: true, json: vi.fn().mockResolvedValue({ workflow: 'data' }) } as Partial as Response) }) @@ -321,48 +298,6 @@ describe('useTemplateWorkflows', () => { expect(fetch).toHaveBeenCalledWith('mock-file-url/templates/template1.json') }) - it('seeds a result into the template before loading the workflow', async () => { - const { loadWorkflowTemplate } = useTemplateWorkflows() - mockWorkflowTemplatesStore.isLoaded = true - vi.mocked(fetch).mockResolvedValueOnce({ - ok: true, - json: vi.fn().mockResolvedValue({ - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['starter.png', 'image'] - } - ] - }) - } as Partial as Response) - - const result = await loadWorkflowTemplate('template1', 'default', { - input: { - filename: 'first-output.png', - subfolder: 'tour', - type: 'output' - } - }) - - expect(result).toBe(true) - expect(app.loadGraphData).toHaveBeenCalledWith( - { - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['tour/first-output.png [output]', 'image'] - } - ] - }, - true, - true, - 'template1', - { openSource: 'template' } - ) - }) - it('tracks template telemetry on load in cloud builds', async () => { const { loadWorkflowTemplate } = useTemplateWorkflows() diff --git a/src/platform/workflow/templates/composables/useTemplateWorkflows.ts b/src/platform/workflow/templates/composables/useTemplateWorkflows.ts index ab72ddcc803..21df601ec13 100644 --- a/src/platform/workflow/templates/composables/useTemplateWorkflows.ts +++ b/src/platform/workflow/templates/composables/useTemplateWorkflows.ts @@ -8,17 +8,10 @@ import type { TemplateInfo, WorkflowTemplates } from '@/platform/workflow/templates/types/template' -import { replaceTemplateImageInput } from '@/platform/workflow/templates/utils/templateWorkflowTransforms' -import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema' -import type { ResultItem } from '@/schemas/apiSchema' import { api } from '@/scripts/api' import { app } from '@/scripts/app' import { useDialogStore } from '@/stores/dialogStore' -interface LoadWorkflowTemplateOptions { - input?: ResultItem -} - export function useTemplateWorkflows() { const { t } = useI18n() const workflowTemplatesStore = useWorkflowTemplatesStore() @@ -104,15 +97,11 @@ export function useTemplateWorkflows() { /** * Loads a workflow template */ - const loadWorkflowTemplate = async ( - id: string, - sourceModule: string, - options: LoadWorkflowTemplateOptions = {} - ) => { + const loadWorkflowTemplate = async (id: string, sourceModule: string) => { if (!isTemplatesLoaded.value) return false loadingTemplateId.value = id - let json: ComfyWorkflowJSON + let json try { // Handle "All" category as a special case @@ -137,12 +126,6 @@ export function useTemplateWorkflows() { // Regular case for normal categories json = await fetchTemplateJson(id, sourceModule) - if (options.input) { - const template = workflowTemplatesStore.getTemplateByName(id) - if (!template || template.sourceModule !== sourceModule) return false - json = replaceTemplateImageInput(json, template, options.input) - } - const workflowName = sourceModule === 'default' ? t(`templateWorkflows.template.${id}`, id) @@ -170,26 +153,15 @@ export function useTemplateWorkflows() { /** * Fetches template JSON from the appropriate endpoint */ - const fetchTemplateJson = async ( - id: string, - sourceModule: string - ): Promise => { - // Default templates provided by frontend are served on this separate endpoint - const url = - sourceModule === 'default' - ? api.fileURL(`/templates/${id}.json`) - : api.apiURL(`/workflow_templates/${sourceModule}/${id}.json`) - - const response = await fetch(url) - // An install pinning an older template package serves an error page here, - // which parses as neither JSON nor a workflow. Separating that from a - // template whose metadata drifted is the difference between a bad pin and - // a bad template. - if (!response.ok) - throw new Error( - `Template ${id} is not served by this install (${response.status})` - ) - return response.json() + const fetchTemplateJson = async (id: string, sourceModule: string) => { + if (sourceModule === 'default') { + // Default templates provided by frontend are served on this separate endpoint + return fetch(api.fileURL(`/templates/${id}.json`)).then((r) => r.json()) + } else { + return fetch( + api.apiURL(`/workflow_templates/${sourceModule}/${id}.json`) + ).then((r) => r.json()) + } } return { diff --git a/src/platform/workflow/templates/types/template.ts b/src/platform/workflow/templates/types/template.ts index 17a87720008..2f78b9d7076 100644 --- a/src/platform/workflow/templates/types/template.ts +++ b/src/platform/workflow/templates/types/template.ts @@ -5,19 +5,6 @@ export interface LogoInfo { position?: string } -/** Served by an external `index.json`, so every field may be absent or stale. */ -export interface TemplateMediaInfo { - nodeId?: string | number - nodeType?: string - file?: string - mediaType?: string -} - -interface TemplateIoInfo { - inputs?: TemplateMediaInfo[] - outputs?: TemplateMediaInfo[] -} - export interface TemplateInfo { name: string /** @@ -80,8 +67,6 @@ export interface TemplateInfo { * Logo overlays to display on the template thumbnail. */ logos?: LogoInfo[] - /** Declared media entry and exit points for continuing from another result. */ - io?: TemplateIoInfo } export enum TemplateIncludeOnDistributionEnum { diff --git a/src/platform/workflow/templates/utils/templateWorkflowTransforms.test.ts b/src/platform/workflow/templates/utils/templateWorkflowTransforms.test.ts deleted file mode 100644 index e3ee4630219..00000000000 --- a/src/platform/workflow/templates/utils/templateWorkflowTransforms.test.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { describe, expect, it } from 'vitest' - -import type { TemplateInfo } from '../types/template' -import { - acceptsTemplateImageInput, - replaceTemplateImageInput -} from './templateWorkflowTransforms' - -const template: TemplateInfo = { - name: 'image-template', - description: 'Image template', - mediaType: 'image', - mediaSubtype: 'png', - io: { - inputs: [ - { - nodeId: 2, - nodeType: 'LoadImage', - file: 'starter.png', - mediaType: 'image' - } - ] - } -} - -describe('template workflow transforms', () => { - it('seeds a declared image input with an output asset', () => { - const workflow = { - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['starter.png', 'image'] - } - ] - } - - const continued = replaceTemplateImageInput(workflow, template, { - filename: 'first-output.png', - subfolder: 'tour', - type: 'output' - }) - - expect(continued.nodes[0].widgets_values).toEqual([ - 'tour/first-output.png [output]', - 'image' - ]) - expect(workflow.nodes[0].widgets_values).toEqual(['starter.png', 'image']) - }) - - it('rejects drift between declared input metadata and workflow widgets', () => { - const workflow = { - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['different.png', 'image'] - } - ] - } - - expect(() => - replaceTemplateImageInput(workflow, template, { - filename: 'first-output.png' - }) - ).toThrow('Expected one matching template widget value') - }) - - it('rejects an output with no filename', () => { - const workflow = { - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['starter.png', 'image'] - } - ] - } - - expect(() => - replaceTemplateImageInput(workflow, template, { type: 'output' }) - ).toThrow('Image output has no filename') - expect(workflow.nodes[0].widgets_values).toEqual(['starter.png', 'image']) - }) - - it.for(['nodeId', 'nodeType', 'file'] as const)( - 'rejects an image input without %s', - (field) => { - const incompleteTemplate = structuredClone(template) - const input = incompleteTemplate.io?.inputs?.[0] - if (!input) throw new Error('Expected template image input') - input[field] = undefined - const workflow = { - nodes: [ - { - id: 2, - type: 'LoadImage', - widgets_values: ['starter.png', 'image'] - } - ] - } - - expect(acceptsTemplateImageInput(incompleteTemplate)).toBe(false) - expect(() => - replaceTemplateImageInput(workflow, incompleteTemplate, { - filename: 'first-output.png' - }) - ).toThrow('Template image input declaration is invalid') - expect(workflow.nodes[0].widgets_values).toEqual(['starter.png', 'image']) - } - ) - - it('reports a template with no declared image input as unusable', () => { - expect(acceptsTemplateImageInput(template)).toBe(true) - expect(acceptsTemplateImageInput({ ...template, io: undefined })).toBe( - false - ) - }) -}) diff --git a/src/platform/workflow/templates/utils/templateWorkflowTransforms.ts b/src/platform/workflow/templates/utils/templateWorkflowTransforms.ts deleted file mode 100644 index 0544858fba7..00000000000 --- a/src/platform/workflow/templates/utils/templateWorkflowTransforms.ts +++ /dev/null @@ -1,137 +0,0 @@ -import type { ResultItem } from '@/schemas/apiSchema' -import { createAnnotatedPath } from '@/utils/createAnnotatedPath' - -import type { TemplateInfo, TemplateMediaInfo } from '../types/template' - -interface TransformableNode { - id: string | number - type: string - widgets_values?: unknown -} - -interface TransformableWorkflow { - nodes: TransformableNode[] -} - -interface NodeSelector { - nodeId: string | number - nodeType: string -} - -/** - * Both serializations of `widgets_values` — the positional array and the - * name-keyed object — replace the one entry holding the template's declared - * file, so they differ only in how the entries are taken apart and put back. - */ -function replaceWidgetValue( - widgetValues: unknown, - currentValue: unknown, - nextValue: unknown -): unknown { - const isArray = Array.isArray(widgetValues) - if (!isArray && (typeof widgetValues !== 'object' || widgetValues === null)) - throw new Error('Template input node has no configurable widgets') - - const entries = Object.entries(widgetValues) - const matches = entries.filter(([, value]) => value === currentValue) - if (matches.length !== 1) - throw new Error('Expected one matching template widget value') - - const [matchedKey] = matches[0] - const replaced = entries.map(([key, value]) => [ - key, - key === matchedKey ? nextValue : value - ]) - return isArray - ? replaced.map(([, value]) => value) - : Object.fromEntries(replaced) -} - -function replaceNodeWidgetValue( - workflow: T, - selector: NodeSelector, - currentValue: unknown, - nextValue: unknown -): T { - // The fetched JSON is unvalidated, so say what is wrong with it rather than - // letting a served error page reach `.filter` as an anonymous TypeError. - if (!Array.isArray(workflow.nodes)) - throw new Error('Template workflow has no nodes') - - const matchingNodes = workflow.nodes.filter( - (node) => - node.type === selector.nodeType && - String(node.id) === String(selector.nodeId) - ) - if (matchingNodes.length !== 1) - throw new Error('Expected one matching template node') - - const target = matchingNodes[0] - return { - ...workflow, - nodes: workflow.nodes.map((node) => - node === target - ? { - ...node, - widgets_values: replaceWidgetValue( - node.widgets_values, - currentValue, - nextValue - ) - } - : node - ) - } -} - -interface SeedableMediaInput extends NodeSelector { - file: string -} - -function findImageInput(template: TemplateInfo) { - return template.io?.inputs?.find(({ mediaType }) => mediaType === 'image') -} - -function isSeedable(input: TemplateMediaInfo): input is SeedableMediaInput { - const { nodeId, nodeType, file } = input - const hasNodeId = - typeof nodeId === 'number' ? Number.isFinite(nodeId) : Boolean(nodeId) - return hasNodeId && Boolean(nodeType) && Boolean(file) -} - -/** - * Whether `replaceTemplateImageInput` has enough metadata to seed this - * template, so a caller can hide an action rather than fail it on click. - */ -export function acceptsTemplateImageInput(template: TemplateInfo): boolean { - const input = findImageInput(template) - return input !== undefined && isSeedable(input) -} - -/** - * Continues `image` into `template` by rewriting the widget value its declared - * image input currently holds. - * - * The declared node has to live in `workflow.nodes`: a node nested inside - * `definitions.subgraphs` is not reachable from `io.inputs`, and a template - * that declares one throws here rather than loading unseeded. - */ -export function replaceTemplateImageInput( - workflow: T, - template: TemplateInfo, - image: ResultItem -): T { - if (!image.filename) throw new Error('Image output has no filename') - - const input = findImageInput(template) - if (!input) throw new Error('Template has no declared image input') - if (!isSeedable(input)) - throw new Error('Template image input declaration is invalid') - - return replaceNodeWidgetValue( - workflow, - { nodeId: input.nodeId, nodeType: input.nodeType }, - input.file, - createAnnotatedPath({ ...image, type: image.type ?? 'output' }) - ) -} diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index b546fd6c47b..8918b0b6f76 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -1,7 +1,6 @@ import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' -import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' import enMessages from '@/locales/en/main.json' with { type: 'json' } @@ -9,106 +8,29 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' } import FirstRunTourNudge from './FirstRunTourNudge.vue' const APPEAR_DELAY_MS = 1500 -const CATALOG_WAIT_MS = 3000 -const FIRST_OUTPUT = { - filename: 'first-output.png', - subfolder: 'tour', - type: 'output' as const -} -type SuggestionId = 'animate' | 'upscale' | 'restyle' - -const SUGGESTION_TITLES: Record = { - animate: enMessages.onboardingCoachmarks.firstRun.nudge.animate.title, - upscale: enMessages.onboardingCoachmarks.firstRun.nudge.upscale.title, - restyle: enMessages.onboardingCoachmarks.firstRun.nudge.restyle.title -} - -type Deferred = { - promise: Promise - resolve: (value: T) => void -} - -function createDeferred(): Deferred { - let resolve!: (value: T) => void - const promise = new Promise((resolveFn) => { - resolve = resolveFn - }) - return { promise, resolve } -} - -const CATALOG_TEMPLATE_IDS = [ - 'video_minimax_h3_i2v_continuation', - 'utility_seedvr2_7b_int8_upscale_image', - 'api_google_nano_banana2_image_edit_continuation' -] - -/** Stands in for what the install's template package actually serves. */ -function catalogEntry(name: string, withIo: boolean) { - return { - name, - sourceModule: 'default', - io: withIo - ? { - inputs: [ - { - nodeId: 1, - nodeType: 'LoadImage', - file: 'starter.png', - mediaType: 'image' - } - ] - } - : undefined - } -} const mocks = await vi.hoisted(async () => { - const { ref, shallowRef } = await import('vue') + const { ref } = await import('vue') return { nudgeArmed: ref(false), - nudgeOutput: shallowRef<{ - filename: string - subfolder: string - type: 'output' - } | null>({ - filename: 'first-output.png', - subfolder: 'tour', - type: 'output' - }), + tourWasCompleted: ref(true), openDialogs: ref([]), - catalog: ref([]), - catalogHasIo: ref(true), dismissNudge: vi.fn(() => { mocks.nudgeArmed.value = false }), showTemplates: vi.fn(), - trackOnboardingTour: vi.fn(), - loadTemplates: vi.fn().mockResolvedValue(true), - loadWorkflowTemplate: vi.fn().mockResolvedValue(true), - addToast: vi.fn() + trackOnboardingTour: vi.fn() } }) vi.mock('../tour/useFirstRunTourController', () => ({ useFirstRunTourController: () => ({ nudgeArmed: mocks.nudgeArmed, - nudgeOutput: mocks.nudgeOutput, + tourWasCompleted: mocks.tourWasCompleted, dismissNudge: mocks.dismissNudge }) })) -vi.mock( - '@/platform/workflow/templates/repositories/workflowTemplatesStore', - () => ({ - useWorkflowTemplatesStore: () => ({ - getTemplateByName: (name: string) => - mocks.catalog.value.includes(name) - ? catalogEntry(name, mocks.catalogHasIo.value) - : undefined - }) - }) -) - vi.mock('@/stores/dialogStore', () => ({ useDialogStore: () => ({ get dialogStack() { @@ -121,20 +43,6 @@ vi.mock('@/composables/useWorkflowTemplateSelectorDialog', () => ({ useWorkflowTemplateSelectorDialog: () => ({ show: mocks.showTemplates }) })) -vi.mock( - '@/platform/workflow/templates/composables/useTemplateWorkflows', - () => ({ - useTemplateWorkflows: () => ({ - loadTemplates: mocks.loadTemplates, - loadWorkflowTemplate: mocks.loadWorkflowTemplate - }) - }) -) - -vi.mock('primevue/usetoast', () => ({ - useToast: () => ({ add: mocks.addToast }) -})) - vi.mock('@/platform/telemetry', () => ({ useTelemetry: () => ({ trackOnboardingTour: mocks.trackOnboardingTour }) })) @@ -149,354 +57,196 @@ function renderNudge() { return render(FirstRunTourNudge, { global: { plugins: [i18n] } }) } +const nudgeCopy = enMessages.onboardingCoachmarks.firstRun.nudge + function nudge() { return screen.queryByTestId('first-run-nudge') } -function suggestionButton(id: SuggestionId) { - return screen.getByRole('button', { - name: new RegExp(SUGGESTION_TITLES[id], 'i') - }) -} - -async function showNudge() { - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) -} - describe('FirstRunTourNudge', () => { beforeEach(() => { mocks.nudgeArmed.value = false - mocks.nudgeOutput.value = FIRST_OUTPUT + mocks.tourWasCompleted.value = true mocks.openDialogs.value = [] - mocks.catalog.value = CATALOG_TEMPLATE_IDS - mocks.catalogHasIo.value = true - mocks.loadTemplates.mockResolvedValue(true) - mocks.loadWorkflowTemplate.mockResolvedValue(true) }) - it('appears after the result has had time to land', async () => { + it('shows a nudge that came due before it mounted', async () => { mocks.nudgeArmed.value = true renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS - 1) - expect(nudge()).toBeNull() + expect( + nudge(), + 'arriving on top of the result the user just made buries it' + ).toBeNull() await vi.advanceTimersByTimeAsync(1) expect( - screen.getByText(enMessages.onboardingCoachmarks.firstRun.nudge.title) - ).toBeTruthy() + nudge(), + 'a nudge armed before this mounted still has to appear' + ).not.toBeNull() expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { tour: 'firstRun', - suggestion_count: 3 + tour_completed: true }) }) - it('waits until the modal stack is clear', async () => { + it('waits out a dialog that is already open', async () => { mocks.nudgeArmed.value = true mocks.openDialogs.value = ['some-dialog'] renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect(nudge()).toBeNull() + expect( + nudge(), + 'the nudge sits below the modal stack, so under a dialog it is invisible' + ).toBeNull() mocks.openDialogs.value = [] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect(nudge()).not.toBeNull() - }) - - it('closes from the full close control and Escape', async () => { - const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - await showNudge() - - await user.click(screen.getByRole('button', { name: enMessages.g.close })) - expect(mocks.dismissNudge).toHaveBeenCalled() - - mocks.nudgeArmed.value = true - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - await user.keyboard('{Escape}') - expect(mocks.dismissNudge).toHaveBeenCalledTimes(2) - }) - - it.for([ - { - id: 'animate', - templateId: 'video_minimax_h3_i2v_continuation' - }, - { - id: 'upscale', - templateId: 'utility_seedvr2_7b_int8_upscale_image' - }, - { - id: 'restyle', - templateId: 'api_google_nano_banana2_image_edit_continuation' - } - ] as const)( - 'continues the first output through $id', - async ({ id, templateId }) => { - const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - await showNudge() - - await user.click(suggestionButton(id)) - - expect(mocks.loadWorkflowTemplate).toHaveBeenCalledWith( - templateId, - 'default', - { input: FIRST_OUTPUT } - ) - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( - 'nudge_suggestion_clicked', - { - tour: 'firstRun', - suggestion_count: 3, - suggestion: id, - loaded: true - } - ) - expect(mocks.dismissNudge).toHaveBeenCalled() - } - ) - - it('waits for the catalog rather than rewriting itself under the user', async () => { - const catalogLoaded = createDeferred() - mocks.catalog.value = [] - mocks.loadTemplates.mockReturnValueOnce(catalogLoaded.promise) - mocks.nudgeArmed.value = true - renderNudge() - - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) expect( nudge(), - 'the fallback copy would be shown, then rewritten into the continuations' - ).toBeNull() - - mocks.catalog.value = CATALOG_TEMPLATE_IDS - catalogLoaded.resolve(true) - await vi.waitFor(() => { - expect(nudge()).not.toBeNull() - }) - - expect(suggestionButton('animate')).toBeTruthy() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - suggestion_count: 3 - }) + 'the dialog was already open at mount, so no open-to-closed edge ever fired' + ).not.toBeNull() }) - it('freezes the fallback when the catalog resolves after the deadline', async () => { - const catalogLoaded = createDeferred() - mocks.catalog.value = [] - mocks.loadTemplates.mockReturnValueOnce(catalogLoaded.promise) + it('waits out a dialog that opens while it is still on its way', async () => { mocks.nudgeArmed.value = true renderNudge() - await vi.advanceTimersByTimeAsync(CATALOG_WAIT_MS) - - expect( - screen.getByText( - enMessages.onboardingCoachmarks.firstRun.nudge.fallback.title - ), - 'the way forward is what the card is for (#14144)' - ).toBeTruthy() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - suggestion_count: 0 - }) - - mocks.catalog.value = CATALOG_TEMPLATE_IDS - catalogLoaded.resolve(true) - await catalogLoaded.promise - await nextTick() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS - 500) + mocks.openDialogs.value = ['some-dialog'] + await vi.advanceTimersByTimeAsync(500 + APPEAR_DELAY_MS) expect( - screen.queryByRole('button', { - name: new RegExp(SUGGESTION_TITLES.animate, 'i') - }), - 'the catalog deadline already decided what the card showed and reported' + nudge(), + 'a nudge that came due behind a dialog would land on top of the modal' ).toBeNull() expect( - screen.getByText( - enMessages.onboardingCoachmarks.firstRun.nudge.fallback.title - ) - ).toBeTruthy() - expect(mocks.trackOnboardingTour).toHaveBeenCalledTimes(1) + mocks.trackOnboardingTour, + 'a nudge nobody can see has not been shown' + ).not.toHaveBeenCalledWith('nudge_shown', expect.anything()) }) - it('reports one nudge per tour, however often it comes and goes', async () => { - await showNudge() + it('reports one nudge once, however often it comes and goes', async () => { + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) mocks.openDialogs.value = ['some-dialog'] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) mocks.openDialogs.value = [] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - const shown = () => - mocks.trackOnboardingTour.mock.calls.filter( - ([stage]) => stage === 'nudge_shown' - ) + const shown = mocks.trackOnboardingTour.mock.calls.filter( + ([stage]) => stage === 'nudge_shown' + ) expect( - shown(), + shown, 'the funnel counts nudges, so a reappearance is not a second one' ).toHaveLength(1) + }) - mocks.nudgeArmed.value = false - await nextTick() + it('congratulates a tour the user walked to the end', async () => { + mocks.tourWasCompleted.value = true mocks.nudgeArmed.value = true + renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect( - shown(), - 'a second tour ends in a second nudge, which the funnel has to see' - ).toHaveLength(2) + expect(screen.getByText(nudgeCopy.ran.title)).toBeTruthy() }) - it('offers only the continuations the install actually serves', async () => { - mocks.catalog.value = ['utility_seedvr2_7b_int8_upscale_image'] - await showNudge() + it('offers no congratulation for a tour nobody finished', async () => { + mocks.tourWasCompleted.value = false + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect(suggestionButton('upscale')).toBeTruthy() expect( - screen.queryByRole('button', { - name: new RegExp(SUGGESTION_TITLES.animate, 'i') - }), - 'this build knows the id, but the pinned template package does not serve it' + screen.queryByText(nudgeCopy.ran.title), + 'a user who skipped, was cut off or saw no tour made no first result' ).toBeNull() + expect(screen.getByText(nudgeCopy.noTour.title)).toBeTruthy() }) - it.for([ - { named: 'serves none of them', catalog: [] as string[] }, - { - named: 'serves them without the metadata to seed them', - catalog: CATALOG_TEMPLATE_IDS, - stripIo: true - } - ])( - 'falls back to the template browser when the install $named', - async ({ catalog, stripIo }) => { - mocks.catalog.value = catalog - mocks.catalogHasIo.value = !stripIo - await showNudge() + it.for([{ finished: true }, { finished: false }])( + 'appears whether or not the tour finished ($finished)', + async ({ finished }) => { + mocks.tourWasCompleted.value = finished + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) expect( - screen.queryByRole('button', { - name: new RegExp(SUGGESTION_TITLES.animate, 'i') - }), - 'every action would be a dead end found by clicking it' - ).toBeNull() - expect( - screen.getByText( - enMessages.onboardingCoachmarks.firstRun.nudge.fallback.title - ), - 'the way forward is what the card is for (#14144)' - ).toBeTruthy() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - suggestion_count: 0 - }) + nudge(), + 'the copy is all that the ending changes; the way forward is offered either way' + ).not.toBeNull() } ) - it('falls back to the template browser when the run made no image', async () => { - mocks.nudgeOutput.value = null - await showNudge() - - expect( - screen.getByText( - enMessages.onboardingCoachmarks.firstRun.nudge.fallback.title - ) - ).toBeTruthy() - expect( - screen.queryByRole('button', { - name: new RegExp(SUGGESTION_TITLES.animate, 'i') - }), - 'there is nothing to seed a continuation with' - ).toBeNull() - }) - - it('keeps the card while a continuation is loading', async () => { + it('stays gone once the user closes it', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.loadWorkflowTemplate.mockReturnValueOnce( - createDeferred().promise - ) - await showNudge() + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - await user.click(suggestionButton('animate')) - await user.keyboard('{Escape}') + await user.click(screen.getByRole('button', { name: enMessages.g.close })) - expect( - mocks.dismissNudge, - 'the graph is about to be replaced, so there is nothing to dismiss out of' - ).not.toHaveBeenCalled() - expect( - screen.getByRole('button', { name: enMessages.g.close }) - ).toBeDisabled() + expect(mocks.dismissNudge).toHaveBeenCalled() + expect(nudge()).toBeNull() }) - it('exposes the pending continuation and blocks competing actions', async () => { + it('stays gone once the user waves it away', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - const workflowLoaded = createDeferred() - mocks.loadWorkflowTemplate.mockReturnValueOnce(workflowLoaded.promise) - await showNudge() + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - const animate = suggestionButton('animate') - await user.click(animate) + await user.click(screen.getByText(nudgeCopy.dismiss)) - expect(animate).toHaveAttribute('aria-busy', 'true') - expect(animate).toBeDisabled() - expect(suggestionButton('upscale')).toBeDisabled() - expect(suggestionButton('restyle')).toBeDisabled() - expect( - screen.getByRole('button', { - name: enMessages.onboardingCoachmarks.firstRun.nudge.explore - }) - ).toBeDisabled() - - workflowLoaded.resolve(true) - await vi.waitFor(() => { - expect(mocks.dismissNudge).toHaveBeenCalled() - }) + expect(nudge()).toBeNull() }) - it('keeps the card open and reports a template load failure', async () => { + it('takes the user to the templates it is pointing at', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.loadWorkflowTemplate.mockResolvedValue(false) - await showNudge() + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - await user.click(suggestionButton('animate')) + await user.click(screen.getByTestId('first-run-nudge-explore')) - expect(mocks.dismissNudge).not.toHaveBeenCalled() - expect(mocks.addToast).toHaveBeenCalledWith( - expect.objectContaining({ severity: 'error' }) - ) + expect( + mocks.showTemplates, + 'the source is what separates a nudge conversion from a command-palette one, and it defaults to command' + ).toHaveBeenCalledWith('first_run_nudge') + expect(mocks.dismissNudge).toHaveBeenCalled() expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( - 'nudge_suggestion_clicked', - { - tour: 'firstRun', - suggestion_count: 3, - suggestion: 'animate', - loaded: false - } + 'explore_templates_clicked', + { tour: 'firstRun', tour_completed: true } ) }) - it('opens the existing template browser from the footer', async () => { + it('separates a conversion from a completed tour from one that never ran', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - await showNudge() + mocks.tourWasCompleted.value = false + mocks.nudgeArmed.value = true + renderNudge() + await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - await user.click( - screen.getByRole('button', { - name: enMessages.onboardingCoachmarks.firstRun.nudge.explore - }) - ) + await user.click(screen.getByTestId('first-run-nudge-explore')) - expect(mocks.showTemplates).toHaveBeenCalledWith('first_run_nudge') + // Both events carry it, so the funnel can be read end to end: without it + // a conversion from a finished tour and one from a tour that never + // started are indistinguishable. + expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { + tour: 'firstRun', + tour_completed: false + }) expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', - { tour: 'firstRun', suggestion_count: 3 } + { tour: 'firstRun', tour_completed: false } ) - expect(mocks.dismissNudge).toHaveBeenCalled() }) }) diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue index a4f9d2e2eb5..e4cfd927a47 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue @@ -3,325 +3,125 @@ v-if="onScreen" role="region" :aria-labelledby="titleId" - :aria-describedby="subtitleId" data-testid="first-run-nudge" - class="fixed right-6 bottom-8 z-1000 flex w-103.25 animate-in flex-col gap-4 overflow-hidden rounded-xl border border-border-subtle bg-base-background p-5 shadow-lg duration-500 fade-in-0" + class="fixed right-0 bottom-0 z-1000 flex w-80 animate-in flex-col overflow-hidden rounded-tl-xl border-t border-l border-border-default/50 bg-base-background shadow-lg duration-500 fade-in-0" > -
-
-
-

- {{ t(`${copyKey}.title`) }} -

-

- {{ t(`${copyKey}.body`) }} -

-
-