Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

add test for Header

kruzhambus051ccedbcf20
diff --git a/src/components/__test__/Header.test.tsx b/src/components/__test__/Header.test.tsx
new file mode 100644
index 000000000..3022f1a9a
--- /dev/null
+++ b/src/components/__test__/Header.test.tsx
@@ -0,0 +1,112 @@
+/* eslint-disable import/no-extraneous-dependencies */
+import React from 'react'
+import { render, screen } from '@testing-library/react'
+import { I18nextProvider } from 'react-i18next'
+import i18n from 'i18next'
+import { IUser } from 'redux/models/IUser'
+import { createMemoryHistory } from 'history'
+import { Router } from 'react-router-dom'
+import configureMockStore from 'redux-mock-store'
+
+import { Provider } from 'react-redux'
+import Header from '../Header'
+
+describe('Header', () => {
+ const history = createMemoryHistory()
+ const authenticated = true
+ const mockStore = configureMockStore()
+ const store = mockStore({})
+ const theme = 'dark'
+ const user: IUser = {
+ id: 'testid',
+ email: '[email protected]',
+ nickname: 'testuser',
+ roles: ['admin'],
+ isActive: true,
+ planCode: 'testplan',
+ trialEndDate: '2021-01-01T00:00:00.000Z',
+ reportFrequency: 'daily',
+ emailRequests: 0,
+ evWarningSentOn: null,
+ subID: null,
+ subUpdateURL: null,
+ subCancelURL: null,
+ created: '',
+ updated: '',
+ exportedAt: '',
+ timezone: '',
+ theme: null,
+ isTwoFactorAuthenticationEnabled: false,
+ trialReminderSent: false,
+ billingFrequency: null,
+ nextBillDate: null,
+ cancellationEffectiveDate: null,
+ apiKey: null,
+ telegramChatId: null,
+ isTelegramChatIdConfirmed: false,
+ timeFormat: '',
+ sharedProjects: [],
+ }
+
+ beforeEach(() => {
+ jest.clearAllMocks()
+ })
+
+ beforeAll(() => {
+ i18n.init({
+ lng: 'en',
+ fallbackLng: 'en',
+ resources: {
+ en: {
+ 'footer.contact': 'Contact Us',
+ 'footer.blog': 'Blog',
+ 'common.logout': 'Logout',
+ 'common.login': 'Login',
+ 'common.dashboard': 'Dashboard',
+ },
+ },
+ })
+ })
+
+ test('renders authed header if authenticated', () => {
+ render(
+ <Router history={history}>
+ <Provider store={store}>
+ <I18nextProvider i18n={i18n}>
+ <Header authenticated={authenticated} theme={theme} user={user} />
+ </I18nextProvider>
+ </Provider>
+ </Router>,
+ )
+
+ expect(screen.getAllByText(/common.dashboard/i)).toHaveLength(2)
+ })
+
+ test('renders not-authed header if not authenticated', () => {
+ render(
+ <Router history={history}>
+ <Provider store={store}>
+ <I18nextProvider i18n={i18n}>
+ <Header authenticated={false} theme={theme} user={user} />
+ </I18nextProvider>
+ </Provider>
+ </Router>,
+ )
+
+ expect(screen.getByText(/auth.common.signin/i)).toBeInTheDocument()
+ })
+
+ test('snapshot', () => {
+ const { container } = render(
+ <Router history={history}>
+ <Provider store={store}>
+ <I18nextProvider i18n={i18n}>
+ <Header authenticated={authenticated} theme={theme} user={user} />
+ </I18nextProvider>
+ </Provider>
+ </Router>,
+ )
+
+ expect(container).toMatchSnapshot()
+ })
+})
diff --git a/src/components/__test__/__snapshots__/Header.test.tsx.snap b/src/components/__test__/__snapshots__/Header.test.tsx.snap
new file mode 100644
index 000000000..2ef0c1253
--- /dev/null
+++ b/src/components/__test__/__snapshots__/Header.test.tsx.snap
@@ -0,0 +1,301 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Header snapshot 1`] = `
+<div>
+ <div
+ class="relative bg-white"
+ data-headlessui-state=""
+ >
+ <header
+ class="bg-indigo-600 dark:bg-gray-750 relative overflow-x-clip"
+ >
+ <nav
+ aria-label="Top"
+ class="mx-auto px-4 sm:px-6 lg:px-8"
+ >
+ <div
+ class="w-full py-4 flex items-center justify-between border-b border-indigo-500 dark:border-gray-300 lg:border-none"
+ >
+ <div
+ class="flex items-center"
+ >
+ <a
+ href="/"
+ >
+ <span
+ class="sr-only"
+ >
+ Swetrix
+ </span>
+ <img
+ alt="Swetrix"
+ class="h-10"
+ src="/assets/logo_white.svg"
+ />
+ </a>
+ <div
+ class="hidden ml-10 space-x-1 lg:flex"
+ >
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="https://blog.swetrix.com"
+ rel="noreferrer noopener"
+ target="_blank"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M12.75 19.5v-.75a7.5 7.5 0 00-7.5-7.5H4.5m0-6.75h.75c7.87 0 14.25 6.38 14.25 14.25v.75M6 18.75a.75.75 0 11-1.5 0 .75.75 0 011.5 0z"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ footer.blog
+ </a>
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="https://docs.swetrix.com"
+ rel="noreferrer noopener"
+ target="_blank"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ common.docs
+ </a>
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="/dashboard"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M3.75 3v11.25A2.25 2.25 0 006 16.5h2.25M3.75 3h-1.5m1.5 0h16.5m0 0h1.5m-1.5 0v11.25A2.25 2.25 0 0118 16.5h-2.25m-7.5 0h7.5m-7.5 0l-1 3m8.5-3l1 3m0 0l.5 1.5m-.5-1.5h-9.5m0 0l-.5 1.5m.75-9l3-3 2.148 2.148A12.061 12.061 0 0116.5 7.605"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ common.dashboard
+ </a>
+ </div>
+ </div>
+ <div
+ class="hidden md:flex justify-center items-center flex-wrap ml-1 md:ml-10 space-y-1 sm:space-y-0 space-x-2 md:space-x-4"
+ >
+ <div
+ class="relative ml-3"
+ data-headlessui-state=""
+ >
+ <div>
+ <button
+ aria-expanded="false"
+ aria-haspopup="menu"
+ class="flex justify-center items-center text-base font-medium text-white focus:outline-none hover:text-indigo-100 hover:dark:text-gray-200"
+ data-headlessui-state=""
+ id="headlessui-menu-button-:r7:"
+ type="button"
+ >
+ <span
+ class="sr-only"
+ >
+ header.switchTheme
+ </span>
+ <svg
+ aria-hidden="true"
+ class="h-6 w-6 text-gray-200 hover:text-gray-300 cursor-pointer"
+ fill="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"
+ />
+ </svg>
+ </button>
+ </div>
+ </div>
+ <div
+ class="relative ml-3"
+ data-headlessui-state=""
+ >
+ <div>
+ <button
+ aria-expanded="false"
+ aria-haspopup="menu"
+ class="flex justify-center items-center text-base font-medium text-white focus:outline-none hover:text-indigo-100 hover:dark:text-gray-200"
+ data-headlessui-state=""
+ id="headlessui-menu-button-:r8:"
+ type="button"
+ >
+ <span>
+ common.account
+ </span>
+ <svg
+ aria-hidden="true"
+ class="h-4 w-4 ml-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M19.5 8.25l-7.5 7.5-7.5-7.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ </button>
+ </div>
+ </div>
+ </div>
+ <div
+ class="md:hidden flex justify-center items-center"
+ >
+ <div
+ class="transition-all duration-1000 ease-in-out rotate-180"
+ >
+ <svg
+ aria-hidden="true"
+ class="h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer"
+ fill="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"
+ />
+ </svg>
+ </div>
+ <button
+ aria-expanded="false"
+ class="bg-white dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200 rounded-md p-2 ml-3 inline-flex items-center justify-center text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500"
+ data-headlessui-state=""
+ id="headlessui-popover-button-:r9:"
+ type="button"
+ >
+ <span
+ class="sr-only"
+ >
+ common.openMenu
+ </span>
+ <svg
+ aria-hidden="true"
+ class="h-6 w-6"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ </button>
+ </div>
+ </div>
+ <div
+ class="py-4 flex flex-wrap justify-center space-x-2 lg:hidden"
+ >
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="https://blog.swetrix.com"
+ rel="noreferrer noopener"
+ target="_blank"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M12.75 19.5v-.75a7.5 7.5 0 00-7.5-7.5H4.5m0-6.75h.75c7.87 0 14.25 6.38 14.25 14.25v.75M6 18.75a.75.75 0 11-1.5 0 .75.75 0 011.5 0z"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ footer.blog
+ </a>
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="https://docs.swetrix.com"
+ rel="noreferrer noopener"
+ target="_blank"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ common.docs
+ </a>
+ <a
+ class="flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md"
+ href="/dashboard"
+ >
+ <svg
+ aria-hidden="true"
+ class="w-5 h-5 mr-1"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M3.75 3v11.25A2.25 2.25 0 006 16.5h2.25M3.75 3h-1.5m1.5 0h16.5m0 0h1.5m-1.5 0v11.25A2.25 2.25 0 0118 16.5h-2.25m-7.5 0h7.5m-7.5 0l-1 3m8.5-3l1 3m0 0l.5 1.5m-.5-1.5h-9.5m0 0l-.5 1.5m.75-9l3-3 2.148 2.148A12.061 12.061 0 0116.5 7.605"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ common.dashboard
+ </a>
+ </div>
+ </nav>
+ </header>
+ </div>
+</div>
+`;
diff --git a/src/ui/__test__/__snapshots__/Chart.test.tsx.snap b/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
index 2fee60800..9f4d71dba 100644
--- a/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
+++ b/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
@@ -16,7 +16,7 @@ exports[`Chart component snapshot 1`] = `
>
<defs>
<clippath
- id="bb-6964509615290046-clip"
+ id="bb-8891935502872631-clip"
>
<rect
height="226"
@@ -24,7 +24,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-6964509615290046-clip-xaxis"
+ id="bb-8891935502872631-clip-xaxis"
>
<rect
height="110"
@@ -34,7 +34,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-6964509615290046-clip-yaxis"
+ id="bb-8891935502872631-clip-yaxis"
>
<rect
height="240"
@@ -44,7 +44,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-6964509615290046-clip-grid"
+ id="bb-8891935502872631-clip-grid"
>
<rect
height="226"
@@ -58,7 +58,7 @@ exports[`Chart component snapshot 1`] = `
>
<g
class="bb-grid"
- clip-path="url(http://localhost/#bb-6964509615290046-clip-grid)"
+ clip-path="url(http://localhost/#bb-8891935502872631-clip-grid)"
>
<g
class="bb-xgrid-focus"
@@ -74,7 +74,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-chart"
- clip-path="url(http://localhost/#bb-6964509615290046-clip)"
+ clip-path="url(http://localhost/#bb-8891935502872631-clip)"
>
<g
class="bb-event-rects bb-event-rects-single"
@@ -215,7 +215,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-axis bb-axis-x"
- clip-path="url(http://localhost/#bb-6964509615290046-clip-xaxis)"
+ clip-path="url(http://localhost/#bb-8891935502872631-clip-xaxis)"
transform="translate(0, 226)"
>
<text
@@ -370,7 +370,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-axis bb-axis-y"
- clip-path="url(http://localhost/#bb-6964509615290046-clip-yaxis)"
+ clip-path="url(http://localhost/#bb-8891935502872631-clip-yaxis)"
transform="translate(0, 0)"
>
<text