Skip to content

Commit

Permalink
NEXT-19742 - Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taltholtmann committed Apr 20, 2022
1 parent dda6258 commit 38bad62
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Component.register('sw-condition-tree', {
data() {
return {
conditionTree: null,
initialLoadingDone: false,
};
},

Expand Down Expand Up @@ -186,6 +187,10 @@ Component.register('sw-condition-tree', {
const rootCondition = this.applyRootIfNecessary();
this.conditionTree = this.createTreeRecursive(rootCondition, this.initialConditions);
this.emitChange([]);
if (!this.initialLoadingDone) {
this.$emit('initial-loading-done');
this.initialLoadingDone = true;
}
},

createTreeRecursive(condition, conditions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ Component.register('sw-settings-rule-detail', {
});
},

openChangeModal(destination) {
this.nextRoute = destination;
this.isDisplayingSaveChangesWarning = true;
},

onLeaveModalClose() {
this.nextRoute = null;
this.isDisplayingSaveChangesWarning = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
:condition-repository="conditionRepository"
:is-loading="isLoading"
@conditions-changed="conditionsChanged"
@tree-finished-loading="setTreeFinishedLoading"
/>
{% endblock %}
</sw-card-view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
:root-condition="null"
:disabled="!acl.can('rule.editor')"
@conditions-changed="onConditionsChanged"
@initial-loading-done="$emit('tree-finished-loading')"
/>
</sw-card>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ function createWrapper(privileges = [], isNewRule = false) {
'sw-context-button': true,
'sw-button-group': true,
'sw-icon': true,
'sw-discard-changes-modal': {
template: `
<div>
Iam here
</div>`
}
},
propsData: {
ruleId: isNewRule ? null : 'uuid1'
Expand All @@ -52,7 +58,8 @@ function createWrapper(privileges = [], isNewRule = false) {
create: () => {
return createRuleMock(true);
},
get: () => Promise.resolve(createRuleMock(false))
get: () => Promise.resolve(createRuleMock(false)),
hasChanges: (rule, hasChanges) => { return hasChanges ?? false; },
};
}
},
Expand All @@ -62,8 +69,10 @@ function createWrapper(privileges = [], isNewRule = false) {

return privileges.includes(identifier);
}
}

},
feature: {
isActive: () => true
},
},
mocks: {
$route: {
Expand All @@ -72,7 +81,8 @@ function createWrapper(privileges = [], isNewRule = false) {
params: {
id: ''
}
}
},
next: () => Promise.resolve()
}
});
}
Expand Down Expand Up @@ -121,4 +131,71 @@ describe('src/module/sw-settings-rule/page/sw-settings-rule-detail', () => {

expect(wrapper.find('.sw-settings-rule-detail__tabs').exists()).toBeFalsy();
});

it('should set user changes when condition tree changed', async () => {
const wrapper = createWrapper([
'rule.editor'
], false);

expect(wrapper.vm.conditionsTreeContainsUserChanges).toBeFalsy();
wrapper.vm.setTreeFinishedLoading();
wrapper.vm.conditionsChanged({ conditions: [], deletedIds: [] });
await wrapper.vm.$nextTick();
expect(wrapper.vm.conditionsTreeContainsUserChanges).toBeTruthy();
});

it('should open changes modal when leaving the route', async () => {
const wrapper = createWrapper([
'rule.editor'
], false);

wrapper.setData({
conditionsTreeContainsUserChanges: true
});

const next = jest.fn();
wrapper.vm.unsavedDataLeaveHandler(
{ name: 'sw.settings.rule.detail.assignments' }, { name: 'sw.settings.rule.detail.base' }, next
);


expect(next).toHaveBeenCalled();
});

it('should reset condition tree state when navigating back to the base tab', async () => {
const wrapper = createWrapper([
'rule.editor'
], false);

wrapper.setData({
conditionsTreeContainsUserChanges: true
});

const next = jest.fn();
wrapper.vm.unsavedDataLeaveHandler(
{ name: 'sw.settings.rule.detail.base' }, {}, next
);

expect(wrapper.vm.conditionsTreeContainsUserChanges).toBeFalsy();
expect(wrapper.vm.conditionTreeFinishedLoading).toBeFalsy();
expect(next).toHaveBeenCalled();
});

it('should not open changes modal when there are no changes', async () => {
const wrapper = createWrapper([
'rule.editor'
], false);

wrapper.setData({
conditionsTreeContainsUserChanges: false
});

const next = jest.fn();
wrapper.vm.unsavedDataLeaveHandler(
{}, {}, next
);

expect(wrapper.vm.isDisplayingSaveChangesWarning).toBeFalsy();
expect(next).toHaveBeenCalled();
});
});

0 comments on commit 38bad62

Please sign in to comment.