From ee982f591ebbc1b2b6007b7c9f8e5a4939b66134 Mon Sep 17 00:00:00 2001 From: Erik Engervall Date: Sun, 18 Apr 2021 11:12:35 +0200 Subject: [PATCH] Add tests for useVersioningStrategyMatchesRepoTags Signed-off-by: Erik Engervall --- ...VersioningStrategyMatchesRepoTags.test.tsx | 92 +++++++++++++++++++ .../useVersioningStrategyMatchesRepoTags.ts | 4 +- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.test.tsx diff --git a/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.test.tsx b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.test.tsx new file mode 100644 index 0000000000..0a7ba54794 --- /dev/null +++ b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.test.tsx @@ -0,0 +1,92 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render } from '@testing-library/react'; + +import { + mockReleaseVersionCalver, + mockReleaseVersionSemver, + mockSemverProject, +} from '../test-helpers/test-helpers'; +import { Project } from '../contexts/ProjectContext'; +import { useVersioningStrategyMatchesRepoTags } from './useVersioningStrategyMatchesRepoTags'; + +const TEST_ID = 'grm--use-versioning-strategy-matches-repo-tags'; +const MATCH = 'match ✅'; +const NO_MATCH = 'NO match ❌'; + +const MockComponent = ({ + project, + latestReleaseTagName, + repositoryName, +}: { + project: Project; + latestReleaseTagName?: string; + repositoryName?: string; +}) => { + const { versioningStrategyMatches } = useVersioningStrategyMatchesRepoTags({ + project, + latestReleaseTagName, + repositoryName, + }); + + return ( +
+ {versioningStrategyMatches ? MATCH : NO_MATCH} +
+ ); +}; + +describe('useVersioningStrategyMatchesRepoTags', () => { + it('should NOT match for missing latestReleaseTagName & repositoryName', () => { + const { getByTestId } = render( + , + ); + + const result = getByTestId(TEST_ID).innerHTML; + + expect(result).toEqual(NO_MATCH); + }); + + it('should NOT match for mismatching versioning strategies', () => { + const { getByTestId } = render( + , + ); + + const result = getByTestId(TEST_ID).innerHTML; + + expect(result).toEqual(NO_MATCH); + }); + + it('should match for matching repositories with same versioning strategy', () => { + const { getByTestId } = render( + , + ); + + const result = getByTestId(TEST_ID).innerHTML; + + expect(result).toEqual(MATCH); + }); +}); diff --git a/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts index 91f4501585..b634ba980a 100644 --- a/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts +++ b/plugins/github-release-manager/src/helpers/useVersioningStrategyMatchesRepoTags.ts @@ -20,12 +20,12 @@ import { Project } from '../contexts/ProjectContext'; import { getTagParts } from './tagParts/getTagParts'; export const useVersioningStrategyMatchesRepoTags = ({ - latestReleaseTagName, project, + latestReleaseTagName, repositoryName, }: { - latestReleaseTagName?: string; project: Project; + latestReleaseTagName?: string; repositoryName?: string; }) => { const [versioningStrategyMatches, setVersioningStrategyMatches] = useState(