Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuiter committed Mar 24, 2019
1 parent 0d442f1 commit a04bb4a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 97 deletions.
31 changes: 17 additions & 14 deletions client/src/store/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {validFeatureModel} from '../fixtures';
import FeatureModel from '../modeling/FeatureModel';
import {initialState, FeatureDiagramCollaborativeSession, State} from './types';
import logger from '../helpers/logger';
import {getCurrentArtifactPath} from '../router';

jest.mock('../helpers/logger');
jest.mock('../modeling/Kernel');
jest.mock('../router');

describe('reducer', () => {
const artifactPath = {project: 'project', artifact: 'artifact'},
Expand All @@ -23,10 +25,11 @@ describe('reducer', () => {
selectedFeatureIDs: [],
kernelFeatureModel: kernelFeatureModel,
kernelContext: {} // assume no kernel in the unit tests
}],
currentArtifactPath: artifactPath
}]
});

beforeEach(() => (getCurrentArtifactPath as jest.Mock).mockReturnValue(artifactPath));

it('returns the initial state', () => {
expect(reducer()).toBe(initialState);
});
Expand Down Expand Up @@ -145,9 +148,8 @@ describe('reducer', () => {
expect((<FeatureDiagramCollaborativeSession>state.collaborativeSessions[0]).isSelectMultipleFeatures).toBe(true);
});

it('does nothing if no feature model is available', () => {
const state = reducer(undefined, actions.ui.featureDiagram.feature.selectAll());
expect(state).toEqual(initialState);
it('throws if no feature model is available', () => {
expect(() => reducer(undefined, actions.ui.featureDiagram.feature.selectAll())).toThrow();
});
});

Expand All @@ -166,9 +168,8 @@ describe('reducer', () => {
expect((<FeatureDiagramCollaborativeSession>state.collaborativeSessions[0]).isSelectMultipleFeatures).toBe(false);
});

it('does nothing if no feature model is available', () => {
const state = reducer(undefined, actions.ui.featureDiagram.feature.deselectAll());
expect(state).toEqual(initialState);
it('throws if no feature model is available', () => {
expect(() => reducer(undefined, actions.ui.featureDiagram.feature.deselectAll())).toThrow();
});
});

Expand All @@ -184,9 +185,8 @@ describe('reducer', () => {
expect((<FeatureDiagramCollaborativeSession>state.collaborativeSessions[0]).selectedFeatureIDs).not.toContain('FeatureHouse');
});

it('does nothing if no feature model is available', () => {
const state = reducer(undefined, actions.ui.featureDiagram.feature.collapseAll());
expect(state).toEqual(initialState);
it('throws if no feature model is available', () => {
expect(() => reducer(undefined, actions.ui.featureDiagram.feature.collapseAll())).toThrow();
});
});

Expand All @@ -198,22 +198,23 @@ describe('reducer', () => {
expect((<FeatureDiagramCollaborativeSession>state.collaborativeSessions[0]).collapsedFeatureIDs).toHaveLength(0);
});

it('does nothing if no feature model is available', () => {
const state = reducer(undefined, actions.ui.featureDiagram.feature.expandAll());
expect(state).toEqual(initialState);
it('throws if no feature model is available', () => {
expect(() => reducer(undefined, actions.ui.featureDiagram.feature.expandAll())).toThrow();
});
});
});

