Skip to content
New issue

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

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

Already on GitHub? # to your account

Start of repo and AttachResult component #1

Merged
merged 5 commits into from
Mar 13, 2019

Conversation

mikegron
Copy link
Collaborator

  • Updated readme and other files, starting from search-ui-seed.
  • Added AttachResult component and tests.

We want this repository to be home to generic and reusable components which could be used by any integrations in the future. So any comment is appreciated!

I started from search-ui-seed and added a basic, generic AttachResult component. The component is super simple and leverages Promises, it's basically a toggle button which also sends analytics events. You just have to give it 3 functions: attach, detach and optionally isAttached. These are configured just like any other component options, there is an example in index.html.

image image image

Added AttachResult component and tests.
@mikegron mikegron added the enhancement New feature or request label Mar 11, 2019
@mikegron mikegron requested a review from erocheleau March 11, 2019 15:07
detach: (queryResult: IQueryResult) => Promise<void>;
/** Optional function to check the initial state of the component. */
isAttached?: (queryResult: IQueryResult) => Promise<boolean>;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ever want to provide an option for tooltip positioning, instead of it always being at the bottom, for the Quickview component we use PopperJs
https://github.com/coveo/search-ui/blob/master/src/ui/Quickview/Quickview.ts

it("should be attached when isAttached returns true", (done) => {
isAttachedSpy.and.returnValue(Promise.resolve(true));
attachResult = Mock.optionsResultComponentSetup(AttachResult, { isAttached: faker.isAttachedMock }, fakeResult);
setTimeout(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems strange that these setTimeout are needed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simulate the back and forth of a server call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was having a hard time trying to make the test work, for some reason I cannot call done() in the spy .and.callFake, the test kept timeouting.. do you have an idea why?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I've run into problems when using promises with the jest framework. There I solve it by moving the async method into the beforeEach. If the promise is the issue, maybe there is a thread that discusses it for Jasmine?

it("should be attached when isAttached returns true", (done) => {
isAttachedSpy.and.returnValue(Promise.resolve(true));
attachResult = Mock.optionsResultComponentSetup(AttachResult, { isAttached: faker.isAttachedMock }, fakeResult);
setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simulate the back and forth of a server call?

@mikegron mikegron merged commit 31897c8 into master Mar 13, 2019
@mikegron mikegron deleted the feature-AttachResultComponent branch March 15, 2019 13:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants