Skip to content
Merged
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
5 changes: 0 additions & 5 deletions .github/workflows/php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
});
Original file line number Diff line number Diff line change
@@ -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: `
<div>
<slot
v-for="item in items"
name="items"
:item="item"
/>
</div>
`,
};

async function createWrapper() {
return mount(await Shopware.Component.build('swag-migration-premapping'), {
global: {
plugins: [Shopware.Store._rootState],
Comment thread
jozsefdamokos marked this conversation as resolved.
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);
});
});
Loading