Skip to content

chore: gets to total test coverage on config-utils methods #2137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export function getCuratedTags(): string[] {
export function getTableSortCriterias() {
const config = AppConfig.resourceConfig[ResourceType.table];

if (config && config.sortCriterias) {
if (config.sortCriterias) {
return config.sortCriterias;
}

Expand Down
159 changes: 135 additions & 24 deletions frontend/amundsen_application/static/js/config/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AppConfig from 'config/config';
import * as ConfigUtils from 'config/config-utils';
import configDefault from 'config/config-default';
import {
BadgeStyle,
NoticeSeverity,
Expand Down Expand Up @@ -110,6 +111,14 @@ describe('getSourceIconClass', () => {
ConfigUtils.DEFAULT_DATABASE_ICON_CLASS
);
});

it('returns default class for features', () => {
const testId = 'fakeName';

expect(ConfigUtils.getSourceIconClass(testId, ResourceType.feature)).toBe(
ConfigUtils.DEFAULT_DATABASE_ICON_CLASS
);
});
});

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

expect(ConfigUtils.getUniqueValueStatTypeName()).toBe(expectedValue);
});

describe('when stats not defined', () => {
it('returns undefined', () => {
const expected = undefined;

AppConfig.resourceConfig[ResourceType.table].stats = expected;
const actual = ConfigUtils.getUniqueValueStatTypeName();

expect(actual).toBe(expected);
});
});
});

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

AppConfig.resourceConfig[ResourceType.table].stats = {
iconNotRequiredTypes: expectedValue,
};
expect(actual).toBe(expected);
});

describe('when defined', () => {
it('returns the stat types where, if they are the only ones present, the stats icon will not be displayed', () => {
const expectedValue = ['test'];

AppConfig.resourceConfig[ResourceType.table].stats = {
iconNotRequiredTypes: expectedValue,
};

expect(ConfigUtils.getIconNotRequiredStatTypes()).toBe(expectedValue);
expect(ConfigUtils.getIconNotRequiredStatTypes()).toBe(expectedValue);
});
});
});

describe('getTableSortCriterias', () => {
it('returns the sorting criterias for tables', () => {
it('returns the sorting criterias', () => {
const expectedValue =
AppConfig.resourceConfig[ResourceType.table].sortCriterias;

expect(ConfigUtils.getTableSortCriterias()).toBe(expectedValue);
});

describe('when the sortCriteria is not defined', () => {
it('returns an empty object', () => {
const expected = {};

AppConfig.resourceConfig[ResourceType.table].sortCriterias = undefined;
const actual = ConfigUtils.getTableSortCriterias();

expect(actual).toEqual(expected);
});
});
});

describe('getBadgeConfig', () => {
Expand Down Expand Up @@ -741,36 +781,88 @@ describe('getIssueDescriptionTemplate', () => {
});

describe('issueTrackingProjectSelectionEnabled', () => {
it('returns whether or not project selection within the issueTracking feature is enabled', () => {
const config = AppConfig.issueTracking.projectSelection;
describe('when set', () => {
it('returns whether or not project selection within the issueTracking feature is enabled', () => {
const config = AppConfig.issueTracking.projectSelection;

expect(ConfigUtils.issueTrackingProjectSelectionEnabled()).toBe(
config ? config.enabled : false
);
expect(ConfigUtils.issueTrackingProjectSelectionEnabled()).toBe(
config ? config.enabled : false
);
});
});

describe('when un-set', () => {
it('returns false', () => {
AppConfig.issueTracking.projectSelection = undefined;
const expected = false;
const actual = ConfigUtils.issueTrackingProjectSelectionEnabled();

expect(actual).toBe(expected);
});
});
});

describe('getProjectSelectionTitle', () => {
it('returns an issue description template string', () => {
const config = AppConfig.issueTracking.projectSelection;
it('returns the default settings', () => {
AppConfig.issueTracking.projectSelection =
configDefault.issueTracking.projectSelection;
const expected = configDefault.issueTracking.projectSelection?.title;
const actual = ConfigUtils.getProjectSelectionTitle();

if (config) config.title = 'Project key';
expect(actual).toBe(expected);
});

expect(ConfigUtils.getProjectSelectionTitle()).toBe(
config ? config.title : ''
);
describe('when set', () => {
it('returns an issue description template string', () => {
const config = AppConfig.issueTracking.projectSelection;

if (config) config.title = 'Project key';

expect(ConfigUtils.getProjectSelectionTitle()).toBe(
config ? config.title : ''
);
});
});

describe('when un-set', () => {
it('returns an empty string', () => {
AppConfig.issueTracking.projectSelection = undefined;
const expected = '';
const actual = ConfigUtils.getProjectSelectionTitle();

expect(actual).toBe(expected);
});
});
});

describe('getProjectSelectionHint', () => {
it('returns an issue description template string', () => {
const config = AppConfig.issueTracking.projectSelection;
it('returns the default settings', () => {
const expected = configDefault.issueTracking.projectSelection?.inputHint;
const actual = ConfigUtils.getProjectSelectionHint();

if (config) config.inputHint = 'PROJECTKEY';
expect(actual).toBe(expected);
});

expect(ConfigUtils.getProjectSelectionHint()).toBe(
config ? config.inputHint : ''
);
describe('when set', () => {
it('returns an issue description template string', () => {
const config = AppConfig.issueTracking.projectSelection;

if (config) config.inputHint = 'PROJECTKEY';

expect(ConfigUtils.getProjectSelectionHint()).toBe(
config ? config.inputHint : ''
);
});
});

describe('when un-set', () => {
it('returns an empty string', () => {
AppConfig.issueTracking.projectSelection = undefined;
const expected = '';
const actual = ConfigUtils.getProjectSelectionHint();

expect(actual).toBe(expected);
});
});
});

Expand All @@ -782,6 +874,25 @@ describe('indexDashboardsEnabled', () => {
});
});

describe('indexFeaturesEnabled', () => {
it('returns false by default', () => {
expect(ConfigUtils.indexFeaturesEnabled()).toBe(
AppConfig.indexFeatures.enabled
);
});

describe('when setting it', () => {
it('returns whether or not the indexFeatures feature is enabled', () => {
const expected = true;

AppConfig.indexFeatures.enabled = expected;
const actual = ConfigUtils.indexFeaturesEnabled();

expect(actual).toBe(expected);
});
});
});

describe('indexUsersEnabled', () => {
it('returns whether or not the indexUsers feature is enabled', () => {
expect(ConfigUtils.indexUsersEnabled()).toBe(AppConfig.indexUsers.enabled);
Expand Down