diff --git a/.github/workflows/php.yaml b/.github/workflows/php.yaml
index 25e13e53f..b03e4f0e2 100644
--- a/.github/workflows/php.yaml
+++ b/.github/workflows/php.yaml
@@ -6,11 +6,6 @@ on:
branches:
- trunk
pull_request:
- paths:
- - composer.json
- - src/**/*.php
- - tests/**/*.php
- - .github/workflows/**
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
diff --git a/src/Resources/app/administration/src/module/swag-migration/component/card/swag-migration-premapping/index.ts b/src/Resources/app/administration/src/module/swag-migration/component/card/swag-migration-premapping/index.ts
index e4c3854e4..7c63247be 100644
--- a/src/Resources/app/administration/src/module/swag-migration/component/card/swag-migration-premapping/index.ts
+++ b/src/Resources/app/administration/src/module/swag-migration/component/card/swag-migration-premapping/index.ts
@@ -73,29 +73,26 @@ export default Shopware.Component.wrapComponentConfig({
return;
}
- const filledOut = this.premapping.every((group: MigrationPremapping) =>
- group.mapping.every(
- (mapping) =>
- mapping.destinationUuid !== null &&
- mapping.destinationUuid !== undefined &&
- mapping.destinationUuid !== '',
- ),
+ await this.migrationApiService.writePremapping(
+ this.premapping.map((group: MigrationPremapping) => ({
+ ...group,
+ mapping: group.mapping.filter((mapping) => {
+ return !!mapping.destinationUuid;
+ }),
+ })),
);
-
- if (!filledOut) {
- return;
- }
-
- await this.migrationApiService.writePremapping(this.premapping);
},
async onPremappingChanged() {
this.migrationStore.setIsLoading(true);
- debounce(async () => {
- await this.savePremapping();
- this.migrationStore.setIsLoading(false);
- }, 500)();
+ this.savePremappingDebounced();
},
+
+ savePremappingDebounced: debounce(function savePremappingDebounced() {
+ void this.savePremapping().finally(() => {
+ this.migrationStore.setIsLoading(false);
+ });
+ }, 500),
},
});
diff --git a/tests/Jest/src/module/swag-migration/component/card/swag-migration-premapping.spec.js b/tests/Jest/src/module/swag-migration/component/card/swag-migration-premapping.spec.js
new file mode 100644
index 000000000..3e0d7355b
--- /dev/null
+++ b/tests/Jest/src/module/swag-migration/component/card/swag-migration-premapping.spec.js
@@ -0,0 +1,146 @@
+import { mount } from '@vue/test-utils';
+import 'SwagMigrationAssistant/module/swag-migration/store/migration.store';
+import swagMigrationPremapping from 'SwagMigrationAssistant/module/swag-migration/component/card/swag-migration-premapping';
+import { fixturePreMapping } from '@/fixture';
+
+Shopware.Component.register('swag-migration-premapping', swagMigrationPremapping);
+
+const migrationApiServiceMock = {
+ generatePremapping: jest.fn(() => Promise.resolve([])),
+ writePremapping: jest.fn(() => Promise.resolve()),
+};
+
+const swagMigrationTabCardStub = {
+ name: 'swag-migration-tab-card',
+ props: ['items'],
+ template: `
+
+
+
+ `,
+};
+
+async function createWrapper() {
+ return mount(await Shopware.Component.build('swag-migration-premapping'), {
+ global: {
+ plugins: [Shopware.Store._rootState],
+ provide: {
+ migrationApiService: migrationApiServiceMock,
+ },
+ stubs: {
+ 'swag-migration-tab-card': swagMigrationTabCardStub,
+ 'swag-migration-grid-selection': true,
+ },
+ },
+ });
+}
+
+describe('module/swag-migration/component/card/swag-migration-premapping', () => {
+ let store = null;
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+
+ store = Shopware.Store.get('swagMigration');
+ store.$reset();
+ });
+
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ it('writes partially filled premapping', async () => {
+ store.premapping = [
+ {
+ ...fixturePreMapping[0],
+ mapping: [
+ fixturePreMapping[0].mapping[0],
+ {
+ ...fixturePreMapping[0].mapping[1],
+ destinationUuid: null,
+ },
+ ],
+ },
+ ];
+
+ const wrapper = await createWrapper();
+ jest.useFakeTimers();
+ const gridSelection = wrapper.findComponent({ name: 'swag-migration-grid-selection' });
+
+ gridSelection.vm.$emit('update:value');
+ jest.advanceTimersByTime(500);
+ await flushPromises();
+
+ expect(migrationApiServiceMock.writePremapping).toHaveBeenCalledTimes(1);
+ expect(migrationApiServiceMock.writePremapping).toHaveBeenCalledWith([
+ {
+ ...store.premapping[0],
+ mapping: [
+ store.premapping[0].mapping[0],
+ ],
+ },
+ ]);
+ });
+
+ it('persists regenerated partial premapping after changing the data selection', async () => {
+ const regeneratedPremapping = [
+ {
+ ...fixturePreMapping[0],
+ mapping: [
+ {
+ ...fixturePreMapping[0].mapping[0],
+ destinationUuid: 'mr',
+ },
+ {
+ ...fixturePreMapping[0].mapping[1],
+ destinationUuid: null,
+ },
+ ],
+ },
+ ];
+
+ migrationApiServiceMock.generatePremapping.mockResolvedValueOnce(regeneratedPremapping);
+
+ await createWrapper();
+
+ store.setDataSelectionIds(['customersOrders']);
+ await flushPromises();
+
+ expect(migrationApiServiceMock.generatePremapping).toHaveBeenCalledTimes(1);
+ expect(migrationApiServiceMock.generatePremapping).toHaveBeenCalledWith(['customersOrders']);
+ expect(migrationApiServiceMock.writePremapping).toHaveBeenCalledTimes(1);
+ expect(migrationApiServiceMock.writePremapping).toHaveBeenCalledWith([
+ {
+ ...store.premapping[0],
+ mapping: [
+ regeneratedPremapping[0].mapping[0],
+ ],
+ },
+ ]);
+ });
+
+ it('debounces repeated premapping changes into a single save', async () => {
+ jest.useFakeTimers();
+
+ store.premapping = fixturePreMapping;
+
+ const wrapper = await createWrapper();
+ const gridSelection = wrapper.findComponent({ name: 'swag-migration-grid-selection' });
+
+ gridSelection.vm.$emit('update:value');
+ gridSelection.vm.$emit('update:value');
+
+ expect(store.isLoading).toBe(true);
+ expect(migrationApiServiceMock.writePremapping).not.toHaveBeenCalled();
+
+ jest.advanceTimersByTime(500);
+ await flushPromises();
+
+ expect(migrationApiServiceMock.writePremapping).toHaveBeenCalledTimes(1);
+ expect(store.isLoading).toBe(false);
+ });
+});