Skip to content

Commit 5f75de6

Browse files
authored
chore: gets to total test coverage on config-utils methods (#2137)
Signed-off-by: Marcos Iglesias <[email protected]>
1 parent be25812 commit 5f75de6

File tree

2 files changed

+136
-25
lines changed

2 files changed

+136
-25
lines changed

frontend/amundsen_application/static/js/config/config-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export function getCuratedTags(): string[] {
337337
export function getTableSortCriterias() {
338338
const config = AppConfig.resourceConfig[ResourceType.table];
339339

340-
if (config && config.sortCriterias) {
340+
if (config.sortCriterias) {
341341
return config.sortCriterias;
342342
}
343343

frontend/amundsen_application/static/js/config/index.spec.ts

Lines changed: 135 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import AppConfig from 'config/config';
22
import * as ConfigUtils from 'config/config-utils';
3+
import configDefault from 'config/config-default';
34
import {
45
BadgeStyle,
56
NoticeSeverity,
@@ -110,6 +111,14 @@ describe('getSourceIconClass', () => {
110111
ConfigUtils.DEFAULT_DATABASE_ICON_CLASS
111112
);
112113
});
114+
115+
it('returns default class for features', () => {
116+
const testId = 'fakeName';
117+
118+
expect(ConfigUtils.getSourceIconClass(testId, ResourceType.feature)).toBe(
119+
ConfigUtils.DEFAULT_DATABASE_ICON_CLASS
120+
);
121+
});
113122
});
114123

115124
it('returns empty string for unconfigured resource', () => {
@@ -606,27 +615,58 @@ describe('getUniqueValueStatTypeName', () => {
606615

607616
expect(ConfigUtils.getUniqueValueStatTypeName()).toBe(expectedValue);
608617
});
618+
619+
describe('when stats not defined', () => {
620+
it('returns undefined', () => {
621+
const expected = undefined;
622+
623+
AppConfig.resourceConfig[ResourceType.table].stats = expected;
624+
const actual = ConfigUtils.getUniqueValueStatTypeName();
625+
626+
expect(actual).toBe(expected);
627+
});
628+
});
609629
});
610630

611631
describe('getIconNotRequiredStatTypes', () => {
612-
it('returns the stat types where, if they are the only ones present, the stats icon will not be displayed', () => {
613-
const expectedValue = ['test'];
632+
it('returns undefined by default', () => {
633+
const expected = undefined;
634+
const actual = ConfigUtils.getIconNotRequiredStatTypes();
614635

615-
AppConfig.resourceConfig[ResourceType.table].stats = {
616-
iconNotRequiredTypes: expectedValue,
617-
};
636+
expect(actual).toBe(expected);
637+
});
638+
639+
describe('when defined', () => {
640+
it('returns the stat types where, if they are the only ones present, the stats icon will not be displayed', () => {
641+
const expectedValue = ['test'];
642+
643+
AppConfig.resourceConfig[ResourceType.table].stats = {
644+
iconNotRequiredTypes: expectedValue,
645+
};
618646

619-
expect(ConfigUtils.getIconNotRequiredStatTypes()).toBe(expectedValue);
647+
expect(ConfigUtils.getIconNotRequiredStatTypes()).toBe(expectedValue);
648+
});
620649
});
621650
});
622651

623652
describe('getTableSortCriterias', () => {
624-
it('returns the sorting criterias for tables', () => {
653+
it('returns the sorting criterias', () => {
625654
const expectedValue =
626655
AppConfig.resourceConfig[ResourceType.table].sortCriterias;
627656

628657
expect(ConfigUtils.getTableSortCriterias()).toBe(expectedValue);
629658
});
659+
660+
describe('when the sortCriteria is not defined', () => {
661+
it('returns an empty object', () => {
662+
const expected = {};
663+
664+
AppConfig.resourceConfig[ResourceType.table].sortCriterias = undefined;
665+
const actual = ConfigUtils.getTableSortCriterias();
666+
667+
expect(actual).toEqual(expected);
668+
});
669+
});
630670
});
631671

632672
describe('getBadgeConfig', () => {
@@ -741,36 +781,88 @@ describe('getIssueDescriptionTemplate', () => {
741781
});
742782

743783
describe('issueTrackingProjectSelectionEnabled', () => {
744-
it('returns whether or not project selection within the issueTracking feature is enabled', () => {
745-
const config = AppConfig.issueTracking.projectSelection;
784+
describe('when set', () => {
785+
it('returns whether or not project selection within the issueTracking feature is enabled', () => {
786+
const config = AppConfig.issueTracking.projectSelection;
746787

747-
expect(ConfigUtils.issueTrackingProjectSelectionEnabled()).toBe(
748-
config ? config.enabled : false
749-
);
788+
expect(ConfigUtils.issueTrackingProjectSelectionEnabled()).toBe(
789+
config ? config.enabled : false
790+
);
791+
});
792+
});
793+
794+
describe('when un-set', () => {
795+
it('returns false', () => {
796+
AppConfig.issueTracking.projectSelection = undefined;
797+
const expected = false;
798+
const actual = ConfigUtils.issueTrackingProjectSelectionEnabled();
799+
800+
expect(actual).toBe(expected);
801+
});
750802
});
751803
});
752804

753805
describe('getProjectSelectionTitle', () => {
754-
it('returns an issue description template string', () => {
755-
const config = AppConfig.issueTracking.projectSelection;
806+
it('returns the default settings', () => {
807+
AppConfig.issueTracking.projectSelection =
808+
configDefault.issueTracking.projectSelection;
809+
const expected = configDefault.issueTracking.projectSelection?.title;
810+
const actual = ConfigUtils.getProjectSelectionTitle();
756811

757-
if (config) config.title = 'Project key';
812+
expect(actual).toBe(expected);
813+
});
758814

759-
expect(ConfigUtils.getProjectSelectionTitle()).toBe(
760-
config ? config.title : ''
761-
);
815+
describe('when set', () => {
816+
it('returns an issue description template string', () => {
817+
const config = AppConfig.issueTracking.projectSelection;
818+
819+
if (config) config.title = 'Project key';
820+
821+
expect(ConfigUtils.getProjectSelectionTitle()).toBe(
822+
config ? config.title : ''
823+
);
824+
});
825+
});
826+
827+
describe('when un-set', () => {
828+
it('returns an empty string', () => {
829+
AppConfig.issueTracking.projectSelection = undefined;
830+
const expected = '';
831+
const actual = ConfigUtils.getProjectSelectionTitle();
832+
833+
expect(actual).toBe(expected);
834+
});
762835
});
763836
});
764837

765838
describe('getProjectSelectionHint', () => {
766-
it('returns an issue description template string', () => {
767-
const config = AppConfig.issueTracking.projectSelection;
839+
it('returns the default settings', () => {
840+
const expected = configDefault.issueTracking.projectSelection?.inputHint;
841+
const actual = ConfigUtils.getProjectSelectionHint();
768842

769-
if (config) config.inputHint = 'PROJECTKEY';
843+
expect(actual).toBe(expected);
844+
});
770845

771-
expect(ConfigUtils.getProjectSelectionHint()).toBe(
772-
config ? config.inputHint : ''
773-
);
846+
describe('when set', () => {
847+
it('returns an issue description template string', () => {
848+
const config = AppConfig.issueTracking.projectSelection;
849+
850+
if (config) config.inputHint = 'PROJECTKEY';
851+
852+
expect(ConfigUtils.getProjectSelectionHint()).toBe(
853+
config ? config.inputHint : ''
854+
);
855+
});
856+
});
857+
858+
describe('when un-set', () => {
859+
it('returns an empty string', () => {
860+
AppConfig.issueTracking.projectSelection = undefined;
861+
const expected = '';
862+
const actual = ConfigUtils.getProjectSelectionHint();
863+
864+
expect(actual).toBe(expected);
865+
});
774866
});
775867
});
776868

@@ -782,6 +874,25 @@ describe('indexDashboardsEnabled', () => {
782874
});
783875
});
784876

877+
describe('indexFeaturesEnabled', () => {
878+
it('returns false by default', () => {
879+
expect(ConfigUtils.indexFeaturesEnabled()).toBe(
880+
AppConfig.indexFeatures.enabled
881+
);
882+
});
883+
884+
describe('when setting it', () => {
885+
it('returns whether or not the indexFeatures feature is enabled', () => {
886+
const expected = true;
887+
888+
AppConfig.indexFeatures.enabled = expected;
889+
const actual = ConfigUtils.indexFeaturesEnabled();
890+
891+
expect(actual).toBe(expected);
892+
});
893+
});
894+
});
895+
785896
describe('indexUsersEnabled', () => {
786897
it('returns whether or not the indexUsers feature is enabled', () => {
787898
expect(ConfigUtils.indexUsersEnabled()).toBe(AppConfig.indexUsers.enabled);

0 commit comments

Comments
 (0)