diff --git a/webapp/src/components/github_assignee_selector/github_assignee_selector.jsx b/webapp/src/components/github_assignee_selector/github_assignee_selector.jsx index 68a806081..0b8b741cb 100644 --- a/webapp/src/components/github_assignee_selector/github_assignee_selector.jsx +++ b/webapp/src/components/github_assignee_selector/github_assignee_selector.jsx @@ -15,6 +15,7 @@ export default class GithubAssigneeSelector extends PureComponent { actions: PropTypes.shape({ getAssigneeOptions: PropTypes.func.isRequired, }).isRequired, + isDisabled: PropTypes.bool, }; loadAssignees = async () => { diff --git a/webapp/src/components/github_label_selector/github_label_selector.tsx b/webapp/src/components/github_label_selector/github_label_selector.tsx index 6be634dfa..f8cf39000 100644 --- a/webapp/src/components/github_label_selector/github_label_selector.tsx +++ b/webapp/src/components/github_label_selector/github_label_selector.tsx @@ -14,6 +14,7 @@ type Props = GitHubLabelSelectorDispatchProps & { theme: Theme; selectedLabels: string[]; onChange: (selection: string[]) => void; + isDisabled?: boolean; }; type Option = { diff --git a/webapp/src/components/github_milestone_selector/github_milestone_selector.jsx b/webapp/src/components/github_milestone_selector/github_milestone_selector.jsx index 444e7f6db..8d06b701d 100644 --- a/webapp/src/components/github_milestone_selector/github_milestone_selector.jsx +++ b/webapp/src/components/github_milestone_selector/github_milestone_selector.jsx @@ -15,6 +15,7 @@ export default class GithubMilestoneSelector extends PureComponent { actions: PropTypes.shape({ getMilestoneOptions: PropTypes.func.isRequired, }).isRequired, + isDisabled: PropTypes.bool, }; loadMilestones = async () => { diff --git a/webapp/src/components/issue_attribute_selector.tsx b/webapp/src/components/issue_attribute_selector.tsx index 68079e925..6bee539c7 100644 --- a/webapp/src/components/issue_attribute_selector.tsx +++ b/webapp/src/components/issue_attribute_selector.tsx @@ -23,6 +23,7 @@ export type Props = { onChange: (selection: ReactSelectOption | ReactSelectOption[] | null) => void; loadOptions: () => Promise; selection: ReactSelectOption | string[] | null; + isDisabled?: boolean; }; type State = { diff --git a/webapp/src/components/modals/create_issue/create_issue.jsx b/webapp/src/components/modals/create_issue/create_issue.jsx index 502408585..ebbd1522f 100644 --- a/webapp/src/components/modals/create_issue/create_issue.jsx +++ b/webapp/src/components/modals/create_issue/create_issue.jsx @@ -120,31 +120,33 @@ export default class CreateIssueModal extends PureComponent { this.setState({issueDescription}); renderIssueAttributeSelectors = () => { - if (!this.state.repo || (this.state.repo.permissions && !this.state.repo.permissions.push)) { - return null; - } + const hasPushPermission = Boolean(this.state.repo && (!this.state.repo.permissions || this.state.repo.permissions.push)); + const repoName = this.state.repo ? this.state.repo.name : ''; return ( <> ); diff --git a/webapp/src/components/modals/create_issue/create_issue.test.jsx b/webapp/src/components/modals/create_issue/create_issue.test.jsx index 575de573a..3ca69582c 100644 --- a/webapp/src/components/modals/create_issue/create_issue.test.jsx +++ b/webapp/src/components/modals/create_issue/create_issue.test.jsx @@ -36,17 +36,38 @@ jest.mock('@/components/github_repo_selector', () => ({ jest.mock('@/components/github_label_selector', () => ({ __esModule: true, - default: () =>
{'Label Selector'}
, + default: ({isDisabled}) => ( +
+ {'Label Selector'} +
+ ), })); jest.mock('@/components/github_assignee_selector', () => ({ __esModule: true, - default: () =>
{'Assignee Selector'}
, + default: ({isDisabled}) => ( +
+ {'Assignee Selector'} +
+ ), })); jest.mock('@/components/github_milestone_selector', () => ({ __esModule: true, - default: () =>
{'Milestone Selector'}
, + default: ({isDisabled}) => ( +
+ {'Milestone Selector'} +
+ ), })); const defaultProps = { @@ -177,24 +198,28 @@ test('CreateIssueModal should set issueDescription state when post prop is updat expect(descriptionInput).toHaveValue('test post'); }); -test('CreateIssueModal should not display attribute selectors when repo does not have push permissions', async () => { +test('CreateIssueModal should disable attribute selectors when repo does not have push permissions or no repo is selected', async () => { render(); + expect(screen.getByTestId('github-label-selector')).toHaveAttribute('data-disabled', 'true'); + expect(screen.getByTestId('github-assignee-selector')).toHaveAttribute('data-disabled', 'true'); + expect(screen.getByTestId('github-milestone-selector')).toHaveAttribute('data-disabled', 'true'); + const selectNoPushRepoButton = screen.getByText('Select No Push Repo'); await userEvent.click(selectNoPushRepoButton); - expect(screen.queryByTestId('github-label-selector')).not.toBeInTheDocument(); - expect(screen.queryByTestId('github-assignee-selector')).not.toBeInTheDocument(); - expect(screen.queryByTestId('github-milestone-selector')).not.toBeInTheDocument(); + expect(screen.getByTestId('github-label-selector')).toHaveAttribute('data-disabled', 'true'); + expect(screen.getByTestId('github-assignee-selector')).toHaveAttribute('data-disabled', 'true'); + expect(screen.getByTestId('github-milestone-selector')).toHaveAttribute('data-disabled', 'true'); }); -test('CreateIssueModal should display attribute selectors when repo has push permissions', async () => { +test('CreateIssueModal should enable attribute selectors when repo has push permissions', async () => { render(); const selectRepoButton = screen.getByText('Select Repo'); await userEvent.click(selectRepoButton); - expect(screen.getByTestId('github-label-selector')).toBeInTheDocument(); - expect(screen.getByTestId('github-assignee-selector')).toBeInTheDocument(); - expect(screen.getByTestId('github-milestone-selector')).toBeInTheDocument(); + expect(screen.getByTestId('github-label-selector')).toHaveAttribute('data-disabled', 'false'); + expect(screen.getByTestId('github-assignee-selector')).toHaveAttribute('data-disabled', 'false'); + expect(screen.getByTestId('github-milestone-selector')).toHaveAttribute('data-disabled', 'false'); });