-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Update git repo url validation regex (#7151)
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,49 @@ describe('SettingsSourceControl', () => { | |
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(), | ||
); | ||
}, 10000); | ||
|
||
describe('should test repo URLs', () => { | ||
beforeEach(() => { | ||
settingsStore.settings.enterprise[EnterpriseEditionFeature.SourceControl] = true; | ||
}); | ||
|
||
test.each([ | ||
['[email protected]:user/repository.git', true], | ||
['[email protected]:org-name/repo-name.git', true], | ||
['[email protected]:2222:user/repo.git', true], | ||
['[email protected]:user/repo.git/path/to/subdir', true], | ||
// The opening bracket in curly braces makes sure it is not treated as a special character by the 'user-event' library | ||
['git@{[}2001:db8:100:f101:210:a4ff:fee3:9566]:user/repo.git', true], | ||
['[email protected]:org/suborg/repo.git', true], | ||
['[email protected]:user-name/repo-name.git', true], | ||
['[email protected]:user_name/repo_name.git', true], | ||
['[email protected]:user/repository', true], | ||
['[email protected]:org-name/repo-name', true], | ||
['[email protected]:2222:user/repo', true], | ||
['[email protected]:v3/User/repo/directory', true], | ||
['http://github.com/user/repository', false], | ||
['https://github.com/user/repository', false], | ||
])('%s', async (url: string, isValid: boolean) => { | ||
await nextTick(); | ||
const { container, queryByText } = renderComponent({ | ||
pinia, | ||
}); | ||
|
||
await waitFor(() => expect(sourceControlStore.preferences.publicKey).not.toEqual('')); | ||
|
||
const repoUrlInput = container.querySelector('input[name="repoUrl"]')!; | ||
|
||
await userEvent.click(repoUrlInput); | ||
await userEvent.type(repoUrlInput, url); | ||
await userEvent.tab(); | ||
|
||
const inputError = expect(queryByText('The Git repository URL is not valid')); | ||
|
||
if (isValid) { | ||
inputError.not.toBeInTheDocument(); | ||
} else { | ||
inputError.toBeInTheDocument(); | ||
} | ||
}); | ||
}); | ||
}); |