@kiwicom/smart-faq
Version:
79 lines (74 loc) • 2.07 kB
JavaScript
// @flow
import * as React from 'react';
import { BrowserRouter } from 'react-router-dom';
import LogContext from '@kiwicom/nitro/lib/services/log/context';
import { mount } from 'enzyme';
import { WrappedFAQArticle } from '../FAQArticle';
import { SearchState } from '../../../SmartFAQ/context/SearchState';
const mockRefType: any = null;
let queriesBeforeClick = 5; //eslint-disable-line
const article = {
id: 'asdsadsa342dfse',
originalId: '23',
perex: 'aa',
title: 'llk',
$refType: mockRefType,
};
const searchState = {
searchText: 'Hola hola',
isVisible: false,
resetQueriesCount: jest.fn(() => {
queriesBeforeClick = 0;
}),
queriesBeforeClick,
changeSearchText: jest.fn(),
clearSearch: jest.fn(),
incrementQueriesCount: jest.fn(),
toggleSearch: jest.fn(),
enableSearch: jest.fn(),
disableSearch: jest.fn(),
};
describe('FAQArticle', () => {
it('click should track queriesBeforeClick and reset queriesCounter', () => {
const log = jest.fn();
const result = mount(
<BrowserRouter>
<SearchState.Provider value={searchState}>
<LogContext.Provider value={{ log }}>
<WrappedFAQArticle
isSearchResult
article={article}
categoryId={444}
onClick={jest.fn()}
/>
</LogContext.Provider>
</SearchState.Provider>
</BrowserRouter>,
);
result
.find('a[data-cy="faq-article-link"]')
.first()
.simulate('click');
expect(log.mock.calls).toHaveLength(1);
expect(log.mock.calls[0]).toEqual([
{
category: 'SmartFAQ',
subCategory: 'FAQs',
action: 'articleClicked',
destinations: {
ga: false,
logmole: false,
exponea: true,
bigQuery: true,
},
},
{
articleId: '23',
queriesBeforeClick: 5,
searchText: 'Hola hola',
},
]);
expect(queriesBeforeClick).toEqual(0);
expect(searchState.resetQueriesCount.mock.calls).toHaveLength(1);
});
});