describe('overlay', () => {
describe('show overlay', () => {
it('shows the about panel', () => {
(getCurrentArtifactPath as jest.Mock).mockReturnValue(undefined);
const state = reducer(undefined, actions.ui.overlay.show({overlay: OverlayType.aboutPanel, overlayProps: {}}));
expect(state.overlay).toBe(OverlayType.aboutPanel);
expect(state.overlayProps).toEqual({});
});

it('shows a feature callout', () => {
(getCurrentArtifactPath as jest.Mock).mockReturnValue(undefined);
let state = reducer(undefined, actions.ui.overlay.show({overlay: OverlayType.featureCallout, overlayProps: {featureID: 'FeatureIDE'}}));
expect(state.overlay).toBe(OverlayType.featureCallout);
expect(state.overlayProps).toEqual({featureID: 'FeatureIDE'});
Expand All @@ -231,6 +232,7 @@ describe('reducer', () => {

describe('hide overlay', () => {
it('hides an overlay after showing it', () => {
(getCurrentArtifactPath as jest.Mock).mockReturnValue(undefined);
let state = reducer(undefined, actions.ui.overlay.show({overlay: OverlayType.aboutPanel, overlayProps: {}}));
expect(state.overlay).toBe(OverlayType.aboutPanel);
expect(state.overlayProps).toEqual({});
Expand All @@ -240,6 +242,7 @@ describe('reducer', () => {
});

it('does nothing if the currently shown overlay is of another type', () => {
(getCurrentArtifactPath as jest.Mock).mockReturnValue(undefined);
let state = reducer(undefined, actions.ui.overlay.show({overlay: OverlayType.aboutPanel, overlayProps: {}}));
expect(state.overlay).toBe(OverlayType.aboutPanel);
expect(state.overlayProps).toEqual({});
Expand Down
80 changes: 0 additions & 80 deletions client/src/store/selectors.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions client/src/store/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import createCachedSelector from 're-reselect';
import FeatureModel from '../modeling/FeatureModel';
import {State, CollaborativeSession, FeatureDiagramCollaborativeSession} from './types';
import logger from '../helpers/logger';
import {ArtifactPath, isArtifactPathEqual, artifactPathToString} from '../types';
import {ArtifactPath, isArtifactPathEqual, artifactPathToString, artifactPathCacheKey} from '../types';
import {KernelFeatureModel} from '../modeling/types';
import {getCurrentArtifactPath} from '../router';

Expand Down Expand Up @@ -36,7 +36,7 @@ const lookupCollaborativeSession = (collaborativeSessions: CollaborativeSession[
export const getCollaborativeSession = createCachedSelector(
(state: State, artifactPath: ArtifactPath) => lookupCollaborativeSession(state.collaborativeSessions, artifactPath),
collaborativeSession => collaborativeSession)(
(_state: State, artifactPath: ArtifactPath) => artifactPathToString(artifactPath));
(_state: State, artifactPath: ArtifactPath) => artifactPathCacheKey(artifactPath));

export function getCurrentCollaborativeSession(state: State): CollaborativeSession | undefined {
const currentArtifactPath = getCurrentArtifactPath(state.collaborativeSessions);
Expand All @@ -59,7 +59,7 @@ export const getFeatureModel = createCachedSelector(
return undefined;
return FeatureModel.fromKernel(kernelFeatureModel).collapse(collapsedFeatureIDs);
}
)((_state: State, artifactPath: ArtifactPath) => artifactPathToString(artifactPath));
)((_state: State, artifactPath: ArtifactPath) => artifactPathCacheKey(artifactPath));

export function getCurrentFeatureModel(state: State): FeatureModel | undefined {
const currentArtifactPath = getCurrentArtifactPath(state.collaborativeSessions);
Expand Down
4 changes: 4 additions & 0 deletions client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export function artifactPathToString(artifactPath: ArtifactPath): string {
return artifactPath ? `${artifactPath.project}/${artifactPath.artifact}` : `(unknown artifact)`;
}

export function artifactPathCacheKey(artifactPath: ArtifactPath): string {
return artifactPath ? `${artifactPath.project.toLowerCase()}/${artifactPath.artifact.toLowerCase()}` : '';
}

export function isArtifactPathEqual(a?: ArtifactPath, b?: ArtifactPath): boolean {
return typeof a !== 'undefined' && typeof b !== 'undefined' &&
a.project.toLowerCase() === b.project.toLowerCase() && a.artifact.toLowerCase() === b.artifact.toLowerCase();
Expand Down

0 comments on commit a04bb4a

Please sign in to comment.