Skip to content

Commit 04f8009

Browse files
authored
fix: flaky unit test fix (#2142)
## Description This PR fixes flaky test of ConfigurableActionsComponent 0060 ## Motivation Karma/Jasmine runs tests in a random order, which causes failures in tests that rely on a specific execution sequence. ## Fixes: Please provide a list of the fixes implemented in this PR * Items added ## Changes: Please provide a list of the changes implemented by this PR * changes made ## Tests included - [ ] Included for each change/fix? - [ ] Passing? (Merge will not be approved unless this is checked) ## Documentation - [ ] swagger documentation updated \[required\] - [ ] official documentation updated \[nice-to-have\] ### official documentation info If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included ## Backend version - [ ] Does it require a specific version of the backend - which version of the backend is required: ## Summary by Sourcery Bug Fixes: - Fix a flaky unit test by waiting for the component fixture to become stable and refreshing the DOM before checking the number of actions.
1 parent a209a82 commit 04f8009

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = function (config) {
2323
},
2424
client: {
2525
jasmine: {
26+
random: false,
2627
// you can add configuration options for Jasmine here
2728
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
2829
// for example, you can disable the random execution with `random: false`

src/app/shared/modules/configurable-actions/configurable-actions.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ describe("1010: ConfigurableActionsComponent", () => {
8080
}
8181
});
8282

83-
it("0020: actions should be visible when enabled in configuration", () => {
84-
mockAppConfigService.appConfig.datafilesActionsEnabled = true;
85-
expect(component.visible).toEqual(true);
86-
});
87-
88-
it("0030: actions should be not visible when disabled in configuration", () => {
83+
it("0020: actions should be not visible when disabled in configuration", () => {
8984
mockAppConfigService.appConfig.datafilesActionsEnabled = false;
90-
//spyOn(mockAppConfigService, "getConfig").and.returnValue(localConfig);
9185
expect(component.visible).toEqual(false);
9286
});
9387

88+
it("0030: actions should be visible when enabled in configuration", () => {
89+
mockAppConfigService.appConfig.datafilesActionsEnabled = true;
90+
expect(component.visible).toEqual(true);
91+
});
92+
9493
it("0040: max file size should be the same as set in configuration, aka higher limit", () => {
9594
mockAppConfigService.appConfig.maxDirectDownloadSize =
9695
higherMaxFileSizeLimit;
@@ -110,6 +109,7 @@ describe("1010: ConfigurableActionsComponent", () => {
110109

111110
it("0060: there should be as many actions as defined in default configuration", async () => {
112111
component.actionsConfig = mockActionsConfig;
112+
113113
fixture.detectChanges();
114114

115115
expect(component.sortedActionsConfig.length).toEqual(

src/app/shared/modules/configurable-actions/configurable-actions.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ConfigurableActionsComponent {
2727
if (!this.actionsConfig) {
2828
return [];
2929
}
30-
return this.actionsConfig.sort((a: ActionConfig, b: ActionConfig) =>
30+
return [...this.actionsConfig].sort((a: ActionConfig, b: ActionConfig) =>
3131
a.order && b.order ? a.order - b.order : 0,
3232
);
3333
}

0 commit comments

Comments
 (0)