diff --git a/src/locales/en/main.json b/src/locales/en/main.json index e08d550640c..1802029cc12 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -5056,16 +5056,27 @@ } }, "nudge": { - "ran": { - "title": "That was one of hundreds", - "body": "You just made your first. Explore what else you can build." + "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" }, - "noTour": { + "upscale": { + "title": "Upscale it", + "detail": "Same image, more detail", + "badge": "4x" + }, + "restyle": { + "title": "Restyle with Nano Banana", + "detail": "Partner model · Any paid plan" + }, + "fallback": { "title": "Hundreds more where that came from", "body": "Browse the templates and pick something to build." }, - "dismiss": "Not now", - "explore": "Explore templates" + "loadFailed": "That template couldn't be loaded. Please try again.", + "explore": "Browse all templates" } } } diff --git a/src/platform/telemetry/TelemetryRegistry.ts b/src/platform/telemetry/TelemetryRegistry.ts index 209f3649e43..b2c2363dd83 100644 --- a/src/platform/telemetry/TelemetryRegistry.ts +++ b/src/platform/telemetry/TelemetryRegistry.ts @@ -25,6 +25,8 @@ import type { OnboardingTourStage, OnboardingTourStepMetadata, OnboardingTourStepStage, + OnboardingTourSuggestionMetadata, + OnboardingTourSuggestionStage, SearchQueryMetadata, PageViewMetadata, PageVisibilityMetadata, @@ -203,6 +205,10 @@ 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 d9bf95b1cd6..1b939396ce6 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -121,9 +121,13 @@ 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' @@ -153,21 +157,32 @@ export interface OnboardingTourStepMetadata { not_started_reason?: OnboardingTourNotStartedReason } -/** The nudge is post-tour, so it reports no step and no count. */ +/** The nudge is post-tour, so it reports no step and no step count. */ export interface OnboardingTourNudgeMetadata { tour: string /** - * 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. + * 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. */ - tour_completed?: boolean + 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 } export type OnboardingTourMetadata = | OnboardingTourStepMetadata | OnboardingTourNudgeMetadata + | OnboardingTourSuggestionMetadata export interface SurveyResponsesNormalized extends SurveyResponses { industry_normalized?: string @@ -949,6 +964,10 @@ export interface TelemetryProvider { stage: OnboardingTourNudgeStage, metadata: OnboardingTourNudgeMetadata ): void + trackOnboardingTour?( + stage: OnboardingTourSuggestionStage, + metadata: OnboardingTourSuggestionMetadata + ): void // Email verification events trackEmailVerification?(stage: 'opened' | 'requested' | 'completed'): void @@ -1100,6 +1119,8 @@ 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', @@ -1183,6 +1204,8 @@ 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 b281104f6fc..7919912e3fb 100644 --- a/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts +++ b/src/platform/workflow/templates/composables/useTemplateWorkflows.test.ts @@ -2,6 +2,7 @@ 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)) @@ -74,6 +75,27 @@ 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', @@ -126,6 +148,7 @@ describe('useTemplateWorkflows', () => { // Mock fetch response vi.mocked(fetch).mockResolvedValue({ + ok: true, json: vi.fn().mockResolvedValue({ workflow: 'data' }) } as Partial as Response) }) @@ -298,6 +321,48 @@ 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 21df601ec13..ab72ddcc803 100644 --- a/src/platform/workflow/templates/composables/useTemplateWorkflows.ts +++ b/src/platform/workflow/templates/composables/useTemplateWorkflows.ts @@ -8,10 +8,17 @@ 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() @@ -97,11 +104,15 @@ export function useTemplateWorkflows() { /** * Loads a workflow template */ - const loadWorkflowTemplate = async (id: string, sourceModule: string) => { + const loadWorkflowTemplate = async ( + id: string, + sourceModule: string, + options: LoadWorkflowTemplateOptions = {} + ) => { if (!isTemplatesLoaded.value) return false loadingTemplateId.value = id - let json + let json: ComfyWorkflowJSON try { // Handle "All" category as a special case @@ -126,6 +137,12 @@ 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) @@ -153,15 +170,26 @@ export function useTemplateWorkflows() { /** * Fetches template JSON from the appropriate endpoint */ - 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()) - } + 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() } return { diff --git a/src/platform/workflow/templates/types/template.ts b/src/platform/workflow/templates/types/template.ts index 2f78b9d7076..17a87720008 100644 --- a/src/platform/workflow/templates/types/template.ts +++ b/src/platform/workflow/templates/types/template.ts @@ -5,6 +5,19 @@ 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 /** @@ -67,6 +80,8 @@ 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 new file mode 100644 index 00000000000..e3ee4630219 --- /dev/null +++ b/src/platform/workflow/templates/utils/templateWorkflowTransforms.test.ts @@ -0,0 +1,119 @@ +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 new file mode 100644 index 00000000000..0544858fba7 --- /dev/null +++ b/src/platform/workflow/templates/utils/templateWorkflowTransforms.ts @@ -0,0 +1,137 @@ +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 8918b0b6f76..b546fd6c47b 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -1,6 +1,7 @@ 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' } @@ -8,29 +9,106 @@ 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 } = await import('vue') + const { ref, shallowRef } = await import('vue') return { nudgeArmed: ref(false), - tourWasCompleted: ref(true), + nudgeOutput: shallowRef<{ + filename: string + subfolder: string + type: 'output' + } | null>({ + filename: 'first-output.png', + subfolder: 'tour', + type: 'output' + }), openDialogs: ref([]), + catalog: ref([]), + catalogHasIo: ref(true), dismissNudge: vi.fn(() => { mocks.nudgeArmed.value = false }), showTemplates: vi.fn(), - trackOnboardingTour: vi.fn() + trackOnboardingTour: vi.fn(), + loadTemplates: vi.fn().mockResolvedValue(true), + loadWorkflowTemplate: vi.fn().mockResolvedValue(true), + addToast: vi.fn() } }) vi.mock('../tour/useFirstRunTourController', () => ({ useFirstRunTourController: () => ({ nudgeArmed: mocks.nudgeArmed, - tourWasCompleted: mocks.tourWasCompleted, + nudgeOutput: mocks.nudgeOutput, 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() { @@ -43,6 +121,20 @@ 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 }) })) @@ -57,196 +149,354 @@ 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.tourWasCompleted.value = true + mocks.nudgeOutput.value = FIRST_OUTPUT mocks.openDialogs.value = [] + mocks.catalog.value = CATALOG_TEMPLATE_IDS + mocks.catalogHasIo.value = true + mocks.loadTemplates.mockResolvedValue(true) + mocks.loadWorkflowTemplate.mockResolvedValue(true) }) - it('shows a nudge that came due before it mounted', async () => { + it('appears after the result has had time to land', async () => { mocks.nudgeArmed.value = true renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS - 1) - expect( - nudge(), - 'arriving on top of the result the user just made buries it' - ).toBeNull() + expect(nudge()).toBeNull() await vi.advanceTimersByTimeAsync(1) expect( - nudge(), - 'a nudge armed before this mounted still has to appear' - ).not.toBeNull() + screen.getByText(enMessages.onboardingCoachmarks.firstRun.nudge.title) + ).toBeTruthy() expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { tour: 'firstRun', - tour_completed: true + suggestion_count: 3 }) }) - it('waits out a dialog that is already open', async () => { + it('waits until the modal stack is clear', async () => { mocks.nudgeArmed.value = true mocks.openDialogs.value = ['some-dialog'] renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect( - nudge(), - 'the nudge sits below the modal stack, so under a dialog it is invisible' - ).toBeNull() + expect(nudge()).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 dialog was already open at mount, so no open-to-closed edge ever fired' - ).not.toBeNull() + '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 + }) }) - it('waits out a dialog that opens while it is still on its way', async () => { + it('freezes the fallback when the catalog resolves after the deadline', async () => { + const catalogLoaded = createDeferred() + mocks.catalog.value = [] + mocks.loadTemplates.mockReturnValueOnce(catalogLoaded.promise) mocks.nudgeArmed.value = true renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS - 500) - mocks.openDialogs.value = ['some-dialog'] - await vi.advanceTimersByTimeAsync(500 + APPEAR_DELAY_MS) + await vi.advanceTimersByTimeAsync(CATALOG_WAIT_MS) expect( - nudge(), - 'a nudge that came due behind a dialog would land on top of the modal' + 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() + + expect( + screen.queryByRole('button', { + name: new RegExp(SUGGESTION_TITLES.animate, 'i') + }), + 'the catalog deadline already decided what the card showed and reported' ).toBeNull() expect( - mocks.trackOnboardingTour, - 'a nudge nobody can see has not been shown' - ).not.toHaveBeenCalledWith('nudge_shown', expect.anything()) + screen.getByText( + enMessages.onboardingCoachmarks.firstRun.nudge.fallback.title + ) + ).toBeTruthy() + expect(mocks.trackOnboardingTour).toHaveBeenCalledTimes(1) }) - it('reports one nudge once, however often it comes and goes', async () => { - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) + it('reports one nudge per tour, however often it comes and goes', async () => { + await showNudge() 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) - }) - it('congratulates a tour the user walked to the end', async () => { - mocks.tourWasCompleted.value = true + mocks.nudgeArmed.value = false + await nextTick() mocks.nudgeArmed.value = true - renderNudge() await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - expect(screen.getByText(nudgeCopy.ran.title)).toBeTruthy() + expect( + shown(), + 'a second tour ends in a second nudge, which the funnel has to see' + ).toHaveLength(2) }) - 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) + it('offers only the continuations the install actually serves', async () => { + mocks.catalog.value = ['utility_seedvr2_7b_int8_upscale_image'] + await showNudge() + expect(suggestionButton('upscale')).toBeTruthy() expect( - screen.queryByText(nudgeCopy.ran.title), - 'a user who skipped, was cut off or saw no tour made no first result' + screen.queryByRole('button', { + name: new RegExp(SUGGESTION_TITLES.animate, 'i') + }), + 'this build knows the id, but the pinned template package does not serve it' ).toBeNull() - expect(screen.getByText(nudgeCopy.noTour.title)).toBeTruthy() }) - 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) + 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() expect( - nudge(), - 'the copy is all that the ending changes; the way forward is offered either way' - ).not.toBeNull() + 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 + }) } ) - it('stays gone once the user closes it', async () => { + 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 () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) + mocks.loadWorkflowTemplate.mockReturnValueOnce( + createDeferred().promise + ) + await showNudge() - await user.click(screen.getByRole('button', { name: enMessages.g.close })) + await user.click(suggestionButton('animate')) + await user.keyboard('{Escape}') - expect(mocks.dismissNudge).toHaveBeenCalled() - expect(nudge()).toBeNull() + 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() }) - it('stays gone once the user waves it away', async () => { + it('exposes the pending continuation and blocks competing actions', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) + const workflowLoaded = createDeferred() + mocks.loadWorkflowTemplate.mockReturnValueOnce(workflowLoaded.promise) + await showNudge() - await user.click(screen.getByText(nudgeCopy.dismiss)) + const animate = suggestionButton('animate') + await user.click(animate) - expect(nudge()).toBeNull() + 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() + }) }) - it('takes the user to the templates it is pointing at', async () => { + it('keeps the card open and reports a template load failure', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) + mocks.loadWorkflowTemplate.mockResolvedValue(false) + await showNudge() - await user.click(screen.getByTestId('first-run-nudge-explore')) + await user.click(suggestionButton('animate')) - 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.dismissNudge).not.toHaveBeenCalled() + expect(mocks.addToast).toHaveBeenCalledWith( + expect.objectContaining({ severity: 'error' }) + ) expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( - 'explore_templates_clicked', - { tour: 'firstRun', tour_completed: true } + 'nudge_suggestion_clicked', + { + tour: 'firstRun', + suggestion_count: 3, + suggestion: 'animate', + loaded: false + } ) }) - it('separates a conversion from a completed tour from one that never ran', async () => { + it('opens the existing template browser from the footer', async () => { const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) - mocks.tourWasCompleted.value = false - mocks.nudgeArmed.value = true - renderNudge() - await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) + await showNudge() - await user.click(screen.getByTestId('first-run-nudge-explore')) + await user.click( + screen.getByRole('button', { + name: enMessages.onboardingCoachmarks.firstRun.nudge.explore + }) + ) - // 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.showTemplates).toHaveBeenCalledWith('first_run_nudge') expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', - { tour: 'firstRun', tour_completed: false } + { tour: 'firstRun', suggestion_count: 3 } ) + expect(mocks.dismissNudge).toHaveBeenCalled() }) }) diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue index e4cfd927a47..a4f9d2e2eb5 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.vue @@ -3,125 +3,325 @@ v-if="onScreen" role="region" :aria-labelledby="titleId" + :aria-describedby="subtitleId" data-testid="first-run-nudge" - 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" + 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" > -
- -