diff --git a/locales/en.json b/locales/en.json index eb46da807..426e1c8f3 100644 --- a/locales/en.json +++ b/locales/en.json @@ -38,6 +38,9 @@ "seeAllWorkflows": "See all workflows", "showWorkflow": "Show {title}", "openWorkflow": "Open {title} on Comfy Hub", + "openWorkflowCta": "Open", + "previousWorkflow": "Previous workflow", + "nextWorkflow": "Next workflow", "workflowsUnavailable": "Example workflows couldn't be loaded. Check your connection and try again.", "retry": "Try again" }, diff --git a/locales/zh.json b/locales/zh.json index f17ba0975..78540d9a3 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -38,6 +38,9 @@ "seeAllWorkflows": "查看全部工作流", "showWorkflow": "显示 {title}", "openWorkflow": "在 Comfy Hub 打开 {title}", + "openWorkflowCta": "打开", + "previousWorkflow": "上一个工作流", + "nextWorkflow": "下一个工作流", "workflowsUnavailable": "无法加载示例工作流。请检查网络连接后重试。", "retry": "重试" }, diff --git a/src/renderer/src/panel/HomeView.test.ts b/src/renderer/src/panel/HomeView.test.ts index 53e282f90..887e03039 100644 --- a/src/renderer/src/panel/HomeView.test.ts +++ b/src/renderer/src/panel/HomeView.test.ts @@ -88,7 +88,10 @@ async function openHome() { function arc(wrapper: VueWrapper): string[] { return wrapper .findAll('[data-testid="home-workflow-card"]:not([aria-hidden="true"])') - .map((card) => ({ offset: Number(card.attributes('data-arc-offset')), text: card.text() })) + .map((card) => ({ + offset: Number(card.attributes('data-arc-offset')), + text: card.get('[data-testid="home-workflow-name"]').text() + })) .sort((left, right) => left.offset - right.offset) .map((card) => `${card.offset}:${card.text}`) } @@ -201,6 +204,91 @@ describe('Home example workflows', () => { expect(cardAt(wrapper, 0).text()).toContain('Workflow 1') }) + it('turns the carousel with the previous and next arrows', async () => { + listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS) + const wrapper = await openHome() + const next = wrapper.get('[data-testid="home-workflow-next"]') + const previous = wrapper.get('[data-testid="home-workflow-previous"]') + + expect(next.attributes('aria-label')).toBe('Next workflow') + expect(previous.attributes('aria-label')).toBe('Previous workflow') + + await next.trigger('click') + await next.trigger('click') + expect(cardAt(wrapper, 0).text()).toContain('Workflow 2') + + await previous.trigger('click') + await previous.trigger('click') + await previous.trigger('click') + expect(cardAt(wrapper, 0).text()).toContain('Workflow 6') + expect(openCatalogWorkflow).not.toHaveBeenCalled() + }) + + it('stops the arrows at the ends of a short list and leaves them out for a single card', async () => { + listHomeWorkflows.mockResolvedValue([UPSCALE, TALK]) + const wrapper = await openHome() + const next = wrapper.get('[data-testid="home-workflow-next"]') + const previous = wrapper.get('[data-testid="home-workflow-previous"]') + + expect(previous.attributes('disabled')).toBeDefined() + expect(next.attributes('disabled')).toBeUndefined() + + await next.trigger('click') + expect(cardAt(wrapper, 0).text()).toContain('Make your character talk') + expect(next.attributes('disabled')).toBeDefined() + expect(previous.attributes('disabled')).toBeUndefined() + + listHomeWorkflows.mockResolvedValue([UPSCALE]) + const single = await openHome() + expect(single.find('[data-testid="home-workflow-next"]').exists()).toBe(false) + expect(single.find('[data-testid="home-workflow-previous"]').exists()).toBe(false) + }) + + it('keeps keyboard focus on an arrow when the one in use reaches the end of a short list', async () => { + listHomeWorkflows.mockResolvedValue([UPSCALE, TALK]) + const wrapper = await openHome() + const next = wrapper.get('[data-testid="home-workflow-next"]') + const previous = wrapper.get('[data-testid="home-workflow-previous"]') + + next.element.focus() + await next.trigger('click') + await flushPromises() + + expect(next.element.disabled).toBe(true) + expect(document.activeElement).toBe(previous.element) + }) + + it('turns with the arrow keys from an arrow button and moves card focus to the new front card', async () => { + listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS) + const wrapper = await openHome() + + const next = wrapper.get('[data-testid="home-workflow-next"]') + await next.trigger('keydown', { key: 'ArrowRight' }) + expect(cardAt(wrapper, 0).text()).toContain('Workflow 1') + + const front = cardAt(wrapper, 0).element as HTMLButtonElement + front.focus() + await cardAt(wrapper, 0).trigger('keydown', { key: 'ArrowRight' }) + await flushPromises() + + expect(cardAt(wrapper, 0).text()).toContain('Workflow 2') + expect(document.activeElement).toBe(cardAt(wrapper, 0).element) + }) + + it('offers Open on the front card only, and opens that workflow from it', async () => { + listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS) + const wrapper = await openHome() + const ctas = wrapper.findAll('[data-testid="home-workflow-cta"]') + + expect(ctas).toHaveLength(1) + expect(cardAt(wrapper, 0).find('[data-testid="home-workflow-cta"]').text()).toBe('Open') + expect(ctas[0]!.attributes('aria-hidden')).toBe('true') + + await ctas[0]!.trigger('click') + + expect(openCatalogWorkflow).toHaveBeenCalledExactlyOnceWith('workflow-0') + }) + it('turns the carousel when it is dragged, and does not open the card the drag ends on', async () => { listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS) const wrapper = await openHome() diff --git a/src/renderer/src/panel/HomeView.vue b/src/renderer/src/panel/HomeView.vue index 0eb40b52b..146487187 100644 --- a/src/renderer/src/panel/HomeView.vue +++ b/src/renderer/src/panel/HomeView.vue @@ -19,7 +19,7 @@ type LoadState = 'loading' | 'ready' | 'unavailable' const HOME_BUILD_LIMIT = 3 const TEXT_LINK_CLASS = - 'h-6 gap-1.5 rounded-[7px] px-1.5 text-[13px]/5 font-medium text-muted-foreground hover:bg-secondary hover:text-foreground' + '-my-1 h-8 gap-1.5 rounded-lg px-3 text-[13px]/5 font-medium text-muted-foreground hover:bg-secondary hover:text-foreground' const emit = defineEmits<{ pick: [installation: Installation] diff --git a/src/renderer/src/panel/home/HomeWorkflowCarousel.vue b/src/renderer/src/panel/home/HomeWorkflowCarousel.vue index c4feb6761..e397d6eb1 100644 --- a/src/renderer/src/panel/home/HomeWorkflowCarousel.vue +++ b/src/renderer/src/panel/home/HomeWorkflowCarousel.vue @@ -1,7 +1,7 @@