[ACS-4630] Fix no different rule is selected when rule is deleted (#2824)

* [ACS-4630] Fix no different rule is selected when rule is deleted

* Add unit test

* Some tests were failing due to objects with same references being used across different tests
This commit is contained in:
Thomas Hunter 2022-11-30 18:28:40 +00:00 committed by GitHub
parent 11dac5894b
commit bfe14f8143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -121,4 +121,19 @@ describe('FolderRuleSetsService', () => {
expect(selectRuleSpy).toHaveBeenCalledWith(ruleMock('owned-rule-1')); expect(selectRuleSpy).toHaveBeenCalledWith(ruleMock('owned-rule-1'));
}); });
it('should select a different rule when removing a rule', () => {
const selectRuleSpy = spyOn(folderRulesService, 'selectRule');
folderRuleSetsService['mainRuleSet'] = JSON.parse(JSON.stringify(ownedRuleSetMock));
folderRuleSetsService['inheritedRuleSets'] = JSON.parse(JSON.stringify([inheritedRuleSetMock]));
folderRuleSetsService.removeRuleFromMainRuleSet('owned-rule-1-id');
expect(selectRuleSpy).toHaveBeenCalledWith(ruleMock('owned-rule-2'));
selectRuleSpy.calls.reset();
folderRuleSetsService.removeRuleFromMainRuleSet('owned-rule-2-id');
expect(selectRuleSpy).toHaveBeenCalledWith(ruleMock('inherited-rule-1'));
});
}); });

View File

@ -210,6 +210,7 @@ export class FolderRuleSetsService {
this.mainRuleSet = null; this.mainRuleSet = null;
this.mainRuleSetSource.next(this.mainRuleSet); this.mainRuleSetSource.next(this.mainRuleSet);
} }
this.folderRulesService.selectRule(this.mainRuleSet?.rules[0] ?? this.inheritedRuleSets[0]?.rules[0] ?? null);
} }
} }
} }