Skip to content

Commit

Permalink
fix(sidebar): Fix defaultView logic (#749)
Browse files Browse the repository at this point in the history
Tweaking getSidebarView() logic so that defaultView is only returned if the state view has not been set (which is user changed when toggling tabs)
  • Loading branch information
Conrad Chan authored Jan 8, 2019
1 parent c08f744 commit bcbbae0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/ContentSidebar/ContentSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class ContentSidebar extends React.PureComponent<Props, State> {
}

// If there was a default view provided, force use that
if (defaultView) {
// only if the view has not been set
if (!view && defaultView) {
return defaultView;
}

Expand Down
15 changes: 14 additions & 1 deletion src/components/ContentSidebar/__tests__/ContentSidebar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,20 @@ describe('components/ContentSidebar/ContentSidebar', () => {
expect(instance.getSidebarView()).toBe('default');
});

test('should return skills when no current view is skills and skills exist', () => {
test('should not return default view if toggled view is set', () => {
const wrapper = getWrapper({ defaultView: 'default' });
const instance = wrapper.instance();
instance.setState({ view: 'activity' });

SidebarUtils.canHaveDetailsSidebar = jest.fn().mockReturnValueOnce(true);
SidebarUtils.shouldRenderSkillsSidebar = jest.fn().mockReturnValueOnce(true);
SidebarUtils.canHaveActivitySidebar = jest.fn().mockReturnValueOnce(true);
SidebarUtils.shouldRenderMetadataSidebar = jest.fn().mockReturnValueOnce(true);

expect(instance.getSidebarView()).toBe('activity');
});

test('should return skills when current view is skills and skills exist', () => {
const wrapper = getWrapper();
const instance = wrapper.instance();

Expand Down

0 comments on commit bcbbae0

Please sign in to comment.