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
a9967814
Commit
a9967814
authored
Jun 15, 2021
by
Mireya Andres
Committed by
David O'Regan
Jun 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache newly committed branches in branch switcher
parent
d6d30254
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
175 additions
and
37 deletions
+175
-37
app/assets/javascripts/pipeline_editor/components/commit/commit_section.vue
...ipts/pipeline_editor/components/commit/commit_section.vue
+16
-0
app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue
...s/pipeline_editor/components/file_nav/branch_switcher.vue
+28
-13
app/assets/javascripts/pipeline_editor/graphql/mutations/update_current_branch.mutation.graphql
.../graphql/mutations/update_current_branch.mutation.graphql
+3
-0
app/assets/javascripts/pipeline_editor/graphql/mutations/update_last_commit_branch.mutation.graphql
...phql/mutations/update_last_commit_branch.mutation.graphql
+3
-0
app/assets/javascripts/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
...r/graphql/queries/client/last_commit_branch.query.graphql
+3
-0
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
+19
-0
app/assets/javascripts/pipeline_editor/index.js
app/assets/javascripts/pipeline_editor/index.js
+8
-0
app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue
...ssets/javascripts/pipeline_editor/pipeline_editor_app.vue
+2
-1
spec/frontend/pipeline_editor/components/commit/commit_section_spec.js
.../pipeline_editor/components/commit/commit_section_spec.js
+5
-4
spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
...peline_editor/components/file-nav/branch_switcher_spec.js
+87
-19
spec/frontend/pipeline_editor/mock_data.js
spec/frontend/pipeline_editor/mock_data.js
+1
-0
No files found.
app/assets/javascripts/pipeline_editor/components/commit/commit_section.vue
View file @
a9967814
...
@@ -8,6 +8,8 @@ import {
...
@@ -8,6 +8,8 @@ import {
COMMIT_SUCCESS
,
COMMIT_SUCCESS
,
}
from
'
../../constants
'
;
}
from
'
../../constants
'
;
import
commitCIFile
from
'
../../graphql/mutations/commit_ci_file.mutation.graphql
'
;
import
commitCIFile
from
'
../../graphql/mutations/commit_ci_file.mutation.graphql
'
;
import
updateCurrentBranchMutation
from
'
../../graphql/mutations/update_current_branch.mutation.graphql
'
;
import
updateLastCommitBranchMutation
from
'
../../graphql/mutations/update_last_commit_branch.mutation.graphql
'
;
import
getCommitSha
from
'
../../graphql/queries/client/commit_sha.graphql
'
;
import
getCommitSha
from
'
../../graphql/queries/client/commit_sha.graphql
'
;
import
getCurrentBranch
from
'
../../graphql/queries/client/current_branch.graphql
'
;
import
getCurrentBranch
from
'
../../graphql/queries/client/current_branch.graphql
'
;
import
getIsNewCiConfigFile
from
'
../../graphql/queries/client/is_new_ci_config_file.graphql
'
;
import
getIsNewCiConfigFile
from
'
../../graphql/queries/client/is_new_ci_config_file.graphql
'
;
...
@@ -113,6 +115,8 @@ export default {
...
@@ -113,6 +115,8 @@ export default {
this
.
redirectToNewMergeRequest
(
targetBranch
);
this
.
redirectToNewMergeRequest
(
targetBranch
);
}
else
{
}
else
{
this
.
$emit
(
'
commit
'
,
{
type
:
COMMIT_SUCCESS
});
this
.
$emit
(
'
commit
'
,
{
type
:
COMMIT_SUCCESS
});
this
.
updateLastCommitBranch
(
targetBranch
);
this
.
updateCurrentBranch
(
targetBranch
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
this
.
$emit
(
'
showError
'
,
{
type
:
COMMIT_FAILURE
,
reasons
:
[
error
?.
message
]
});
this
.
$emit
(
'
showError
'
,
{
type
:
COMMIT_FAILURE
,
reasons
:
[
error
?.
message
]
});
...
@@ -123,6 +127,18 @@ export default {
...
@@ -123,6 +127,18 @@ export default {
onCommitCancel
()
{
onCommitCancel
()
{
this
.
$emit
(
'
resetContent
'
);
this
.
$emit
(
'
resetContent
'
);
},
},
updateCurrentBranch
(
currentBranch
)
{
this
.
$apollo
.
mutate
({
mutation
:
updateCurrentBranchMutation
,
variables
:
{
currentBranch
},
});
},
updateLastCommitBranch
(
lastCommitBranch
)
{
this
.
$apollo
.
mutate
({
mutation
:
updateLastCommitBranchMutation
,
variables
:
{
lastCommitBranch
},
});
},
},
},
};
};
</
script
>
</
script
>
...
...
app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue
View file @
a9967814
...
@@ -18,8 +18,10 @@ import {
...
@@ -18,8 +18,10 @@ import {
BRANCH_SEARCH_DEBOUNCE
,
BRANCH_SEARCH_DEBOUNCE
,
DEFAULT_FAILURE
,
DEFAULT_FAILURE
,
}
from
'
~/pipeline_editor/constants
'
;
}
from
'
~/pipeline_editor/constants
'
;
import
getAvailableBranches
from
'
~/pipeline_editor/graphql/queries/available_branches.graphql
'
;
import
updateCurrentBranchMutation
from
'
~/pipeline_editor/graphql/mutations/update_current_branch.mutation.graphql
'
;
import
getCurrentBranch
from
'
~/pipeline_editor/graphql/queries/client/current_branch.graphql
'
;
import
getAvailableBranchesQuery
from
'
~/pipeline_editor/graphql/queries/available_branches.graphql
'
;
import
getCurrentBranchQuery
from
'
~/pipeline_editor/graphql/queries/client/current_branch.graphql
'
;
import
getLastCommitBranchQuery
from
'
~/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
'
;
export
default
{
export
default
{
i18n
:
{
i18n
:
{
...
@@ -55,11 +57,12 @@ export default {
...
@@ -55,11 +57,12 @@ export default {
pageLimit
:
this
.
paginationLimit
,
pageLimit
:
this
.
paginationLimit
,
pageCounter
:
0
,
pageCounter
:
0
,
searchTerm
:
''
,
searchTerm
:
''
,
lastCommitBranch
:
''
,
};
};
},
},
apollo
:
{
apollo
:
{
availableBranches
:
{
availableBranches
:
{
query
:
getAvailableBranches
,
query
:
getAvailableBranches
Query
,
variables
()
{
variables
()
{
return
{
return
{
limit
:
this
.
paginationLimit
,
limit
:
this
.
paginationLimit
,
...
@@ -79,7 +82,16 @@ export default {
...
@@ -79,7 +82,16 @@ export default {
},
},
},
},
currentBranch
:
{
currentBranch
:
{
query
:
getCurrentBranch
,
query
:
getCurrentBranchQuery
,
},
lastCommitBranch
:
{
query
:
getLastCommitBranchQuery
,
result
({
data
:
{
lastCommitBranch
}
})
{
if
(
lastCommitBranch
===
''
||
this
.
availableBranches
.
includes
(
lastCommitBranch
))
{
return
;
}
this
.
availableBranches
.
unshift
(
lastCommitBranch
);
},
},
},
},
},
computed
:
{
computed
:
{
...
@@ -94,13 +106,14 @@ export default {
...
@@ -94,13 +106,14 @@ export default {
},
},
},
},
methods
:
{
methods
:
{
availableBranchesQueryVars
()
{
availableBranchesQueryVars
(
varsOverride
=
{}
)
{
if
(
this
.
searchTerm
.
length
>
0
)
{
if
(
this
.
searchTerm
.
length
>
0
)
{
return
{
return
{
limit
:
this
.
totalBranches
,
limit
:
this
.
totalBranches
,
offset
:
0
,
offset
:
0
,
projectFullPath
:
this
.
projectFullPath
,
projectFullPath
:
this
.
projectFullPath
,
searchPattern
:
`*
${
this
.
searchTerm
}
*`
,
searchPattern
:
`*
${
this
.
searchTerm
}
*`
,
...
varsOverride
,
};
};
}
}
...
@@ -109,6 +122,7 @@ export default {
...
@@ -109,6 +122,7 @@ export default {
offset
:
this
.
pageCounter
*
this
.
paginationLimit
,
offset
:
this
.
pageCounter
*
this
.
paginationLimit
,
projectFullPath
:
this
.
projectFullPath
,
projectFullPath
:
this
.
projectFullPath
,
searchPattern
:
'
*
'
,
searchPattern
:
'
*
'
,
...
varsOverride
,
};
};
},
},
// if there is no searchPattern, paginate by {paginationLimit} branches
// if there is no searchPattern, paginate by {paginationLimit} branches
...
@@ -116,7 +130,7 @@ export default {
...
@@ -116,7 +130,7 @@ export default {
if
(
if
(
this
.
isBranchesLoading
||
this
.
isBranchesLoading
||
this
.
searchTerm
.
length
>
0
||
this
.
searchTerm
.
length
>
0
||
this
.
branches
.
length
==
=
this
.
totalBranches
this
.
branches
.
length
>
=
this
.
totalBranches
)
{
)
{
return
;
return
;
}
}
...
@@ -140,11 +154,7 @@ export default {
...
@@ -140,11 +154,7 @@ export default {
return
;
return
;
}
}
await
this
.
$apollo
.
getClient
().
writeQuery
({
this
.
updateCurrentBranch
(
newBranch
);
query
:
getCurrentBranch
,
data
:
{
currentBranch
:
newBranch
},
});
const
updatedPath
=
setUrlParams
({
branch_name
:
newBranch
});
const
updatedPath
=
setUrlParams
({
branch_name
:
newBranch
});
historyPushState
(
updatedPath
);
historyPushState
(
updatedPath
);
...
@@ -162,7 +172,7 @@ export default {
...
@@ -162,7 +172,7 @@ export default {
this
.
isSearchingBranches
=
true
;
this
.
isSearchingBranches
=
true
;
const
fetchResults
=
await
this
.
$apollo
const
fetchResults
=
await
this
.
$apollo
.
query
({
.
query
({
query
:
getAvailableBranches
,
query
:
getAvailableBranches
Query
,
fetchPolicy
:
fetchPolicies
.
NETWORK_ONLY
,
fetchPolicy
:
fetchPolicies
.
NETWORK_ONLY
,
variables
:
this
.
availableBranchesQueryVars
(),
variables
:
this
.
availableBranchesQueryVars
(),
})
})
...
@@ -177,6 +187,12 @@ export default {
...
@@ -177,6 +187,12 @@ export default {
reasons
:
[
this
.
$options
.
i18n
.
fetchError
],
reasons
:
[
this
.
$options
.
i18n
.
fetchError
],
});
});
},
},
updateCurrentBranch
(
currentBranch
)
{
this
.
$apollo
.
mutate
({
mutation
:
updateCurrentBranchMutation
,
variables
:
{
currentBranch
},
});
},
},
},
};
};
</
script
>
</
script
>
...
@@ -197,7 +213,6 @@ export default {
...
@@ -197,7 +213,6 @@ export default {
<gl-infinite-scroll
<gl-infinite-scroll
:fetched-items=
"branches.length"
:fetched-items=
"branches.length"
:total-items=
"totalBranches"
:max-list-height=
"250"
:max-list-height=
"250"
@
bottomReached=
"fetchNextBranches"
@
bottomReached=
"fetchNextBranches"
>
>
...
...
app/assets/javascripts/pipeline_editor/graphql/mutations/update_current_branch.mutation.graphql
0 → 100644
View file @
a9967814
mutation
updateCurrentBranch
(
$currentBranch
:
String
)
{
updateCurrentBranch
(
currentBranch
:
$currentBranch
)
@client
}
app/assets/javascripts/pipeline_editor/graphql/mutations/update_last_commit_branch.mutation.graphql
0 → 100644
View file @
a9967814
mutation
updateLastCommitBranch
(
$lastCommitBranch
:
String
)
{
updateLastCommitBranch
(
lastCommitBranch
:
$lastCommitBranch
)
@client
}
app/assets/javascripts/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
0 → 100644
View file @
a9967814
query
getLastCommitBranchQuery
{
lastCommitBranch
@client
}
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
View file @
a9967814
import
produce
from
'
immer
'
;
import
Api
from
'
~/api
'
;
import
Api
from
'
~/api
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
getCurrentBranchQuery
from
'
./queries/client/current_branch.graphql
'
;
import
getLastCommitBranchQuery
from
'
./queries/client/last_commit_branch.query.graphql
'
;
export
const
resolvers
=
{
export
const
resolvers
=
{
Query
:
{
Query
:
{
...
@@ -39,5 +42,21 @@ export const resolvers = {
...
@@ -39,5 +42,21 @@ export const resolvers = {
__typename
:
'
CiLintContent
'
,
__typename
:
'
CiLintContent
'
,
}));
}));
},
},
updateCurrentBranch
:
(
_
,
{
currentBranch
=
undefined
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getCurrentBranchQuery
,
data
:
produce
(
cache
.
readQuery
({
query
:
getCurrentBranchQuery
}),
(
draftData
)
=>
{
draftData
.
currentBranch
=
currentBranch
;
}),
});
},
updateLastCommitBranch
:
(
_
,
{
lastCommitBranch
=
undefined
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getLastCommitBranchQuery
,
data
:
produce
(
cache
.
readQuery
({
query
:
getLastCommitBranchQuery
}),
(
draftData
)
=>
{
draftData
.
lastCommitBranch
=
lastCommitBranch
;
}),
});
},
},
},
};
};
app/assets/javascripts/pipeline_editor/index.js
View file @
a9967814
...
@@ -6,6 +6,7 @@ import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
...
@@ -6,6 +6,7 @@ import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
import
{
CODE_SNIPPET_SOURCE_SETTINGS
}
from
'
./components/code_snippet_alert/constants
'
;
import
{
CODE_SNIPPET_SOURCE_SETTINGS
}
from
'
./components/code_snippet_alert/constants
'
;
import
getCommitSha
from
'
./graphql/queries/client/commit_sha.graphql
'
;
import
getCommitSha
from
'
./graphql/queries/client/commit_sha.graphql
'
;
import
getCurrentBranch
from
'
./graphql/queries/client/current_branch.graphql
'
;
import
getCurrentBranch
from
'
./graphql/queries/client/current_branch.graphql
'
;
import
getLastCommitBranchQuery
from
'
./graphql/queries/client/last_commit_branch.query.graphql
'
;
import
getPipelineEtag
from
'
./graphql/queries/client/pipeline_etag.graphql
'
;
import
getPipelineEtag
from
'
./graphql/queries/client/pipeline_etag.graphql
'
;
import
{
resolvers
}
from
'
./graphql/resolvers
'
;
import
{
resolvers
}
from
'
./graphql/resolvers
'
;
import
typeDefs
from
'
./graphql/typedefs.graphql
'
;
import
typeDefs
from
'
./graphql/typedefs.graphql
'
;
...
@@ -82,6 +83,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
...
@@ -82,6 +83,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
},
},
});
});
cache
.
writeQuery
({
query
:
getLastCommitBranchQuery
,
data
:
{
lastCommitBranch
:
''
,
},
});
return
new
Vue
({
return
new
Vue
({
el
,
el
,
apolloProvider
,
apolloProvider
,
...
...
app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue
View file @
a9967814
...
@@ -252,7 +252,8 @@ export default {
...
@@ -252,7 +252,8 @@ export default {
.
getClient
()
.
getClient
()
.
writeQuery
({
query
:
getIsNewCiConfigFile
,
data
:
{
isNewCiConfigFile
:
false
}
});
.
writeQuery
({
query
:
getIsNewCiConfigFile
,
data
:
{
isNewCiConfigFile
:
false
}
});
}
}
// Keep track of the latest commited content to know
// Keep track of the latest committed content to know
// if the user has made changes to the file that are unsaved.
// if the user has made changes to the file that are unsaved.
this
.
lastCommittedContent
=
this
.
currentCiFileContent
;
this
.
lastCommittedContent
=
this
.
currentCiFileContent
;
},
},
...
...
spec/frontend/pipeline_editor/components/commit/commit_section_spec.js
View file @
a9967814
...
@@ -118,7 +118,8 @@ describe('Pipeline Editor | Commit section', () => {
...
@@ -118,7 +118,8 @@ describe('Pipeline Editor | Commit section', () => {
});
});
it
(
'
calls the mutation with the CREATE action
'
,
()
=>
{
it
(
'
calls the mutation with the CREATE action
'
,
()
=>
{
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
1
);
// the extra calls are for updating client queries (currentBranch and lastCommitBranch)
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
3
);
expect
(
mockMutate
).
toHaveBeenCalledWith
({
expect
(
mockMutate
).
toHaveBeenCalledWith
({
mutation
:
commitCreate
,
mutation
:
commitCreate
,
update
:
expect
.
any
(
Function
),
update
:
expect
.
any
(
Function
),
...
@@ -138,7 +139,7 @@ describe('Pipeline Editor | Commit section', () => {
...
@@ -138,7 +139,7 @@ describe('Pipeline Editor | Commit section', () => {
});
});
it
(
'
calls the mutation with the UPDATE action
'
,
()
=>
{
it
(
'
calls the mutation with the UPDATE action
'
,
()
=>
{
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
3
);
expect
(
mockMutate
).
toHaveBeenCalledWith
({
expect
(
mockMutate
).
toHaveBeenCalledWith
({
mutation
:
commitCreate
,
mutation
:
commitCreate
,
update
:
expect
.
any
(
Function
),
update
:
expect
.
any
(
Function
),
...
@@ -158,7 +159,7 @@ describe('Pipeline Editor | Commit section', () => {
...
@@ -158,7 +159,7 @@ describe('Pipeline Editor | Commit section', () => {
});
});
it
(
'
calls the mutation with the current branch
'
,
()
=>
{
it
(
'
calls the mutation with the current branch
'
,
()
=>
{
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
3
);
expect
(
mockMutate
).
toHaveBeenCalledWith
({
expect
(
mockMutate
).
toHaveBeenCalledWith
({
mutation
:
commitCreate
,
mutation
:
commitCreate
,
update
:
expect
.
any
(
Function
),
update
:
expect
.
any
(
Function
),
...
@@ -181,7 +182,7 @@ describe('Pipeline Editor | Commit section', () => {
...
@@ -181,7 +182,7 @@ describe('Pipeline Editor | Commit section', () => {
it
(
'
a second commit submits the latest sha, keeping the form updated
'
,
async
()
=>
{
it
(
'
a second commit submits the latest sha, keeping the form updated
'
,
async
()
=>
{
await
submitCommit
();
await
submitCommit
();
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
2
);
expect
(
mockMutate
).
toHaveBeenCalledTimes
(
6
);
expect
(
mockMutate
).
toHaveBeenCalledWith
({
expect
(
mockMutate
).
toHaveBeenCalledWith
({
mutation
:
commitCreate
,
mutation
:
commitCreate
,
update
:
expect
.
any
(
Function
),
update
:
expect
.
any
(
Function
),
...
...
spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
View file @
a9967814
...
@@ -11,7 +11,7 @@ import createMockApollo from 'helpers/mock_apollo_helper';
...
@@ -11,7 +11,7 @@ import createMockApollo from 'helpers/mock_apollo_helper';
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
BranchSwitcher
from
'
~/pipeline_editor/components/file_nav/branch_switcher.vue
'
;
import
BranchSwitcher
from
'
~/pipeline_editor/components/file_nav/branch_switcher.vue
'
;
import
{
DEFAULT_FAILURE
}
from
'
~/pipeline_editor/constants
'
;
import
{
DEFAULT_FAILURE
}
from
'
~/pipeline_editor/constants
'
;
import
getAvailableBranches
from
'
~/pipeline_editor/graphql/queries/available_branches.graphql
'
;
import
getAvailableBranches
Query
from
'
~/pipeline_editor/graphql/queries/available_branches.graphql
'
;
import
{
import
{
mockBranchPaginationLimit
,
mockBranchPaginationLimit
,
mockDefaultBranch
,
mockDefaultBranch
,
...
@@ -22,6 +22,7 @@ import {
...
@@ -22,6 +22,7 @@ import {
mockTotalBranches
,
mockTotalBranches
,
mockTotalBranchResults
,
mockTotalBranchResults
,
mockTotalSearchResults
,
mockTotalSearchResults
,
mockNewBranch
,
}
from
'
../../mock_data
'
;
}
from
'
../../mock_data
'
;
const
localVue
=
createLocalVue
();
const
localVue
=
createLocalVue
();
...
@@ -31,9 +32,12 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -31,9 +32,12 @@ describe('Pipeline editor branch switcher', () => {
let
wrapper
;
let
wrapper
;
let
mockApollo
;
let
mockApollo
;
let
mockAvailableBranchQuery
;
let
mockAvailableBranchQuery
;
let
mockCurrentBranchQuery
;
let
mockLastCommitBranchQuery
;
const
createComponent
=
(
const
createComponent
=
(
{
isQueryLoading
,
mountFn
,
options
}
=
{
{
currentBranch
,
isQueryLoading
,
mountFn
,
options
}
=
{
currentBranch
:
mockDefaultBranch
,
isQueryLoading
:
false
,
isQueryLoading
:
false
,
mountFn
:
shallowMount
,
mountFn
:
shallowMount
,
options
:
{},
options
:
{},
...
@@ -59,7 +63,7 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -59,7 +63,7 @@ describe('Pipeline editor branch switcher', () => {
data
()
{
data
()
{
return
{
return
{
availableBranches
:
[
'
main
'
],
availableBranches
:
[
'
main
'
],
currentBranch
:
mockDefaultBranch
,
currentBranch
,
};
};
},
},
...
options
,
...
options
,
...
@@ -67,8 +71,18 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -67,8 +71,18 @@ describe('Pipeline editor branch switcher', () => {
};
};
const
createComponentWithApollo
=
(
mountFn
=
shallowMount
)
=>
{
const
createComponentWithApollo
=
(
mountFn
=
shallowMount
)
=>
{
const
handlers
=
[[
getAvailableBranches
,
mockAvailableBranchQuery
]];
const
handlers
=
[[
getAvailableBranchesQuery
,
mockAvailableBranchQuery
]];
mockApollo
=
createMockApollo
(
handlers
);
const
resolvers
=
{
Query
:
{
currentBranch
()
{
return
mockCurrentBranchQuery
();
},
lastCommitBranch
()
{
return
mockLastCommitBranchQuery
();
},
},
};
mockApollo
=
createMockApollo
(
handlers
,
resolvers
);
createComponent
({
createComponent
({
mountFn
,
mountFn
,
...
@@ -76,11 +90,6 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -76,11 +90,6 @@ describe('Pipeline editor branch switcher', () => {
localVue
,
localVue
,
apolloProvider
:
mockApollo
,
apolloProvider
:
mockApollo
,
mocks
:
{},
mocks
:
{},
data
()
{
return
{
currentBranch
:
mockDefaultBranch
,
};
},
},
},
});
});
};
};
...
@@ -90,9 +99,24 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -90,9 +99,24 @@ describe('Pipeline editor branch switcher', () => {
const
findLoadingIcon
=
()
=>
wrapper
.
findComponent
(
GlLoadingIcon
);
const
findLoadingIcon
=
()
=>
wrapper
.
findComponent
(
GlLoadingIcon
);
const
findSearchBox
=
()
=>
wrapper
.
findComponent
(
GlSearchBoxByType
);
const
findSearchBox
=
()
=>
wrapper
.
findComponent
(
GlSearchBoxByType
);
const
findInfiniteScroll
=
()
=>
wrapper
.
findComponent
(
GlInfiniteScroll
);
const
findInfiniteScroll
=
()
=>
wrapper
.
findComponent
(
GlInfiniteScroll
);
const
defaultBranchInDropdown
=
()
=>
findDropdownItems
().
at
(
0
);
const
setMockResolvedValues
=
({
availableBranches
,
currentBranch
,
lastCommitBranch
})
=>
{
if
(
availableBranches
)
{
mockAvailableBranchQuery
.
mockResolvedValue
(
availableBranches
);
}
if
(
currentBranch
)
{
mockCurrentBranchQuery
.
mockResolvedValue
(
currentBranch
);
}
mockLastCommitBranchQuery
.
mockResolvedValue
(
lastCommitBranch
||
''
);
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mockAvailableBranchQuery
=
jest
.
fn
();
mockAvailableBranchQuery
=
jest
.
fn
();
mockCurrentBranchQuery
=
jest
.
fn
();
mockLastCommitBranchQuery
=
jest
.
fn
();
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -121,7 +145,10 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -121,7 +145,10 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
after querying
'
,
()
=>
{
describe
(
'
after querying
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
mockAvailableBranchQuery
.
mockResolvedValue
(
mockProjectBranches
);
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
(
mount
);
createComponentWithApollo
(
mount
);
await
waitForPromises
();
await
waitForPromises
();
});
});
...
@@ -136,10 +163,8 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -136,10 +163,8 @@ describe('Pipeline editor branch switcher', () => {
});
});
it
(
'
renders current branch with a check mark
'
,
()
=>
{
it
(
'
renders current branch with a check mark
'
,
()
=>
{
const
defaultBranchInDropdown
=
findDropdownItems
().
at
(
0
);
expect
(
defaultBranchInDropdown
().
text
()).
toBe
(
mockDefaultBranch
);
expect
(
defaultBranchInDropdown
().
props
(
'
isChecked
'
)).
toBe
(
true
);
expect
(
defaultBranchInDropdown
.
text
()).
toBe
(
mockDefaultBranch
);
expect
(
defaultBranchInDropdown
.
props
(
'
isChecked
'
)).
toBe
(
true
);
});
});
it
(
'
does not render check mark for other branches
'
,
()
=>
{
it
(
'
does not render check mark for other branches
'
,
()
=>
{
...
@@ -152,7 +177,10 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -152,7 +177,10 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
on fetch error
'
,
()
=>
{
describe
(
'
on fetch error
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
mockAvailableBranchQuery
.
mockResolvedValue
(
new
Error
());
setMockResolvedValues
({
availableBranches
:
new
Error
(),
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
();
createComponentWithApollo
();
await
waitForPromises
();
await
waitForPromises
();
});
});
...
@@ -169,7 +197,10 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -169,7 +197,10 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when switching branches
'
,
()
=>
{
describe
(
'
when switching branches
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
jest
.
spyOn
(
window
.
history
,
'
pushState
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
window
.
history
,
'
pushState
'
).
mockImplementation
(()
=>
{});
mockAvailableBranchQuery
.
mockResolvedValue
(
mockProjectBranches
);
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
(
mount
);
createComponentWithApollo
(
mount
);
await
waitForPromises
();
await
waitForPromises
();
});
});
...
@@ -216,7 +247,10 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -216,7 +247,10 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when searching
'
,
()
=>
{
describe
(
'
when searching
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
mockAvailableBranchQuery
.
mockResolvedValue
(
mockProjectBranches
);
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
(
mount
);
createComponentWithApollo
(
mount
);
await
waitForPromises
();
await
waitForPromises
();
});
});
...
@@ -316,7 +350,10 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -316,7 +350,10 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when scrolling to the bottom of the list
'
,
()
=>
{
describe
(
'
when scrolling to the bottom of the list
'
,
()
=>
{
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
mockAvailableBranchQuery
.
mockResolvedValue
(
mockProjectBranches
);
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
();
createComponentWithApollo
();
await
waitForPromises
();
await
waitForPromises
();
});
});
...
@@ -372,4 +409,35 @@ describe('Pipeline editor branch switcher', () => {
...
@@ -372,4 +409,35 @@ describe('Pipeline editor branch switcher', () => {
});
});
});
});
});
});
describe
(
'
when committing a new branch
'
,
()
=>
{
const
createNewBranch
=
async
()
=>
{
setMockResolvedValues
({
currentBranch
:
mockNewBranch
,
lastCommitBranch
:
mockNewBranch
,
});
await
wrapper
.
vm
.
$apollo
.
queries
.
currentBranch
.
refetch
();
await
wrapper
.
vm
.
$apollo
.
queries
.
lastCommitBranch
.
refetch
();
};
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
(
mount
);
await
waitForPromises
();
await
createNewBranch
();
});
it
(
'
sets new branch as current branch
'
,
()
=>
{
expect
(
defaultBranchInDropdown
().
text
()).
toBe
(
mockNewBranch
);
expect
(
defaultBranchInDropdown
().
props
(
'
isChecked
'
)).
toBe
(
true
);
});
it
(
'
adds new branch to branch switcher
'
,
()
=>
{
expect
(
defaultBranchInDropdown
().
text
()).
toBe
(
mockNewBranch
);
expect
(
findDropdownItems
()).
toHaveLength
(
mockTotalBranchResults
+
1
);
});
});
});
});
spec/frontend/pipeline_editor/mock_data.js
View file @
a9967814
...
@@ -5,6 +5,7 @@ export const mockProjectNamespace = 'user1';
...
@@ -5,6 +5,7 @@ export const mockProjectNamespace = 'user1';
export
const
mockProjectPath
=
'
project1
'
;
export
const
mockProjectPath
=
'
project1
'
;
export
const
mockProjectFullPath
=
`
${
mockProjectNamespace
}
/
${
mockProjectPath
}
`
;
export
const
mockProjectFullPath
=
`
${
mockProjectNamespace
}
/
${
mockProjectPath
}
`
;
export
const
mockDefaultBranch
=
'
main
'
;
export
const
mockDefaultBranch
=
'
main
'
;
export
const
mockNewBranch
=
'
new-branch
'
;
export
const
mockNewMergeRequestPath
=
'
/-/merge_requests/new
'
;
export
const
mockNewMergeRequestPath
=
'
/-/merge_requests/new
'
;
export
const
mockCommitSha
=
'
aabbccdd
'
;
export
const
mockCommitSha
=
'
aabbccdd
'
;
export
const
mockCommitNextSha
=
'
eeffgghh
'
;
export
const
mockCommitNextSha
=
'
eeffgghh
'
;
...
...
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