Commit 469676b5 authored by Tom Quirk's avatar Tom Quirk

Address reviewer feedback

- expand test coverage in new branch form spec
- fix type
parent 0e18d47c
...@@ -36,7 +36,11 @@ export default { ...@@ -36,7 +36,11 @@ export default {
ProjectDropdown, ProjectDropdown,
SourceBranchDropdown, SourceBranchDropdown,
}, },
inject: ['initialBranchName'], inject: {
initialBranchName: {
default: '',
},
},
data() { data() {
return { return {
selectedProject: null, selectedProject: null,
...@@ -56,8 +60,11 @@ export default { ...@@ -56,8 +60,11 @@ export default {
showAlert() { showAlert() {
return Boolean(this.alertParams?.message); return Boolean(this.alertParams?.message);
}, },
isBranchNameValid() {
return (this.branchName ?? '').trim().length > 0;
},
disableSubmitButton() { disableSubmitButton() {
return !(this.selectedProject && this.selectedSourceBranchName && this.branchName); return !(this.selectedProject && this.selectedSourceBranchName && this.isBranchNameValid);
}, },
}, },
methods: { methods: {
......
...@@ -26,7 +26,7 @@ RSpec.describe 'Create GitLab branches from Jira', :js do ...@@ -26,7 +26,7 @@ RSpec.describe 'Create GitLab branches from Jira', :js do
visit new_jira_connect_branch_path(issue_key: 'ACME-123', issue_summary: 'My issue !@#$% title') visit new_jira_connect_branch_path(issue_key: 'ACME-123', issue_summary: 'My issue !@#$% title')
expect(page).to have_button('Create branch', disabled: true) expect(page).to have_button('Create branch', disabled: true)
# intiially, branch field should be hidden. # initially, branch field should be hidden.
expect(page).not_to have_field('Branch name') expect(page).not_to have_field('Branch name')
# Select project1 # Select project1
......
...@@ -54,8 +54,8 @@ describe('NewBranchForm', () => { ...@@ -54,8 +54,8 @@ describe('NewBranchForm', () => {
const completeForm = async () => { const completeForm = async () => {
await findProjectDropdown().vm.$emit('change', mockProject); await findProjectDropdown().vm.$emit('change', mockProject);
await findInput().vm.$emit('input', 'cool-branch-name');
await findSourceBranchDropdown().vm.$emit('change', 'source-branch'); await findSourceBranchDropdown().vm.$emit('change', 'source-branch');
await findInput().vm.$emit('input', 'cool-branch-name');
}; };
function createMockApolloProvider({ function createMockApolloProvider({
...@@ -84,23 +84,40 @@ describe('NewBranchForm', () => { ...@@ -84,23 +84,40 @@ describe('NewBranchForm', () => {
describe('when selecting items from dropdowns', () => { describe('when selecting items from dropdowns', () => {
describe('when no project selected', () => { describe('when no project selected', () => {
it('hides source branch selection and branch name input', () => { beforeEach(() => {
createComponent(); createComponent();
});
it('hides source branch selection and branch name input', () => {
expect(findSourceBranchDropdown().exists()).toBe(false); expect(findSourceBranchDropdown().exists()).toBe(false);
expect(findInput().exists()).toBe(false); expect(findInput().exists()).toBe(false);
}); });
it('disables the submit button', () => {
expect(findButton().props('disabled')).toBe(true);
});
}); });
describe('when a valid project is selected', () => { describe('when a valid project is selected', () => {
it('sets the `selectedProject` prop for ProjectDropdown and SourceBranchDropdown', async () => { describe("when a source branch isn't selected", () => {
createComponent(); beforeEach(async () => {
createComponent();
await findProjectDropdown().vm.$emit('change', mockProject);
});
const projectDropdown = findProjectDropdown(); it('sets the `selectedProject` prop for ProjectDropdown and SourceBranchDropdown', () => {
await projectDropdown.vm.$emit('change', mockProject); expect(findProjectDropdown().props('selectedProject')).toEqual(mockProject);
expect(findSourceBranchDropdown().exists()).toBe(true);
expect(findSourceBranchDropdown().props('selectedProject')).toEqual(mockProject);
});
it('disables the submit button', () => {
expect(findButton().props('disabled')).toBe(true);
});
expect(projectDropdown.props('selectedProject')).toEqual(mockProject); it('renders branch input field', () => {
expect(findSourceBranchDropdown().props('selectedProject')).toEqual(mockProject); expect(findInput().exists()).toBe(true);
});
}); });
describe('when `initialBranchName` is provided', () => { describe('when `initialBranchName` is provided', () => {
...@@ -125,6 +142,22 @@ describe('NewBranchForm', () => { ...@@ -125,6 +142,22 @@ describe('NewBranchForm', () => {
expect(sourceBranchDropdown.props('selectedBranchName')).toBe(mockBranchName); expect(sourceBranchDropdown.props('selectedBranchName')).toBe(mockBranchName);
}); });
describe.each`
branchName | submitButtonDisabled
${undefined} | ${true}
${''} | ${true}
${' '} | ${true}
${'test-branch'} | ${false}
`('when branch name is $branchName', ({ branchName, submitButtonDisabled }) => {
it(`sets submit button 'disabled' prop to ${submitButtonDisabled}`, async () => {
createComponent();
await completeForm();
await findInput().vm.$emit('input', branchName);
expect(findButton().props('disabled')).toBe(submitButtonDisabled);
});
});
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment