Commit 727106f0 authored by Samantha Ming's avatar Samantha Ming

Sort fork form namespaces alphabetically

This will ensure the namespaces are
displayed in alphabetical order by its name.

Changelog: changed
parent 81e12628
......@@ -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