Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/js/pages/sites/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down
57 changes: 57 additions & 0 deletions resources/js/tests/pages/SitesEdit.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
Loading