-
Notifications
You must be signed in to change notification settings - Fork 622
feat: Replace BuilderExitButton with new BuilderFooterToolbar #9378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { mount } from '@vue/test-utils' | ||
| import { createPinia, setActivePinia } from 'pinia' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { computed, ref } from 'vue' | ||
| import { createI18n } from 'vue-i18n' | ||
|
|
||
| import type { AppMode } from '@/composables/useAppMode' | ||
|
|
||
| import BuilderFooterToolbar from '@/components/builder/BuilderFooterToolbar.vue' | ||
|
|
||
| const mockSetMode = vi.hoisted(() => vi.fn()) | ||
| const mockExitBuilder = vi.hoisted(() => vi.fn()) | ||
| const mockShowDialog = vi.hoisted(() => vi.fn()) | ||
|
|
||
| const mockState = { | ||
| mode: 'builder:select' as AppMode, | ||
| settingView: false | ||
| } | ||
|
|
||
| vi.mock('@/composables/useAppMode', () => ({ | ||
| useAppMode: () => ({ | ||
| mode: computed(() => mockState.mode), | ||
| isBuilderMode: ref(true), | ||
| setMode: mockSetMode | ||
| }) | ||
| })) | ||
|
|
||
| const mockHasOutputs = ref(true) | ||
|
|
||
| vi.mock('@/stores/appModeStore', () => ({ | ||
| useAppModeStore: () => ({ | ||
| exitBuilder: mockExitBuilder, | ||
| hasOutputs: mockHasOutputs, | ||
| $id: 'appMode' | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/stores/dialogStore', () => ({ | ||
| useDialogStore: () => ({ | ||
| dialogStack: [] | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/components/builder/useAppSetDefaultView', () => ({ | ||
| useAppSetDefaultView: () => ({ | ||
| settingView: computed(() => mockState.settingView), | ||
| showDialog: mockShowDialog | ||
| }) | ||
| })) | ||
|
|
||
| const i18n = createI18n({ | ||
| legacy: false, | ||
| locale: 'en', | ||
| messages: { | ||
| en: { | ||
| builderMenu: { exitAppBuilder: 'Exit app builder' }, | ||
| builderFooterToolbar: { | ||
| label: 'Builder navigation', | ||
| back: 'Back', | ||
| next: 'Next' | ||
| } | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| describe('BuilderFooterToolbar', () => { | ||
| beforeEach(() => { | ||
| setActivePinia(createPinia()) | ||
| vi.clearAllMocks() | ||
| mockState.mode = 'builder:select' | ||
| mockHasOutputs.value = true | ||
| mockState.settingView = false | ||
| }) | ||
|
|
||
| function mountComponent() { | ||
| return mount(BuilderFooterToolbar, { | ||
| global: { | ||
| plugins: [i18n], | ||
| stubs: { Button: false } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function getButtons(wrapper: ReturnType<typeof mountComponent>) { | ||
| const buttons = wrapper.findAll('button') | ||
| return { | ||
| exit: buttons[0], | ||
| back: buttons[1], | ||
| next: buttons[2] | ||
| } | ||
| } | ||
|
|
||
| it('disables back on the first step', () => { | ||
| mockState.mode = 'builder:select' | ||
| const { back } = getButtons(mountComponent()) | ||
| expect(back.attributes('disabled')).toBeDefined() | ||
| }) | ||
|
|
||
| it('enables back on the second step', () => { | ||
| mockState.mode = 'builder:arrange' | ||
| const { back } = getButtons(mountComponent()) | ||
| expect(back.attributes('disabled')).toBeUndefined() | ||
| }) | ||
|
|
||
| it('disables next on the setDefaultView step', () => { | ||
| mockState.settingView = true | ||
| const { next } = getButtons(mountComponent()) | ||
| expect(next.attributes('disabled')).toBeDefined() | ||
| }) | ||
|
|
||
| it('disables next on arrange step when no outputs', () => { | ||
| mockState.mode = 'builder:arrange' | ||
| mockHasOutputs.value = false | ||
| const { next } = getButtons(mountComponent()) | ||
| expect(next.attributes('disabled')).toBeDefined() | ||
| }) | ||
|
|
||
| it('enables next on select step', () => { | ||
| mockState.mode = 'builder:select' | ||
| const { next } = getButtons(mountComponent()) | ||
| expect(next.attributes('disabled')).toBeUndefined() | ||
| }) | ||
|
|
||
| it('calls setMode on back click', async () => { | ||
| mockState.mode = 'builder:arrange' | ||
| const { back } = getButtons(mountComponent()) | ||
| await back.trigger('click') | ||
| expect(mockSetMode).toHaveBeenCalledWith('builder:select') | ||
| }) | ||
|
|
||
| it('calls setMode on next click from select step', async () => { | ||
| mockState.mode = 'builder:select' | ||
| const { next } = getButtons(mountComponent()) | ||
| await next.trigger('click') | ||
| expect(mockSetMode).toHaveBeenCalledWith('builder:arrange') | ||
| }) | ||
|
|
||
| it('opens default view dialog on next click from arrange step', async () => { | ||
| mockState.mode = 'builder:arrange' | ||
| const { next } = getButtons(mountComponent()) | ||
| await next.trigger('click') | ||
| expect(mockSetMode).toHaveBeenCalledWith('builder:arrange') | ||
| expect(mockShowDialog).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('calls exitBuilder on exit button click', async () => { | ||
| const { exit } = getButtons(mountComponent()) | ||
| await exit.trigger('click') | ||
| expect(mockExitBuilder).toHaveBeenCalledOnce() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <template> | ||
| <nav | ||
| class="fixed bottom-4 left-1/2 z-1000 flex -translate-x-1/2 items-center gap-2 rounded-2xl border border-border-default bg-base-background p-2 shadow-interface" | ||
| :aria-label="t('builderFooterToolbar.label')" | ||
| > | ||
| <Button variant="textonly" size="lg" @click="onExitBuilder"> | ||
| {{ t('builderMenu.exitAppBuilder') }} | ||
| </Button> | ||
| <Button | ||
| variant="textonly" | ||
| size="lg" | ||
| :disabled="isFirstStep" | ||
| @click="onBack" | ||
| > | ||
| <i class="icon-[lucide--chevron-left]" aria-hidden="true" /> | ||
| {{ t('builderFooterToolbar.back') }} | ||
| </Button> | ||
| <Button size="lg" :disabled="isLastStep" @click="onNext"> | ||
| {{ t('builderFooterToolbar.next') }} | ||
| <i class="icon-[lucide--chevron-right]" aria-hidden="true" /> | ||
| </Button> | ||
| </nav> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { useEventListener } from '@vueuse/core' | ||
| import { storeToRefs } from 'pinia' | ||
| import { useI18n } from 'vue-i18n' | ||
|
|
||
| import Button from '@/components/ui/button/Button.vue' | ||
| import { useAppMode } from '@/composables/useAppMode' | ||
| import { useAppModeStore } from '@/stores/appModeStore' | ||
| import { useDialogStore } from '@/stores/dialogStore' | ||
|
|
||
| import { useAppSetDefaultView } from './useAppSetDefaultView' | ||
| import type { BuilderStepId } from './useBuilderSteps' | ||
| import { BUILDER_STEPS, useBuilderSteps } from './useBuilderSteps' | ||
|
|
||
| const { t } = useI18n() | ||
| const appModeStore = useAppModeStore() | ||
| const dialogStore = useDialogStore() | ||
| const { isBuilderMode, setMode } = useAppMode() | ||
| const { hasOutputs } = storeToRefs(appModeStore) | ||
| const { showDialog } = useAppSetDefaultView() | ||
| const { activeStepIndex, isFirstStep, isLastStep } = useBuilderSteps({ | ||
| hasOutputs | ||
| }) | ||
|
|
||
| useEventListener(window, 'keydown', (e: KeyboardEvent) => { | ||
| if ( | ||
| e.key === 'Escape' && | ||
| !e.ctrlKey && | ||
| !e.altKey && | ||
| !e.metaKey && | ||
| dialogStore.dialogStack.length === 0 && | ||
| isBuilderMode.value | ||
| ) { | ||
| e.preventDefault() | ||
| e.stopPropagation() | ||
| onExitBuilder() | ||
| } | ||
| }) | ||
|
|
||
| function onExitBuilder() { | ||
| void appModeStore.exitBuilder() | ||
| } | ||
|
|
||
| function navigateToStep(stepId: BuilderStepId) { | ||
| if (stepId === 'setDefaultView') { | ||
| setMode('builder:arrange') | ||
| showDialog() | ||
| } else { | ||
| setMode(stepId) | ||
| } | ||
| } | ||
|
|
||
| function onBack() { | ||
| if (isFirstStep.value) return | ||
| navigateToStep(BUILDER_STEPS[activeStepIndex.value - 1]) | ||
| } | ||
|
|
||
| function onNext() { | ||
| if (isLastStep.value) return | ||
| navigateToStep(BUILDER_STEPS[activeStepIndex.value + 1]) | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type { Ref } from 'vue' | ||
|
|
||
| import { computed } from 'vue' | ||
|
|
||
| import { useAppMode } from '@/composables/useAppMode' | ||
|
|
||
| import { useAppSetDefaultView } from './useAppSetDefaultView' | ||
|
|
||
| export const BUILDER_STEPS = [ | ||
| 'builder:select', | ||
| 'builder:arrange', | ||
| 'setDefaultView' | ||
| ] as const | ||
|
|
||
| export type BuilderStepId = (typeof BUILDER_STEPS)[number] | ||
|
|
||
| const ARRANGE_INDEX = BUILDER_STEPS.indexOf('builder:arrange') | ||
|
|
||
| export function useBuilderSteps(options?: { hasOutputs?: Ref<boolean> }) { | ||
| const { mode, isBuilderMode } = useAppMode() | ||
| const { settingView } = useAppSetDefaultView() | ||
|
|
||
| const activeStep = computed<BuilderStepId>(() => { | ||
| if (settingView.value) return 'setDefaultView' | ||
| if (isBuilderMode.value) { | ||
| return mode.value as BuilderStepId | ||
| } | ||
| return 'builder:select' | ||
| }) | ||
|
|
||
| const activeStepIndex = computed(() => | ||
| BUILDER_STEPS.indexOf(activeStep.value) | ||
| ) | ||
|
pythongosssss marked this conversation as resolved.
|
||
|
|
||
| const isFirstStep = computed(() => activeStepIndex.value === 0) | ||
|
|
||
| const isLastStep = computed(() => { | ||
| if (!options?.hasOutputs?.value) | ||
| return activeStepIndex.value >= ARRANGE_INDEX | ||
| return activeStepIndex.value >= BUILDER_STEPS.length - 1 | ||
| }) | ||
|
|
||
| return { activeStep, activeStepIndex, isFirstStep, isLastStep } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.