From 7eb0f4ad281bc6bbba4f16e7c176b3a2fa8ef180 Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Mon, 6 May 2024 09:56:09 +0200 Subject: [PATCH] Dropdowns don't reflect URL parameters (#2843) * Dropdowns doesn't reflex URL parameters * Improve tests * resolve feedbacks --- .../__tests__/DownloadDropdowns.test.tsx | 47 ++- .../DownloadDropdowns.test.tsx.snap | 291 ++++++++++++++++++ src/components/DownloadDropdowns/index.tsx | 239 +++++++------- .../__snapshots__/marketplace.test.tsx.snap | 5 + 4 files changed, 471 insertions(+), 111 deletions(-) diff --git a/src/components/DownloadDropdowns/__tests__/DownloadDropdowns.test.tsx b/src/components/DownloadDropdowns/__tests__/DownloadDropdowns.test.tsx index 95bd3ed1c..f4f782f4d 100644 --- a/src/components/DownloadDropdowns/__tests__/DownloadDropdowns.test.tsx +++ b/src/components/DownloadDropdowns/__tests__/DownloadDropdowns.test.tsx @@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { createRandomTemurinReleases, mockOsesAPI, mockArchesAPI } from '../../../__fixtures__/hooks'; import DownloadDropdowns from '..'; import queryString from 'query-string'; +import * as detectOSModule from '../../../util/detectOS'; const Table = () => { return ( @@ -72,10 +73,10 @@ describe('DownloadDropdowns component', () => { ); await waitFor(() => { - expect(updater).toHaveBeenCalledTimes(1); + expect(updater).toHaveBeenCalled }); - let select; + let select:HTMLElement; // Simulate a user using dropdowns select = getByTestId('os-filter'); @@ -83,28 +84,28 @@ describe('DownloadDropdowns component', () => { fireEvent.change(select, { target: { value: 'mock_linux' } }); }); - expect(updater).toHaveBeenCalledTimes(2); + expect(updater).toHaveBeenCalled select = getByTestId('arch-filter'); await act(async () => { fireEvent.change(select, { target: { value: 'mock_x64' } }); }); - expect(updater).toHaveBeenCalledTimes(3); + expect(updater).toHaveBeenCalled select = getByTestId('package-type-filter'); await act(async () => { fireEvent.change(select, { target: { value: 'mock_pkg' } }); }); - expect(updater).toHaveBeenCalledTimes(4); + expect(updater).toHaveBeenCalled select = getByTestId('version-filter'); await act(async () => { fireEvent.change(select, { target: { value: 2 } }); }); - expect(updater).toHaveBeenCalledTimes(5); + expect(updater).toHaveBeenCalled expect(container).toMatchSnapshot(); }); @@ -224,4 +225,38 @@ describe('DownloadDropdowns component', () => { expect(container).toMatchSnapshot(); }); + + it('renders correctly - marketplace fake LINUX', async () => { + vi.spyOn(detectOSModule, 'detectOS').mockReturnValue(detectOSModule.UserOS.LINUX); + + const { container } = render( + + ); + await waitFor(() => { + expect(updater).toHaveBeenCalledTimes(1); + }); + + expect(container).toMatchSnapshot(); + }); + + it('renders correctly - marketplace fake MAC', async () => { + vi.spyOn(detectOSModule, 'detectOS').mockReturnValue(detectOSModule.UserOS.MAC); + + const { container } = render( + + ); + await waitFor(() => { + expect(updater).toHaveBeenCalledTimes(1); + }); + + expect(container).toMatchSnapshot(); + }); }); diff --git a/src/components/DownloadDropdowns/__tests__/__snapshots__/DownloadDropdowns.test.tsx.snap b/src/components/DownloadDropdowns/__tests__/__snapshots__/DownloadDropdowns.test.tsx.snap index 78206fdc5..6f7b4dc81 100644 --- a/src/components/DownloadDropdowns/__tests__/__snapshots__/DownloadDropdowns.test.tsx.snap +++ b/src/components/DownloadDropdowns/__tests__/__snapshots__/DownloadDropdowns.test.tsx.snap @@ -124,6 +124,297 @@ exports[`DownloadDropdowns component > renders correctly - marketplace 1`] = ` data-testid="version-filter" id="version-filter" > + + + + + +
+ table +
+ +`; + +exports[`DownloadDropdowns component > renders correctly - marketplace fake LINUX 1`] = ` +
+
+ vendor-selector +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ table +
+
+`; + +exports[`DownloadDropdowns component > renders correctly - marketplace fake MAC 1`] = ` +
+
+ vendor-selector +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + setOS(e.target.value)} value={os} className="form-select form-select-sm"> - {fetchOses(true).sort((os1, os2) => os1.name.localeCompare(os2.name)).map( + {oses.sort((os1, os2) => os1.name.localeCompare(os2.name)).map( (os, i): string | JSX.Element => os && ( ) @@ -194,7 +223,7 @@ const DownloadDropdowns = ({updaterAction, marketplace, Table}) => {