Skip to content

Commit

Permalink
PR changes and unit tests
Browse files Browse the repository at this point in the history
SNOW-364
  • Loading branch information
mikegron committed Jul 3, 2020
1 parent 0ab6bca commit 763b85b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
7 changes: 2 additions & 5 deletions src/components/AttachResult/AttachResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,11 @@ export class AttachResult extends Component {
let customData: IAnalyticsCaseAttachMeta = {
resultUriHash: this.queryResult.raw.urihash,
author: this.queryResult.raw.author,
articleID:
this.options.articleIdField && this.queryResult.raw[this.options.articleIdField]
? this.queryResult.raw[this.options.articleIdField]
: null,
articleID: this.queryResult.raw[this.options.articleIdField],
caseID: this.options.caseId
};

this.usageAnalytics.logCustomEvent<IAnalyticsCaseDetachMeta>(cause, customData, this.root);
this.usageAnalytics.logCustomEvent<IAnalyticsCaseDetachMeta>(cause, customData, this.element, this.queryResult);
}

protected render(): void {
Expand Down
75 changes: 60 additions & 15 deletions tests/components/AttachResult/AttachResult.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AttachResult, IAttachResultOptions } from '../../../src/components/AttachResult/AttachResult';
import { Mock, Fake } from 'coveo-search-ui-tests';
import { IQueryResult, Logger } from 'coveo-search-ui';
import { IQueryResult, Logger, analyticsActionCauseList } from 'coveo-search-ui';
import { AttachResultEvents, IAttachResultEventArgs } from '../../../src/components/AttachResult/Events';

describe('AttachResult', () => {
let attachResult: Mock.IBasicComponentSetup<AttachResult>;
let fakeResult = Fake.createFakeResult();
fakeResult.raw.article = 'foo';

beforeAll(() => {
Logger.disable();
Expand Down Expand Up @@ -94,14 +95,23 @@ describe('AttachResult', () => {

attachSpy = spyOn(faker, 'attach').and.callThrough();

attachResult = Mock.optionsResultComponentSetup(
attachResult = Mock.advancedResultComponentSetup(
AttachResult,
{
attach: faker.attach,
detachCaption: 'detach me',
attachCaption: 'attach me'
},
fakeResult
fakeResult,
new Mock.AdvancedComponentSetupOptions(
document.createElement('div'),
{
attach: faker.attach,
detachCaption: 'detach me',
attachCaption: 'attach me',
caseId: 'testcase',
articleIdField: 'article'
},
env => {
env.searchInterface.usageAnalytics = env.usageAnalytics;
return env;
}
)
);

attachResult.cmp.detach().then(() => {
Expand Down Expand Up @@ -145,6 +155,22 @@ describe('AttachResult', () => {
});
attachResult.cmp.attach();
});

it('should log a click and attach event', async () => {
await attachResult.cmp.attach();
expect(attachResult.env.usageAnalytics.logClickEvent).toHaveBeenCalledWith(
analyticsActionCauseList.caseAttach,
jasmine.any(Object),
fakeResult,
attachResult.cmp.element
);
expect(attachResult.env.usageAnalytics.logCustomEvent).toHaveBeenCalledWith(
analyticsActionCauseList.caseAttach,
jasmine.objectContaining({ caseID: 'testcase', articleID: 'foo', resultUriHash: fakeResult.raw.urihash }),
attachResult.cmp.element,
fakeResult
);
});
});

describe('detach', () => {
Expand All @@ -159,14 +185,23 @@ describe('AttachResult', () => {

detachSpy = spyOn(faker, 'detach').and.callThrough();

attachResult = Mock.optionsResultComponentSetup(
attachResult = Mock.advancedResultComponentSetup(
AttachResult,
{
detach: faker.detach,
detachCaption: 'detach me',
attachCaption: 'attach me'
},
fakeResult
fakeResult,
new Mock.AdvancedComponentSetupOptions(
document.createElement('div'),
{
detach: faker.detach,
detachCaption: 'detach me',
attachCaption: 'attach me',
caseId: 'testcase',
articleIdField: 'article'
},
env => {
env.searchInterface.usageAnalytics = env.usageAnalytics;
return env;
}
)
);

attachResult.cmp.attach().then(() => {
Expand Down Expand Up @@ -210,6 +245,16 @@ describe('AttachResult', () => {
});
attachResult.cmp.detach();
});

it('should log a detach event', async () => {
await attachResult.cmp.detach();
expect(attachResult.env.usageAnalytics.logCustomEvent).toHaveBeenCalledWith(
analyticsActionCauseList.caseDetach,
jasmine.objectContaining({ caseID: 'testcase', articleID: 'foo', resultUriHash: fakeResult.raw.urihash }),
attachResult.cmp.element,
fakeResult
);
});
});

describe('click', () => {
Expand Down

0 comments on commit 763b85b

Please sign in to comment.