diff --git a/resources/js/pages/sites/Edit.vue b/resources/js/pages/sites/Edit.vue index 9eb90a7edab..9c4f172688d 100644 --- a/resources/js/pages/sites/Edit.vue +++ b/resources/js/pages/sites/Edit.vue @@ -3,6 +3,7 @@ import Head from '@/pages/layout/Head.vue'; import { Header, CommandPaletteItem, Button, PublishContainer, DocsCallout } from '@ui'; import { computed, onMounted, onUnmounted, ref, useTemplateRef } from 'vue'; import { Pipeline, Request } from '@ui/Publish/SavePipeline.js'; +import { clone } from '@/bootstrap/globals.js'; const props = defineProps({ blueprint: Object, @@ -12,7 +13,7 @@ const props = defineProps({ }); const container = useTemplateRef('container'); -const values = ref(props.initialValues); +const values = ref(clone(props.initialValues)); const errors = ref({}); const saving = ref(false); diff --git a/resources/js/tests/pages/SitesEdit.test.js b/resources/js/tests/pages/SitesEdit.test.js new file mode 100644 index 00000000000..463b48c56f0 --- /dev/null +++ b/resources/js/tests/pages/SitesEdit.test.js @@ -0,0 +1,57 @@ +import { mount } from '@vue/test-utils'; +import { afterEach, expect, test, vi } from 'vitest'; +import { data_set } from '@/bootstrap/globals'; +import Edit from '@/pages/sites/Edit.vue'; + +let multisiteEnabled = false; + +globalThis.Statamic = { + $config: { get: (key) => (key === 'multisiteEnabled' ? multisiteEnabled : undefined) }, + $keys: { bindGlobal: () => ({ destroy: () => {} }) }, + $commandPalette: { add: () => {}, category: { Actions: 'Actions' } }, +}; + +function mountEdit(initialValues) { + return mount(Edit, { + props: { blueprint: null, initialValues, meta: {}, updateUrl: '/update' }, + global: { + stubs: { + Head: true, + Header: true, + CommandPaletteItem: true, + Button: true, + PublishContainer: true, + DocsCallout: true, + }, + mocks: { + $commandPalette: { category: { Actions: 'Actions' } }, + }, + }, + }); +} + +afterEach(() => { + multisiteEnabled = false; + vi.restoreAllMocks(); +}); + +test('it warns before saving a changed site handle', () => { + const confirm = vi.spyOn(window, 'confirm').mockReturnValue(false); + const wrapper = mountEdit({ handle: 'default', name: 'Default' }); + + data_set(wrapper.vm.values, 'handle', 'main'); + wrapper.vm.save(); + + expect(confirm).toHaveBeenCalledOnce(); +}); + +test('it warns before saving a changed handle when multisite is enabled', () => { + multisiteEnabled = true; + const confirm = vi.spyOn(window, 'confirm').mockReturnValue(false); + const wrapper = mountEdit({ sites: [{ handle: 'default' }, { handle: 'french' }] }); + + data_set(wrapper.vm.values, 'sites.0.handle', 'english'); + wrapper.vm.save(); + + expect(confirm).toHaveBeenCalledOnce(); +});