From 13906def32e628f2e640cc337e38c6af082b4daa Mon Sep 17 00:00:00 2001 From: Erik Engervall Date: Wed, 21 Apr 2021 20:53:41 +0200 Subject: [PATCH] Improve test coverage for VersioningStrategy & add VERSIONING_STRATEGIES to constants.test.ts Signed-off-by: Erik Engervall --- .../VersioningStrategy.test.tsx | 35 +++++++++++++------ .../src/constants/constants.test.ts | 4 +++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/plugins/github-release-manager/src/cards/RepoDetailsForm/VersioningStrategy.test.tsx b/plugins/github-release-manager/src/cards/RepoDetailsForm/VersioningStrategy.test.tsx index 9790fba23a..bc27ea4ce1 100644 --- a/plugins/github-release-manager/src/cards/RepoDetailsForm/VersioningStrategy.test.tsx +++ b/plugins/github-release-manager/src/cards/RepoDetailsForm/VersioningStrategy.test.tsx @@ -15,22 +15,23 @@ */ import React from 'react'; -import { render } from '@testing-library/react'; +import { render, fireEvent } from '@testing-library/react'; import { - mockCalverProject, + mockSemverProject, mockSearchCalver, } from '../../test-helpers/test-helpers'; -import { TEST_IDS } from '../../test-helpers/test-ids'; + +const mockNavigate = jest.fn(); jest.mock('react-router', () => ({ - useNavigate: jest.fn(), + useNavigate: () => mockNavigate, useLocation: jest.fn(() => ({ search: mockSearchCalver, })), })); jest.mock('../../contexts/ProjectContext', () => ({ - useProjectContext: jest.fn(() => mockCalverProject), + useProjectContext: jest.fn(() => mockSemverProject), })); import { VersioningStrategy } from './VersioningStrategy'; @@ -38,11 +39,25 @@ import { VersioningStrategy } from './VersioningStrategy'; describe('Repo', () => { beforeEach(jest.clearAllMocks); - it('should render radio group', async () => { - const { getByTestId } = render(); + it('should render radio group with default values and handle changes', async () => { + const { getByLabelText } = render(); - expect( - getByTestId(TEST_IDS.form.versioningStrategy.radioGroup), - ).toBeInTheDocument(); + const radio1 = getByLabelText('Semantic versioning'); + const radio2 = getByLabelText('Calendar versioning'); + + expect(radio1).toBeChecked(); + expect(radio2).not.toBeChecked(); + + fireEvent.click(radio2); + expect(mockNavigate.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "?versioningStrategy=calver&owner=mock_owner&repo=mock_repo", + Object { + "replace": true, + }, + ], + ] + `); }); }); diff --git a/plugins/github-release-manager/src/constants/constants.test.ts b/plugins/github-release-manager/src/constants/constants.test.ts index 3441221821..cf2b7d7548 100644 --- a/plugins/github-release-manager/src/constants/constants.test.ts +++ b/plugins/github-release-manager/src/constants/constants.test.ts @@ -30,6 +30,10 @@ describe('constants', () => { "minor": "minor", "patch": "patch", }, + "VERSIONING_STRATEGIES": Object { + "calver": "calver", + "semver": "semver", + }, } `); });