Commit 84400237 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'sort-fork-form-namespace' into 'master'

Sort fork form namespaces

See merge request gitlab-org/gitlab!65178
parents 574bc44b 727106f0
......@@ -39,6 +39,14 @@ const initFormField = ({ value, required = true, skipValidation = false }) => ({
feedback: null,
});
function sortNamespaces(namespaces) {
if (!namespaces || !namespaces?.length) {
return namespaces;
}
return namespaces.sort((a, b) => a.name.localeCompare(b.name));
}
export default {
components: {
GlForm,
......@@ -206,7 +214,7 @@ export default {
methods: {
async fetchNamespaces() {
const { data } = await axios.get(this.endpoint);
this.namespaces = data.namespaces;
this.namespaces = sortNamespaces(data.namespaces);
},
isVisibilityLevelDisabled(visibility) {
return !this.allowedVisibilityLevels.includes(visibility);
......
......@@ -181,6 +181,20 @@ describe('ForkForm component', () => {
expect(optionsArray.at(1).text()).toBe(MOCK_NAMESPACES_RESPONSE[0].name);
expect(optionsArray.at(2).text()).toBe(MOCK_NAMESPACES_RESPONSE[1].name);
});
it('set namespaces in alphabetical order', async () => {
const namespace = {
name: 'aaa',
id: 3,
};
mockGetRequest({
namespaces: [...MOCK_NAMESPACES_RESPONSE, namespace],
});
createComponent();
await axios.waitForAll();
expect(wrapper.vm.namespaces).toEqual([namespace, ...MOCK_NAMESPACES_RESPONSE]);
});
});
describe('project slug', () => {
......
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