Skip to content

Commit

Permalink
Adds tests to featureFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Aug 10, 2023
1 parent 79256b1 commit 2391f7a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@
*/
import * as uiCore from '@superset-ui/core';

it('initializes feature flags', () => {
Object.defineProperty(window, 'featureFlags', {
value: undefined,
});
uiCore.initFeatureFlags();
expect(window.featureFlags).toEqual({});
});

it('initializes feature flags with predefined values', () => {
Object.defineProperty(window, 'featureFlags', {
value: undefined,
});
const featureFlags = {
CLIENT_CACHE: true,
DRILL_BY: false,
};
uiCore.initFeatureFlags(featureFlags);
expect(window.featureFlags).toEqual(featureFlags);
});

it('does nothing if feature flags are already initialized', () => {
const featureFlags = { DRILL_BY: false };
Object.defineProperty(window, 'featureFlags', {
value: featureFlags,
});
uiCore.initFeatureFlags({ DRILL_BY: true });
expect(window.featureFlags).toEqual(featureFlags);
});

it('returns false and raises console error if feature flags have not been initialized', () => {
const logging = jest.spyOn(uiCore.logging, 'error');
Object.defineProperty(window, 'featureFlags', {
Expand Down
20 changes: 11 additions & 9 deletions superset-frontend/src/dashboard/util/permissionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { FeatureFlag } from '@superset-ui/core';
import * as featureFlags from 'src/featureFlags';
import * as uiCore from '@superset-ui/core';
import {
UndefinedUser,
UserWithPermissionsAndRoles,
Expand Down Expand Up @@ -91,7 +90,10 @@ const dashboard: Dashboard = {
roles: [],
};

let isFeatureEnabledMock: jest.MockInstance<boolean, [feature: FeatureFlag]>;
let isFeatureEnabledMock: jest.MockInstance<
boolean,
[feature: uiCore.FeatureFlag]
>;

describe('canUserEditDashboard', () => {
it('allows owners to edit', () => {
Expand Down Expand Up @@ -160,10 +162,10 @@ test('canUserAccessSqlLab returns true for sqllab role', () => {
describe('canUserSaveAsDashboard with RBAC feature flag disabled', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
(featureFlag: FeatureFlag) =>
featureFlag !== FeatureFlag.DASHBOARD_RBAC,
(featureFlag: uiCore.FeatureFlag) =>
featureFlag !== uiCore.FeatureFlag.DASHBOARD_RBAC,
);
});

Expand All @@ -188,10 +190,10 @@ describe('canUserSaveAsDashboard with RBAC feature flag disabled', () => {
describe('canUserSaveAsDashboard with RBAC feature flag enabled', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
(featureFlag: FeatureFlag) =>
featureFlag === FeatureFlag.DASHBOARD_RBAC,
(featureFlag: uiCore.FeatureFlag) =>
featureFlag === uiCore.FeatureFlag.DASHBOARD_RBAC,
);
});

Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/dashboard/util/permissionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { FeatureFlag } from '@superset-ui/core';
import { isFeatureEnabled } from 'src/featureFlags';
import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
import {
isUserWithPermissionsAndRoles,
UndefinedUser,
Expand Down

0 comments on commit 2391f7a

Please sign in to comment.