Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8ac6382e
Commit
8ac6382e
authored
Nov 02, 2020
by
derek-knox
Committed by
Chad Woolley
Nov 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update test suite
Update tests Add changelog
parent
a5438f30
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
10 deletions
+91
-10
changelogs/unreleased/263252-mr-template-api.yml
changelogs/unreleased/263252-mr-template-api.yml
+5
-0
spec/controllers/projects/templates_controller_spec.rb
spec/controllers/projects/templates_controller_spec.rb
+39
-0
spec/frontend/api_spec.js
spec/frontend/api_spec.js
+22
-0
spec/frontend/static_site_editor/components/edit_meta_modal_spec.js
...end/static_site_editor/components/edit_meta_modal_spec.js
+25
-10
No files found.
changelogs/unreleased/263252-mr-template-api.yml
0 → 100644
View file @
8ac6382e
---
title
:
Add merge request description templates to Static Site Editor
merge_request
:
46488
author
:
type
:
added
spec/controllers/projects/templates_controller_spec.rb
View file @
8ac6382e
...
...
@@ -10,6 +10,45 @@ RSpec.describe Projects::TemplatesController do
let!
(
:file_1
)
{
project
.
repository
.
create_file
(
user
,
file_path_1
,
'issue content'
,
message:
'message'
,
branch_name:
'master'
)
}
let!
(
:file_2
)
{
project
.
repository
.
create_file
(
user
,
file_path_2
,
'merge request content'
,
message:
'message'
,
branch_name:
'master'
)
}
describe
'#index'
do
before
do
sign_in
(
user
)
end
shared_examples
'templates request'
do
it
'returns the templates'
do
get
(
:index
,
params:
{
namespace_id:
project
.
namespace
,
template_type:
template_type
,
project_id:
project
},
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
).
to
eq
(
expected_templates
)
end
it
'fails for user with no access'
do
other_user
=
create
(
:user
)
sign_in
(
other_user
)
get
(
:index
,
params:
{
namespace_id:
project
.
namespace
,
template_type:
template_type
,
project_id:
project
},
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'when querying for issue templates'
do
it_behaves_like
'templates request'
do
let
(
:template_type
)
{
'issue'
}
let
(
:expected_templates
)
{
[
{
key:
"template1"
,
name:
"template_1"
,
content:
"This is template 1!"
}
]
}
end
end
context
'when querying for merge_request templates'
do
it_behaves_like
'templates request'
do
let
(
:template_type
)
{
'merge_request'
}
let
(
:expected_templates
)
{
[
{
key:
"template1"
,
name:
"template_1"
,
content:
"This is template 1!"
}
]
}
end
end
end
describe
'#show'
do
shared_examples
'renders issue templates as json'
do
it
do
...
...
spec/frontend/api_spec.js
View file @
8ac6382e
...
...
@@ -570,6 +570,28 @@ describe('Api', () => {
});
});
describe
(
'
issueTemplates
'
,
()
=>
{
it
(
'
fetches all templates by type
'
,
done
=>
{
const
namespace
=
'
some namespace
'
;
const
project
=
'
some project
'
;
const
templateType
=
'
template type
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/
${
namespace
}
/
${
project
}
/templates/
${
templateType
}
`
;
const
expectedData
=
[
{
key
:
'
Template1
'
,
name
:
'
Template 1
'
,
content
:
'
This is template 1!
'
},
];
mock
.
onGet
(
expectedUrl
).
reply
(
httpStatus
.
OK
,
expectedData
);
Api
.
issueTemplates
(
namespace
,
project
,
templateType
,
(
error
,
response
)
=>
{
expect
(
response
.
length
).
toBe
(
1
);
const
{
key
,
name
,
content
}
=
response
[
0
];
expect
(
key
).
toBe
(
'
Template1
'
);
expect
(
name
).
toBe
(
'
Template 1
'
);
expect
(
content
).
toBe
(
'
This is template 1!
'
);
done
();
});
});
});
describe
(
'
projectTemplates
'
,
()
=>
{
it
(
'
fetches a list of templates
'
,
done
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/projects/gitlab-org%2Fgitlab-ce/templates/licenses`
;
...
...
spec/frontend/static_site_editor/components/edit_meta_modal_spec.js
View file @
8ac6382e
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlModal
}
from
'
@gitlab/ui
'
;
import
{
useLocalStorageSpy
}
from
'
helpers/local_storage_helper
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
LocalStorageSync
from
'
~/vue_shared/components/local_storage_sync.vue
'
;
import
EditMetaModal
from
'
~/static_site_editor/components/edit_meta_modal.vue
'
;
import
EditMetaControls
from
'
~/static_site_editor/components/edit_meta_controls.vue
'
;
import
{
MR_META_LOCAL_STORAGE_KEY
}
from
'
~/static_site_editor/constants
'
;
import
{
sourcePath
,
mergeRequestMeta
,
mergeRequestTemplates
}
from
'
../mock_data
'
;
import
{
sourcePath
,
mergeRequestMeta
,
mergeRequestTemplates
,
project
as
namespaceProject
,
}
from
'
../mock_data
'
;
describe
(
'
~/static_site_editor/components/edit_meta_modal.vue
'
,
()
=>
{
useLocalStorageSpy
();
let
wrapper
;
let
resetCachedEditable
;
let
mockEditMetaControlsInstance
;
let
mockAxios
;
const
{
title
,
description
}
=
mergeRequestMeta
;
const
[
namespace
,
project
]
=
namespaceProject
.
split
(
'
/
'
);
const
buildWrapper
=
(
propsData
=
{},
data
=
{})
=>
{
wrapper
=
shallowMount
(
EditMetaModal
,
{
propsData
:
{
sourcePath
,
namespace
,
project
,
...
propsData
,
},
data
:
()
=>
data
,
});
};
const
buildMocks
=
()
=>
{
resetCachedEditable
=
jest
.
fn
();
mockEditMetaControlsInstance
=
{
resetCachedEditable
};
wrapper
.
vm
.
$refs
.
editMetaControls
=
mockEditMetaControlsInstance
;
const
buildMockAxios
=
()
=>
{
mockAxios
=
new
MockAdapter
(
axios
);
mockAxios
.
onGet
(
`
${
namespace
}
/
${
project
}
/templates/merge_request`
)
.
reply
(
200
,
mergeRequestTemplates
);
};
const
buildMockRefs
=
()
=>
{
wrapper
.
vm
.
$refs
.
editMetaControls
=
{
resetCachedEditable
:
jest
.
fn
()
};
};
const
findGlModal
=
()
=>
wrapper
.
find
(
GlModal
);
...
...
@@ -37,16 +51,17 @@ describe('~/static_site_editor/components/edit_meta_modal.vue', () => {
beforeEach
(()
=>
{
localStorage
.
setItem
(
MR_META_LOCAL_STORAGE_KEY
);
});
beforeEach
(()
=>
{
buildMockAxios
();
buildWrapper
();
buildMocks
();
buildMock
Ref
s
();
return
wrapper
.
vm
.
$nextTick
();
});
afterEach
(()
=>
{
mockAxios
.
restore
();
wrapper
.
destroy
();
wrapper
=
null
;
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment