Skip to content

Commit

Permalink
fix(SFINT-3295): Add useResponsiveManager option to UserActions
Browse files Browse the repository at this point in the history
We want to be able to use the UserAction without him being tied to the ResponsiveComponentManager and without creating a ResponsiveHeaderButton.
  • Loading branch information
louis-bompart committed Jul 8, 2020
1 parent 53fe18a commit a3744ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/UserActions/UserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export interface IUserActionsOptions {
* Default: `False`
*/
hidden: Boolean;
/**
* Whether or not the UserAction component should use the CoveoSearchUI ResponsiveManager
* Inoperant if `hidden` is true.
*
* Default: `True`
*/
useResponsiveManager: Boolean;
}

/**
Expand Down Expand Up @@ -100,6 +107,9 @@ export class UserActions extends Component {
}),
hidden: ComponentOptions.buildBooleanOption({
defaultValue: false
}),
useResponsiveManager: ComponentOptions.buildBooleanOption({
defaultValue: true
})
};

Expand Down Expand Up @@ -130,7 +140,9 @@ export class UserActions extends Component {
this.tagViewsOfUser();

if (!options.hidden) {
ResponsiveUserActions.init(this.root, this);
if (options.useResponsiveManager) {
ResponsiveUserActions.init(this.root, this);
}
this.bind.onRootElement(QueryEvents.newQuery, () => this.hide());
this.hide();
}
Expand Down
34 changes: 34 additions & 0 deletions tests/components/UserActions/UserActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('UserActions', () => {

it('should not be displayed if hidden option is true', () => {
const responsiveComponentStub = sandbox.stub(ResponsiveUserActions, 'init');
const hideSpy = sandbox.spy(UserActions.prototype, 'hide');

Mock.advancedComponentSetup<UserActions>(
UserActions,
Expand All @@ -85,6 +86,39 @@ describe('UserActions', () => {
})
);

return delay(() => {
expect(hideSpy.called).toBe(false);
expect(responsiveComponentStub.called).toBe(false);
});
});

it('should register to the ResponsiveComponentManager by default', () => {
const responsiveComponentStub = sandbox.stub(ResponsiveUserActions, 'init');

Mock.advancedComponentSetup<UserActions>(
UserActions,
new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => {
fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS));
return env;
})
);

return delay(() => {
expect(responsiveComponentStub.called).toBe(true);
});
});

it('should not register to the ResponsiveComponentManager when useResponsiveManager is false', () => {
const responsiveComponentStub = sandbox.stub(ResponsiveUserActions, 'init');

Mock.advancedComponentSetup<UserActions>(
UserActions,
new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', useResponsiveManager: false }, env => {
fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS));
return env;
})
);

return delay(() => {
expect(responsiveComponentStub.called).toBe(false);
});
Expand Down

0 comments on commit a3744ac

Please sign in to comment.