From 2ef8aee1d0c5fafee6d3c71314bde920b0724b0f Mon Sep 17 00:00:00 2001 From: Klara Ward Date: Tue, 27 Sep 2022 09:57:42 +0200 Subject: [PATCH 1/4] Filter archived repos in GH PR plugin Signed-off-by: Klara Ward --- .changeset/great-ways-switch.md | 8 ++++++++ .../src/api/useGetPullRequestDetails.ts | 1 + .../EntityTeamPullRequestsCard.tsx | 7 +++++++ .../EntityTeamPullRequestsContent.tsx | 7 +++++++ .../src/components/PullRequestCard/PullRequestCard.tsx | 8 +++++++- plugins/github-pull-requests-board/src/utils/functions.ts | 5 +++++ plugins/github-pull-requests-board/src/utils/types.tsx | 3 ++- 7 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .changeset/great-ways-switch.md diff --git a/.changeset/great-ways-switch.md b/.changeset/great-ways-switch.md new file mode 100644 index 0000000000..82ad1d7d26 --- /dev/null +++ b/.changeset/great-ways-switch.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-github-pull-requests-board': patch +--- + +Add a new "Archived" Filter Options to the Github Pull Requests Dashboard. + +When toggling this option on, the dashboard will displays PRs in archived repositories. +These PRs will not be displayed in the default filter. diff --git a/plugins/github-pull-requests-board/src/api/useGetPullRequestDetails.ts b/plugins/github-pull-requests-board/src/api/useGetPullRequestDetails.ts index 3f818c63fc..a276c8fe9d 100644 --- a/plugins/github-pull-requests-board/src/api/useGetPullRequestDetails.ts +++ b/plugins/github-pull-requests-board/src/api/useGetPullRequestDetails.ts @@ -36,6 +36,7 @@ export const useGetPullRequestDetails = () => { owner { login } + isArchived } title url diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.tsx index 95d7745c62..ea605327ab 100644 --- a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.tsx +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.tsx @@ -29,6 +29,7 @@ import { PRCardFormating } from '../../utils/types'; import { shouldDisplayCard } from '../../utils/functions'; import { DraftPrIcon } from '../icons/DraftPr'; import { useUserRepositoriesAndTeam } from '../../hooks/useUserRepositoriesAndTeam'; +import UnarchiveIcon from '@material-ui/icons/Unarchive'; /** @public */ export interface EntityTeamPullRequestsCardProps { @@ -71,6 +72,11 @@ const EntityTeamPullRequestsCard = (props: EntityTeamPullRequestsCardProps) => { value: 'draft', ariaLabel: 'Show draft PRs', }, + { + icon: , + value: 'archivedRepo', + ariaLabel: 'Show archived repos', + }, { icon: , value: 'fullscreen', @@ -127,6 +133,7 @@ const EntityTeamPullRequestsCard = (props: EntityTeamPullRequestsCardProps) => { url={url} reviews={latestReviews.nodes} repositoryName={repository.name} + repositoryIsArchived={repository.isArchived} isDraft={isDraft} /> ), diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.tsx index 2b4c298e83..662e6f4265 100644 --- a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.tsx +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.tsx @@ -27,6 +27,7 @@ import { PRCardFormating } from '../../utils/types'; import { shouldDisplayCard } from '../../utils/functions'; import { DraftPrIcon } from '../icons/DraftPr'; import { useUserRepositoriesAndTeam } from '../../hooks/useUserRepositoriesAndTeam'; +import UnarchiveIcon from '@material-ui/icons/Unarchive'; /** @public */ export interface EntityTeamPullRequestsContentProps { @@ -71,6 +72,11 @@ const EntityTeamPullRequestsContent = ( value: 'draft', ariaLabel: 'Show draft PRs', }, + { + icon: , + value: 'archivedRepo', + ariaLabel: 'Show archived repos', + }, ]} /> @@ -119,6 +125,7 @@ const EntityTeamPullRequestsContent = ( url={url} reviews={latestReviews.nodes} repositoryName={repository.name} + repositoryIsArchived={repository.isArchived} isDraft={isDraft} /> ), diff --git a/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx b/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx index 7e1596f5c2..51ee162555 100644 --- a/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx +++ b/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx @@ -31,6 +31,7 @@ type Props = { url: string; reviews: Reviews; repositoryName: string; + repositoryIsArchived: boolean; isDraft: boolean; }; @@ -43,6 +44,7 @@ const PullRequestCard: FunctionComponent = (props: Props) => { url, reviews, repositoryName, + repositoryIsArchived, isDraft, } = props; @@ -50,7 +52,11 @@ const PullRequestCard: FunctionComponent = (props: Props) => { const commentsReviews = getCommentedReviews(reviews); const changeRequests = getChangeRequests(reviews); - const cardTitle = isDraft ? `🔧 DRAFT - ${title}` : title; + // Resolved in this way to satisfy merge - Author: tylerhekman-procore + // This information should probably be moved into dedicated CardHeader fields + // instead of title prefixes + const cardTitleModifiers = [isDraft && '🔧 DRAFT', repositoryIsArchived && '📁 ARCHIVED'].filter(Boolean); + const cardTitle = cardTitleModifiers.length > 0 ? `(${cardTitleModifiers.join(' | ')}) - ${title}` : title; return ( Date: Thu, 6 Apr 2023 02:53:34 -0700 Subject: [PATCH 2/4] Add card filter icons and tests Signed-off-by: tylerhekman-procore --- .changeset/great-ways-switch.md | 2 +- .../src/components/Card/Card.tsx | 6 + .../src/components/Card/CardHeader.tsx | 24 +- .../EntityTeamPullRequestsCard.test.tsx | 261 ++++++++++++++++++ .../EntityTeamPullRequestsContent.test.tsx | 261 ++++++++++++++++++ .../PullRequestCard/PullRequestCard.tsx | 10 +- 6 files changed, 555 insertions(+), 9 deletions(-) create mode 100644 plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx create mode 100644 plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx diff --git a/.changeset/great-ways-switch.md b/.changeset/great-ways-switch.md index 82ad1d7d26..96469dfade 100644 --- a/.changeset/great-ways-switch.md +++ b/.changeset/great-ways-switch.md @@ -4,5 +4,5 @@ Add a new "Archived" Filter Options to the Github Pull Requests Dashboard. -When toggling this option on, the dashboard will displays PRs in archived repositories. +When toggling this option on, the dashboard will display PRs from archived repositories. These PRs will not be displayed in the default filter. diff --git a/plugins/github-pull-requests-board/src/components/Card/Card.tsx b/plugins/github-pull-requests-board/src/components/Card/Card.tsx index 56e8c6a077..3a47fca696 100644 --- a/plugins/github-pull-requests-board/src/components/Card/Card.tsx +++ b/plugins/github-pull-requests-board/src/components/Card/Card.tsx @@ -25,6 +25,8 @@ type Props = { authorName: string; authorAvatar?: string; repositoryName: string; + isDraft: boolean; + repositoryIsArchived: boolean; }; const Card: FunctionComponent = (props: PropsWithChildren) => { @@ -36,6 +38,8 @@ const Card: FunctionComponent = (props: PropsWithChildren) => { authorName, authorAvatar, repositoryName, + isDraft, + repositoryIsArchived, children, } = props; @@ -51,6 +55,8 @@ const Card: FunctionComponent = (props: PropsWithChildren) => { authorName={authorName} authorAvatar={authorAvatar} repositoryName={repositoryName} + isDraft={isDraft} + repositoryIsArchived={repositoryIsArchived} /> {children} diff --git a/plugins/github-pull-requests-board/src/components/Card/CardHeader.tsx b/plugins/github-pull-requests-board/src/components/Card/CardHeader.tsx index 831423a464..bb6f3e564d 100644 --- a/plugins/github-pull-requests-board/src/components/Card/CardHeader.tsx +++ b/plugins/github-pull-requests-board/src/components/Card/CardHeader.tsx @@ -14,9 +14,11 @@ * limitations under the License. */ import React, { FunctionComponent } from 'react'; -import { Typography, Box } from '@material-ui/core'; +import { Typography, Box, Tooltip } from '@material-ui/core'; import { getElapsedTime } from '../../utils/functions'; import { UserHeader } from '../UserHeader'; +import { DraftPrIcon } from '../icons/DraftPr'; +import UnarchiveIcon from '@material-ui/icons/Unarchive'; type Props = { title: string; @@ -25,6 +27,8 @@ type Props = { authorName: string; authorAvatar?: string; repositoryName: string; + isDraft: boolean; + repositoryIsArchived: boolean; }; const CardHeader: FunctionComponent = (props: Props) => { @@ -35,6 +39,8 @@ const CardHeader: FunctionComponent = (props: Props) => { authorName, authorAvatar, repositoryName, + isDraft, + repositoryIsArchived, } = props; return ( @@ -45,6 +51,22 @@ const CardHeader: FunctionComponent = (props: Props) => { + + {isDraft && ( + + + + + + )} + {repositoryIsArchived && ( + + + + + + )} + {title} diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx new file mode 100644 index 0000000000..29594ea6d4 --- /dev/null +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx @@ -0,0 +1,261 @@ +/* + * Copyright 2023 The Backstage Authors + * + * 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 { EntityTeamPullRequestsCard } from '../EntityTeamPullRequestsCard'; +import { PullRequestsColumn } from '../../utils/types'; +import { render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/react'; + +jest.mock('../../hooks/useUserRepositoriesAndTeam', () => { + return { + useUserRepositoriesAndTeam: () => { + return { + loading: false, + repositories: ['team-login/team-repo'], + teamMembers: ['team-member'], + teamMembersOrganization: 'test-org', + }; + }, + }; +}); + +jest.mock('../../hooks/usePullRequestsByTeam', () => { + const buildPullRequest = ( + prTitle: string, + authorLogin: string, + repoName: string, + isDraft: boolean, + isArchived: boolean, + ) => { + return { + id: 'id', + title: prTitle, + url: 'url', + lastEditedAt: 'last-edited-at', + latestReviews: { + nodes: [], + }, + mergeable: true, + state: 'state', + reviewDecision: null, + createdAt: 'created-at', + repository: { + name: repoName, + owner: { + login: 'team-login', + }, + isArchived: isArchived, + }, + isDraft: isDraft, + author: { + login: authorLogin, + avatarUrl: 'avatar-url', + id: 'id', + email: 'email', + name: 'name', + }, + }; + }; + + const pullRequests: PullRequestsColumn[] = [ + { + title: 'column', + content: [ + buildPullRequest( + 'non-team-non-draft-non-archive', + 'non-team-member', + 'team-repo', + false, + false, + ), + buildPullRequest( + 'non-team-non-draft-is-archive', + 'non-team-member', + 'team-repo', + false, + true, + ), + buildPullRequest( + 'non-team-is-draft-non-archive', + 'non-team-member', + 'team-repo', + true, + false, + ), + buildPullRequest( + 'non-team-is-draft-is-archive', + 'non-team-member', + 'team-repo', + true, + true, + ), + buildPullRequest( + 'is-team-non-draft-non-archive', + 'team-member', + 'non-team-repo', + false, + false, + ), + buildPullRequest( + 'is-team-non-draft-is-archive', + 'team-member', + 'non-team-repo', + false, + true, + ), + buildPullRequest( + 'is-team-is-draft-non-archive', + 'team-member', + 'non-team-repo', + true, + false, + ), + buildPullRequest( + 'is-team-is-draft-is-archive', + 'team-member', + 'non-team-repo', + true, + true, + ), + ], + }, + ]; + + return { + usePullRequestsByTeam: () => { + return { + loading: false, + pullRequests: pullRequests, + refreshPullRequest: () => {}, + }; + }, + }; +}); + +describe('EntityTeamPullRequestsCard', () => { + it('should render', async () => { + await render(); + }); + + describe('non-team PRs', () => { + describe('non-draft PRs', () => { + it('should show non-team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, queryAllByTitle } = await render( + , + ); + expect(getByText('non-team-non-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + + it('should show non-team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('non-team-non-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + }); + + describe('draft PRs', () => { + it('should show draft non-team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + expect(getByText('non-team-is-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + + it('should show draft non-team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('non-team-is-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + }); + }); + + describe('team PRs', () => { + describe('non-draft PRs', () => { + it('should show team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + expect(getByText('is-team-non-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + + it('should show team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('is-team-non-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + }); + + describe('draft PRs', () => { + it('should show draft team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + expect(getByText('is-team-is-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + + it('should show draft team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('is-team-is-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + }); + }); +}); diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx new file mode 100644 index 0000000000..a1bd051217 --- /dev/null +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx @@ -0,0 +1,261 @@ +/* + * Copyright 2023 The Backstage Authors + * + * 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 { EntityTeamPullRequestsContent } from '../EntityTeamPullRequestsContent'; +import { PullRequestsColumn } from '../../utils/types'; +import { render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/react'; + +jest.mock('../../hooks/useUserRepositoriesAndTeam', () => { + return { + useUserRepositoriesAndTeam: () => { + return { + loading: false, + repositories: ['team-login/team-repo'], + teamMembers: ['team-member'], + teamMembersOrganization: 'test-org', + }; + }, + }; +}); + +jest.mock('../../hooks/usePullRequestsByTeam', () => { + const buildPullRequest = ( + prTitle: string, + authorLogin: string, + repoName: string, + isDraft: boolean, + isArchived: boolean, + ) => { + return { + id: 'id', + title: prTitle, + url: 'url', + lastEditedAt: 'last-edited-at', + latestReviews: { + nodes: [], + }, + mergeable: true, + state: 'state', + reviewDecision: null, + createdAt: 'created-at', + repository: { + name: repoName, + owner: { + login: 'team-login', + }, + isArchived: isArchived, + }, + isDraft: isDraft, + author: { + login: authorLogin, + avatarUrl: 'avatar-url', + id: 'id', + email: 'email', + name: 'name', + }, + }; + }; + + const pullRequests: PullRequestsColumn[] = [ + { + title: 'column', + content: [ + buildPullRequest( + 'non-team-non-draft-non-archive', + 'non-team-member', + 'team-repo', + false, + false, + ), + buildPullRequest( + 'non-team-non-draft-is-archive', + 'non-team-member', + 'team-repo', + false, + true, + ), + buildPullRequest( + 'non-team-is-draft-non-archive', + 'non-team-member', + 'team-repo', + true, + false, + ), + buildPullRequest( + 'non-team-is-draft-is-archive', + 'non-team-member', + 'team-repo', + true, + true, + ), + buildPullRequest( + 'is-team-non-draft-non-archive', + 'team-member', + 'non-team-repo', + false, + false, + ), + buildPullRequest( + 'is-team-non-draft-is-archive', + 'team-member', + 'non-team-repo', + false, + true, + ), + buildPullRequest( + 'is-team-is-draft-non-archive', + 'team-member', + 'non-team-repo', + true, + false, + ), + buildPullRequest( + 'is-team-is-draft-is-archive', + 'team-member', + 'non-team-repo', + true, + true, + ), + ], + }, + ]; + + return { + usePullRequestsByTeam: () => { + return { + loading: false, + pullRequests: pullRequests, + refreshPullRequest: () => {}, + }; + }, + }; +}); + +describe('EntityTeamPullRequestsContent', () => { + it('should render', async () => { + await render(); + }); + + describe('non-team PRs', () => { + describe('non-draft PRs', () => { + it('should show non-team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, queryAllByTitle } = await render( + , + ); + expect(getByText('non-team-non-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + + it('should show non-team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('non-team-non-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + }); + + describe('draft PRs', () => { + it('should show draft non-team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + expect(getByText('non-team-is-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + + it('should show draft non-team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('non-team-is-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + }); + }); + + describe('team PRs', () => { + describe('non-draft PRs', () => { + it('should show team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + expect(getByText('is-team-non-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + + it('should show team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('is-team-non-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(0); + }); + }); + + describe('draft PRs', () => { + it('should show draft team PRs for un-archived repos when archived option is not checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + expect(getByText('is-team-is-draft-non-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(0); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + + it('should show draft team PRs for archived repos when archived option is checked', async () => { + const { getByText, getAllByText, getByTitle, queryAllByTitle } = + await render(); + const teamToggle = getByTitle('Show PRs from your team'); + fireEvent.click(teamToggle); + const draftToggle = getByTitle('Show draft PRs'); + fireEvent.click(draftToggle); + const archiveToggle = getByTitle('Show archived repos'); + fireEvent.click(archiveToggle); + expect(getByText('is-team-is-draft-is-archive')).toBeInTheDocument(); + expect(getAllByText('non-team-repo')).toHaveLength(1); + expect(queryAllByTitle('Repository is archived')).toHaveLength(1); + expect(queryAllByTitle('Draft PR')).toHaveLength(1); + }); + }); + }); +}); diff --git a/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx b/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx index 51ee162555..fa3ce4eb9c 100644 --- a/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx +++ b/plugins/github-pull-requests-board/src/components/PullRequestCard/PullRequestCard.tsx @@ -52,21 +52,17 @@ const PullRequestCard: FunctionComponent = (props: Props) => { const commentsReviews = getCommentedReviews(reviews); const changeRequests = getChangeRequests(reviews); - // Resolved in this way to satisfy merge - Author: tylerhekman-procore - // This information should probably be moved into dedicated CardHeader fields - // instead of title prefixes - const cardTitleModifiers = [isDraft && '🔧 DRAFT', repositoryIsArchived && '📁 ARCHIVED'].filter(Boolean); - const cardTitle = cardTitleModifiers.length > 0 ? `(${cardTitleModifiers.join(' | ')}) - ${title}` : title; - return ( {!!approvedReviews.length && ( Date: Fri, 7 Apr 2023 00:09:43 -0700 Subject: [PATCH 3/4] Remove render tests with no assertions Signed-off-by: tylerhekman-procore --- .../EntityTeamPullRequestsCard.test.tsx | 4 ---- .../EntityTeamPullRequestsContent.test.tsx | 4 ---- 2 files changed, 8 deletions(-) diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx index 29594ea6d4..4965e1fbba 100644 --- a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsCard/EntityTeamPullRequestsCard.test.tsx @@ -146,10 +146,6 @@ jest.mock('../../hooks/usePullRequestsByTeam', () => { }); describe('EntityTeamPullRequestsCard', () => { - it('should render', async () => { - await render(); - }); - describe('non-team PRs', () => { describe('non-draft PRs', () => { it('should show non-team PRs for un-archived repos when archived option is not checked', async () => { diff --git a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx index a1bd051217..58faa7fb70 100644 --- a/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx +++ b/plugins/github-pull-requests-board/src/components/EntityTeamPullRequestsContent/EntityTeamPullRequestsContent.test.tsx @@ -146,10 +146,6 @@ jest.mock('../../hooks/usePullRequestsByTeam', () => { }); describe('EntityTeamPullRequestsContent', () => { - it('should render', async () => { - await render(); - }); - describe('non-team PRs', () => { describe('non-draft PRs', () => { it('should show non-team PRs for un-archived repos when archived option is not checked', async () => { From f796f0e0a00c04b3e63d4e24deb5598e40685473 Mon Sep 17 00:00:00 2001 From: tylerhekman-procore Date: Fri, 7 Apr 2023 00:28:28 -0700 Subject: [PATCH 4/4] Prettier write Signed-off-by: tylerhekman-procore --- plugins/github-pull-requests-board/src/utils/functions.ts | 2 +- plugins/github-pull-requests-board/src/utils/types.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/github-pull-requests-board/src/utils/functions.ts b/plugins/github-pull-requests-board/src/utils/functions.ts index c68f24f116..777db81aff 100644 --- a/plugins/github-pull-requests-board/src/utils/functions.ts +++ b/plugins/github-pull-requests-board/src/utils/functions.ts @@ -139,7 +139,7 @@ export const shouldDisplayCard = ( // hide PRs from archived repositories unless "archivedRepo" filter is toggled if (infoCardFormat.includes('archivedRepo') !== repository.isArchived) { - return false + return false; } // when "team" filter is toggled on, only shows PR from team members diff --git a/plugins/github-pull-requests-board/src/utils/types.tsx b/plugins/github-pull-requests-board/src/utils/types.tsx index d9e15237e5..4c80052731 100644 --- a/plugins/github-pull-requests-board/src/utils/types.tsx +++ b/plugins/github-pull-requests-board/src/utils/types.tsx @@ -100,7 +100,12 @@ export type PullRequestsColumn = { content: PullRequests; }; -export type PRCardFormating = 'compacted' | 'fullscreen' | 'draft' | 'team' | 'archivedRepo'; +export type PRCardFormating = + | 'compacted' + | 'fullscreen' + | 'draft' + | 'team' + | 'archivedRepo'; export type ReviewDecision = 'IN_PROGRESS' | 'APPROVED' | 'REVIEW_REQUIRED';