UNPKG

@kiwicom/smart-faq

Version:

95 lines (84 loc) 2.71 kB
// @flow import * as React from 'react'; import { ThemeProvider } from 'styled-components'; import defaultTheme from '@kiwicom/orbit-components/lib/defaultTheme'; import { UnwrappedArticleContent } from '../ArticleContent'; import PageVariantContext, { VARIANTS, } from '../../../../SmartFAQ/context/PageVariant'; import getTestRenderer from '../../../../services/TestRenderer'; import { UserContext } from '../../../../SmartFAQ/context/User'; const anything: any = null; const commonProps = { history: anything, match: anything, location: anything, isInGuaranteeArticle: true, showGuaranteeChat: false, article: { $refType: anything, $fragmentRefs: anything, id: 'abc123==', originalId: '123', title: 'Kiwi.com Guarantee', perex: 'Perex for Kiwi.com Guarantee', content: 'Content of the article about Kiwi.com Guarantee', }, theme: defaultTheme, }; const userContext = { user: null, brand: 'kiwicom', loginToken: null, simpleToken: null, kwAuthToken: null, onLogin: () => {}, onLogout: () => Promise.resolve(null), }; describe('ArticleContent', () => { it('should show call to sign in for non-logged user in guarantee article', () => { const wrapper = getTestRenderer(() => ( <ThemeProvider theme={defaultTheme}> <UserContext.Provider value={userContext}> <PageVariantContext.Provider value={VARIANTS.SIDEBAR}> <UnwrappedArticleContent {...commonProps} /> </PageVariantContext.Provider> </UserContext.Provider> </ThemeProvider> )); expect( wrapper.find(`[data-test="GuaranteeLoggedOut"]`).exists(), ).toBeTruthy(); }); it('should not show call to sign in in different article', () => { const wrapper = getTestRenderer(() => ( <ThemeProvider theme={defaultTheme}> <UserContext.Provider value={{ ...userContext, loginToken: 'sampleToken' }} > <UnwrappedArticleContent {...commonProps} isInGuaranteeArticle={false} /> </UserContext.Provider> </ThemeProvider> )); expect( wrapper.find(`[data-test="GuaranteeLoggedOut"]`).exists(), ).toBeFalsy(); }); it('should not show call to sign in for already logged user', () => { const wrapper = getTestRenderer(() => ( <ThemeProvider theme={defaultTheme}> <UserContext.Provider value={{ ...userContext, loginToken: 'sampleToken' }} > <UnwrappedArticleContent {...commonProps} /> </UserContext.Provider> </ThemeProvider> )); expect( wrapper.find(`[data-test="GuaranteeLoggedOut"]`).exists(), ).toBeFalsy(); }); });