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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
5b84c2fb
Commit
5b84c2fb
authored
Aug 30, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added component specs
parent
d6410a03
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
345 additions
and
22 deletions
+345
-22
app/assets/javascripts/ide/components/file_templates/bar.vue
app/assets/javascripts/ide/components/file_templates/bar.vue
+7
-18
app/assets/javascripts/ide/components/new_dropdown/modal.vue
app/assets/javascripts/ide/components/new_dropdown/modal.vue
+7
-1
app/assets/javascripts/ide/stores/index.js
app/assets/javascripts/ide/stores/index.js
+1
-1
app/assets/javascripts/ide/stores/modules/file_templates/index.js
...ts/javascripts/ide/stores/modules/file_templates/index.js
+2
-2
app/assets/stylesheets/page_bundles/ide.scss
app/assets/stylesheets/page_bundles/ide.scss
+10
-0
spec/javascripts/ide/components/file_templates/bar_spec.js
spec/javascripts/ide/components/file_templates/bar_spec.js
+115
-0
spec/javascripts/ide/components/file_templates/dropdown_spec.js
...avascripts/ide/components/file_templates/dropdown_spec.js
+201
-0
spec/javascripts/ide/helpers.js
spec/javascripts/ide/helpers.js
+2
-0
No files found.
app/assets/javascripts/ide/components/file_templates/bar.vue
View file @
5b84c2fb
...
...
@@ -15,9 +15,7 @@ export default {
},
},
watch
:
{
activeFile
:
{
handler
:
'
setInitialType
'
,
},
activeFile
:
'
setInitialType
'
,
},
mounted
()
{
this
.
setInitialType
();
...
...
@@ -38,9 +36,12 @@ export default {
selectTemplateType
(
type
)
{
this
.
setSelectedTemplateType
(
type
);
},
select
e
Template
(
template
)
{
selectTemplate
(
template
)
{
this
.
fetchTemplate
(
template
);
},
undo
()
{
this
.
undoFileTemplate
();
},
},
};
</
script
>
...
...
@@ -63,29 +64,17 @@ export default {
:searchable=
"true"
:title=
"__('File templates')"
class=
"mr-2"
@
click=
"select
e
Template"
@
click=
"selectTemplate"
/>
<transition
name=
"fade"
>
<button
v-show=
"updateSuccess"
type=
"button"
class=
"btn btn-default"
@
click=
"undo
FileTemplate
"
@
click=
"undo"
>
{{
__
(
'
Undo
'
)
}}
</button>
</transition>
</div>
</
template
>
<
style
>
.ide-file-templates
{
padding
:
8px
16px
;
background-color
:
#fafafa
;
border-bottom
:
1px
solid
#eaeaea
;
}
.ide-file-templates
.dropdown
{
min-width
:
180px
;
}
</
style
>
app/assets/javascripts/ide/components/new_dropdown/modal.vue
View file @
5b84c2fb
...
...
@@ -51,6 +51,9 @@ export default {
return
__
(
'
Create file
'
);
},
isCreatingNew
()
{
return
this
.
entryModal
.
type
!==
modalTypes
.
rename
;
},
},
methods
:
{
...
mapActions
([
'
createTempEntry
'
,
'
renameEntry
'
]),
...
...
@@ -110,7 +113,10 @@ export default {
class=
"form-control"
placeholder=
"/dir/file_name"
/>
<ul
class=
"prepend-top-default list-inline"
>
<ul
v-if=
"isCreatingNew"
class=
"prepend-top-default list-inline"
>
<li
v-for=
"(template, index) in templateTypes"
:key=
"index"
...
...
app/assets/javascripts/ide/stores/index.js
View file @
5b84c2fb
...
...
@@ -23,7 +23,7 @@ export const createStore = () =>
pipelines
,
mergeRequests
,
branches
,
fileTemplates
,
fileTemplates
:
fileTemplates
()
,
},
});
...
...
app/assets/javascripts/ide/stores/modules/file_templates/index.js
View file @
5b84c2fb
...
...
@@ -3,10 +3,10 @@ import * as actions from './actions';
import
*
as
getters
from
'
./getters
'
;
import
mutations
from
'
./mutations
'
;
export
default
{
export
default
()
=>
(
{
namespaced
:
true
,
actions
,
state
:
createState
(),
getters
,
mutations
,
};
}
)
;
app/assets/stylesheets/page_bundles/ide.scss
View file @
5b84c2fb
...
...
@@ -1442,3 +1442,13 @@ $ide-tree-text-start: $ide-activity-bar-width + $ide-tree-padding;
top
:
50%
;
transform
:
translateY
(
-50%
);
}
.ide-file-templates
{
padding
:
$grid-size
$gl-padding
;
background-color
:
$gray-light
;
border-bottom
:
1px
solid
$white-dark
;
.dropdown
{
min-width
:
180px
;
}
}
spec/javascripts/ide/components/file_templates/bar_spec.js
0 → 100644
View file @
5b84c2fb
import
Vue
from
'
vue
'
;
import
{
createStore
}
from
'
~/ide/stores
'
;
import
Bar
from
'
~/ide/components/file_templates/bar.vue
'
;
import
{
createComponentWithStore
}
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
resetStore
,
file
}
from
'
../../helpers
'
;
describe
(
'
IDE file templates bar component
'
,
()
=>
{
let
Component
;
let
vm
;
beforeAll
(()
=>
{
Component
=
Vue
.
extend
(
Bar
);
});
beforeEach
(()
=>
{
const
store
=
createStore
();
store
.
state
.
openFiles
.
push
({
...
file
(
'
file
'
),
opened
:
true
,
active
:
true
,
});
vm
=
createComponentWithStore
(
Component
,
store
).
$mount
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
resetStore
(
vm
.
$store
);
});
describe
(
'
template type dropdown
'
,
()
=>
{
it
(
'
renders dropdown component
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown
'
).
textContent
).
toContain
(
'
Choose a type
'
);
});
it
(
'
calls setSelectedTemplateType when clicking item
'
,
()
=>
{
spyOn
(
vm
,
'
setSelectedTemplateType
'
);
vm
.
$el
.
querySelector
(
'
.dropdown-content button
'
).
click
();
expect
(
vm
.
setSelectedTemplateType
).
toHaveBeenCalledWith
({
name
:
'
.gitlab-ci.yml
'
,
key
:
'
gitlab_ci_ymls
'
,
});
});
});
describe
(
'
template dropdown
'
,
()
=>
{
beforeEach
(
done
=>
{
vm
.
$store
.
state
.
fileTemplates
.
templates
=
[
{
name
:
'
test
'
,
},
];
vm
.
$store
.
state
.
fileTemplates
.
selectedTemplateType
=
{
name
:
'
.gitlab-ci.yml
'
,
key
:
'
gitlab_ci_ymls
'
,
};
vm
.
$nextTick
(
done
);
});
it
(
'
renders dropdown component
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelectorAll
(
'
.dropdown
'
)[
1
].
textContent
).
toContain
(
'
Choose a template
'
);
});
it
(
'
calls fetchTemplate on click
'
,
()
=>
{
spyOn
(
vm
,
'
fetchTemplate
'
);
vm
.
$el
.
querySelectorAll
(
'
.dropdown-content
'
)[
1
]
.
querySelector
(
'
button
'
)
.
click
();
expect
(
vm
.
fetchTemplate
).
toHaveBeenCalledWith
({
name
:
'
test
'
,
});
});
});
it
(
'
shows undo button if updateSuccess is true
'
,
done
=>
{
vm
.
$store
.
state
.
fileTemplates
.
updateSuccess
=
true
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.btn-default
'
).
style
.
display
).
not
.
toBe
(
'
none
'
);
done
();
});
});
it
(
'
calls undoFileTemplate when clicking undo button
'
,
()
=>
{
spyOn
(
vm
,
'
undoFileTemplate
'
);
vm
.
$el
.
querySelector
(
'
.btn-default
'
).
click
();
expect
(
vm
.
undoFileTemplate
).
toHaveBeenCalled
();
});
it
(
'
calls setSelectedTemplateType if activeFile name matches a template
'
,
done
=>
{
spyOn
(
vm
,
'
setSelectedTemplateType
'
);
vm
.
$store
.
state
.
openFiles
[
0
].
name
=
'
.gitlab-ci.yml
'
;
vm
.
setInitialType
();
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
setSelectedTemplateType
).
toHaveBeenCalledWith
({
name
:
'
.gitlab-ci.yml
'
,
key
:
'
gitlab_ci_ymls
'
,
});
done
();
});
});
});
spec/javascripts/ide/components/file_templates/dropdown_spec.js
0 → 100644
View file @
5b84c2fb
import
$
from
'
jquery
'
;
import
Vue
from
'
vue
'
;
import
{
createStore
}
from
'
~/ide/stores
'
;
import
Dropdown
from
'
~/ide/components/file_templates/dropdown.vue
'
;
import
{
createComponentWithStore
}
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
describe
(
'
IDE file templates dropdown component
'
,
()
=>
{
let
Component
;
let
vm
;
beforeAll
(()
=>
{
Component
=
Vue
.
extend
(
Dropdown
);
});
beforeEach
(()
=>
{
const
store
=
createStore
();
vm
=
createComponentWithStore
(
Component
,
store
,
{
label
:
'
Test
'
,
}).
$mount
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
resetStore
(
vm
.
$store
);
});
describe
(
'
async
'
,
()
=>
{
beforeEach
(()
=>
{
vm
.
async
=
true
;
});
it
(
'
calls async store method on Bootstrap dropdown event
'
,
()
=>
{
spyOn
(
vm
,
'
fetchTemplateTypes
'
);
$
(
vm
.
$el
).
trigger
(
'
show.bs.dropdown
'
);
expect
(
vm
.
fetchTemplateTypes
).
toHaveBeenCalled
();
});
it
(
'
renders templates when async
'
,
done
=>
{
vm
.
$store
.
state
.
fileTemplates
.
templates
=
[
{
name
:
'
test
'
,
},
];
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-content
'
).
textContent
).
toContain
(
'
test
'
);
done
();
});
});
it
(
'
renders loading icon when isLoading is true
'
,
done
=>
{
vm
.
$store
.
state
.
fileTemplates
.
isLoading
=
true
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.loading-container
'
)).
not
.
toBe
(
null
);
done
();
});
});
it
(
'
searches template data
'
,
()
=>
{
vm
.
$store
.
state
.
fileTemplates
.
templates
=
[
{
name
:
'
test
'
,
},
];
vm
.
searchable
=
true
;
vm
.
search
=
'
hello
'
;
expect
(
vm
.
outputData
).
toEqual
([]);
});
it
(
'
does not filter data is searchable is false
'
,
()
=>
{
vm
.
$store
.
state
.
fileTemplates
.
templates
=
[
{
name
:
'
test
'
,
},
];
vm
.
search
=
'
hello
'
;
expect
(
vm
.
outputData
).
toEqual
([
{
name
:
'
test
'
,
},
]);
});
it
(
'
calls clickItem on click
'
,
done
=>
{
spyOn
(
vm
,
'
clickItem
'
);
vm
.
$store
.
state
.
fileTemplates
.
templates
=
[
{
name
:
'
test
'
,
},
];
vm
.
$nextTick
(()
=>
{
vm
.
$el
.
querySelector
(
'
.dropdown-content button
'
).
click
();
expect
(
vm
.
clickItem
).
toHaveBeenCalledWith
({
name
:
'
test
'
,
});
done
();
});
});
it
(
'
renders input when searchable is true
'
,
done
=>
{
vm
.
searchable
=
true
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-input
'
)).
not
.
toBe
(
null
);
done
();
});
});
it
(
'
does not render input when searchable is true & showLoading is true
'
,
done
=>
{
vm
.
searchable
=
true
;
vm
.
$store
.
state
.
fileTemplates
.
isLoading
=
true
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-input
'
)).
toBe
(
null
);
done
();
});
});
});
describe
(
'
sync
'
,
()
=>
{
beforeEach
(
done
=>
{
vm
.
data
=
[
{
name
:
'
test sync
'
,
},
];
vm
.
$nextTick
(
done
);
});
it
(
'
renders props data
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-content
'
).
textContent
).
toContain
(
'
test sync
'
);
});
it
(
'
renders input when searchable is true
'
,
done
=>
{
vm
.
searchable
=
true
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-input
'
)).
not
.
toBe
(
null
);
done
();
});
});
it
(
'
calls clickItem on click
'
,
done
=>
{
spyOn
(
vm
,
'
clickItem
'
);
vm
.
$nextTick
(()
=>
{
vm
.
$el
.
querySelector
(
'
.dropdown-content button
'
).
click
();
expect
(
vm
.
clickItem
).
toHaveBeenCalledWith
({
name
:
'
test sync
'
,
});
done
();
});
});
it
(
'
searches template data
'
,
()
=>
{
vm
.
searchable
=
true
;
vm
.
search
=
'
hello
'
;
expect
(
vm
.
outputData
).
toEqual
([]);
});
it
(
'
does not filter data is searchable is false
'
,
()
=>
{
vm
.
search
=
'
hello
'
;
expect
(
vm
.
outputData
).
toEqual
([
{
name
:
'
test sync
'
,
},
]);
});
it
(
'
renders dropdown title
'
,
done
=>
{
vm
.
title
=
'
Test title
'
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.dropdown-title
'
).
textContent
).
toContain
(
'
Test title
'
);
done
();
});
});
});
});
spec/javascripts/ide/helpers.js
View file @
5b84c2fb
...
...
@@ -5,6 +5,7 @@ import commitState from '~/ide/stores/modules/commit/state';
import
mergeRequestsState
from
'
~/ide/stores/modules/merge_requests/state
'
;
import
pipelinesState
from
'
~/ide/stores/modules/pipelines/state
'
;
import
branchesState
from
'
~/ide/stores/modules/branches/state
'
;
import
fileTemplatesState
from
'
~/ide/stores/modules/file_templates/state
'
;
export
const
resetStore
=
store
=>
{
const
newState
=
{
...
...
@@ -13,6 +14,7 @@ export const resetStore = store => {
mergeRequests
:
mergeRequestsState
(),
pipelines
:
pipelinesState
(),
branches
:
branchesState
(),
fileTemplates
:
fileTemplatesState
(),
};
store
.
replaceState
(
newState
);
};
...
...
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