github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/components/Footer.spec.tsx (about) 1 import React from 'react'; 2 import { render } from '@testing-library/react'; 3 import { Maybe } from 'true-myth'; 4 import * as buildInfo from '../util/buildInfo'; 5 import Footer from './Footer'; 6 7 const mockDate = new Date('2021-12-21T12:44:01.741Z'); 8 9 jest.mock('../util/buildInfo.ts'); 10 const actual = jest.requireActual('../util/buildInfo.ts'); 11 12 const basicBuildInfo = { 13 goos: '', 14 goarch: '', 15 goVersion: '', 16 version: '', 17 time: '', 18 gitDirty: '', 19 gitSHA: '', 20 jsVersion: '', 21 useEmbeddedAssets: '', 22 }; 23 24 describe('Footer', function () { 25 beforeEach(() => { 26 jest.useFakeTimers().setSystemTime(mockDate.getTime()); 27 }); 28 afterEach(() => { 29 jest.restoreAllMocks(); 30 }); 31 32 describe('trademark', function () { 33 beforeEach(() => { 34 const buildInfoMock = jest.spyOn(buildInfo, 'buildInfo'); 35 const latestVersionMock = jest.spyOn(buildInfo, 'latestVersionInfo'); 36 37 buildInfoMock.mockImplementation(() => ({ ...basicBuildInfo })); 38 latestVersionMock.mockImplementation(() => actual.latestVersionInfo()); 39 }); 40 41 it('shows current year correctly', function () { 42 const { queryByText } = render(<Footer />); 43 44 expect(queryByText(/Pyroscope 2020 – 2021/i)).toBeInTheDocument(); 45 }); 46 }); 47 48 describe('latest version', function () { 49 test.each([ 50 // smaller 51 ['0.0.1', '1.0.0', true], 52 ['v0.0.1', 'v1.0.0', true], 53 ['v9.0.1', 'v10.0.0', true], 54 55 // same version 56 ['1.0.0', '1.0.0', false], 57 ['v1.0.0', 'v1.0.0', false], 58 // current is bigger (bug with the server most likely) 59 ['1.0.0', '0.0.1', false], 60 ['v1.0.0', 'v0.0.1', false], 61 ['v10.0.1', 'v1.0.0', false], 62 ])( 63 `currVer (%s), latestVer(%s) should show update available? '%s'`, 64 (v1, v2, display) => { 65 const buildInfoMock = jest.spyOn(buildInfo, 'buildInfo'); 66 const latestVersionMock = jest.spyOn(buildInfo, 'latestVersionInfo'); 67 68 buildInfoMock.mockImplementation(() => ({ 69 ...basicBuildInfo, 70 version: v1, 71 })); 72 73 latestVersionMock.mockImplementation(() => 74 Maybe.of({ latest_version: v2 }) 75 ); 76 77 const { queryByText } = render(<Footer />); 78 79 if (display) { 80 expect(queryByText(/Newer Version Available/i)).toBeInTheDocument(); 81 } else { 82 expect( 83 queryByText(/Newer Version Available/i) 84 ).not.toBeInTheDocument(); 85 } 86 } 87 ); 88 89 it('does not crash when version is not available', () => { 90 const buildInfoMock = jest.spyOn(buildInfo, 'buildInfo'); 91 const latestVersionMock = jest.spyOn(buildInfo, 'latestVersionInfo'); 92 93 buildInfoMock.mockImplementation(() => ({ ...basicBuildInfo })); 94 latestVersionMock.mockImplementation(() => Maybe.nothing()); 95 96 const { queryByRole } = render(<Footer />); 97 expect(queryByRole('contentinfo')).toBeInTheDocument(); 98 }); 99 }); 100 });