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
8ccbfa2f
Commit
8ccbfa2f
authored
Nov 06, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test updates
parent
f82af4bd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
172 deletions
+121
-172
app/assets/javascripts/repo/stores/actions.js
app/assets/javascripts/repo/stores/actions.js
+1
-1
spec/javascripts/helpers/vuex_action_helper.js
spec/javascripts/helpers/vuex_action_helper.js
+7
-44
spec/javascripts/repo/stores/actions/branch_spec.js
spec/javascripts/repo/stores/actions/branch_spec.js
+17
-24
spec/javascripts/repo/stores/actions_spec.js
spec/javascripts/repo/stores/actions_spec.js
+96
-103
No files found.
app/assets/javascripts/repo/stores/actions.js
View file @
8ccbfa2f
...
@@ -3,7 +3,7 @@ import flash from '../../flash';
...
@@ -3,7 +3,7 @@ import flash from '../../flash';
import
service
from
'
../services
'
;
import
service
from
'
../services
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
export
const
redirectToUrl
=
url
=>
gl
.
utils
.
visitUrl
(
url
);
export
const
redirectToUrl
=
(
_
,
url
)
=>
gl
.
utils
.
visitUrl
(
url
);
export
const
setInitialData
=
({
commit
},
data
)
=>
commit
(
types
.
SET_INITIAL_DATA
,
data
);
export
const
setInitialData
=
({
commit
},
data
)
=>
commit
(
types
.
SET_INITIAL_DATA
,
data
);
...
...
spec/javascripts/helpers/vuex_action_helper.js
View file @
8ccbfa2f
/* eslint-disable */
/* eslint-disable */
export
const
testWithDispatch
=
(
action
,
payload
,
state
,
expectedDispatch
,
done
)
=>
{
let
count
=
0
;
// mock commit
const
dispatch
=
(
type
,
payload
)
=>
{
const
dispatch
=
expectedDispatch
[
count
];
try
{
expect
(
dispatch
.
type
).
toEqual
(
type
);
if
(
payload
!==
null
)
{
expect
(
dispatch
.
payload
).
toEqual
(
payload
);
}
}
catch
(
error
)
{
done
.
fail
(
error
);
}
count
++
;
if
(
count
>=
expectedDispatch
.
length
)
{
done
();
}
};
// call the action with mocked store and arguments
action
({
dispatch
,
state
},
payload
);
// check if no mutations should have been dispatched
if
(
expectedDispatch
.
length
===
0
)
{
expect
(
count
).
to
.
equal
(
0
);
done
();
}
};
/**
/**
* helper for testing action with expected mutations
* helper for testing action with expected mutations
* https://vuex.vuejs.org/en/testing.html
* https://vuex.vuejs.org/en/testing.html
...
@@ -44,31 +12,26 @@ export default (action, payload, state, expectedMutations, done) => {
...
@@ -44,31 +12,26 @@ export default (action, payload, state, expectedMutations, done) => {
const
mutation
=
expectedMutations
[
count
];
const
mutation
=
expectedMutations
[
count
];
try
{
try
{
expect
(
mutation
.
type
).
to
E
qual
(
type
);
expect
(
mutation
.
type
).
to
.
e
qual
(
type
);
if
(
payload
!==
null
)
{
if
(
payload
)
{
expect
(
mutation
.
payload
).
to
E
qual
(
payload
);
expect
(
mutation
.
payload
).
to
.
deep
.
e
qual
(
payload
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
if
(
done
)
{
done
(
error
);
done
.
fail
(
error
);
}
}
}
count
++
;
count
++
;
if
(
count
>=
expectedMutations
.
length
&&
done
)
{
if
(
count
>=
expectedMutations
.
length
)
{
done
();
done
();
}
}
};
};
// call the action with mocked store and arguments
// call the action with mocked store and arguments
return
action
({
commit
,
state
},
payload
);
action
({
commit
,
state
},
payload
);
// check if no mutations should have been dispatched
// check if no mutations should have been dispatched
if
(
expectedMutations
.
length
===
0
)
{
if
(
expectedMutations
.
length
===
0
)
{
expect
(
count
).
to
.
equal
(
0
);
expect
(
count
).
to
.
equal
(
0
);
done
();
if
(
done
)
{
done
();
}
}
}
};
};
spec/javascripts/repo/stores/actions/branch_spec.js
View file @
8ccbfa2f
import
*
as
actions
from
'
~/repo/stores/actions/branch
'
;
import
store
from
'
~/repo/stores
'
;
import
state
from
'
~/repo/stores/state
'
;
import
service
from
'
~/repo/services
'
;
import
service
from
'
~/repo/services
'
;
import
testAction
from
'
../../../helpers/vuex_action_helper
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
describe
(
'
Multi-file store branch actions
'
,
()
=>
{
describe
(
'
Multi-file store branch actions
'
,
()
=>
{
let
localState
;
afterEach
(()
=>
{
resetStore
(
store
);
beforeEach
(()
=>
{
localState
=
state
();
});
});
describe
(
'
createNewBranch
'
,
()
=>
{
describe
(
'
createNewBranch
'
,
()
=>
{
...
@@ -19,27 +16,23 @@ describe('Multi-file store branch actions', () => {
...
@@ -19,27 +16,23 @@ describe('Multi-file store branch actions', () => {
}));
}));
spyOn
(
history
,
'
pushState
'
);
spyOn
(
history
,
'
pushState
'
);
localS
tate
.
project
.
id
=
2
;
store
.
s
tate
.
project
.
id
=
2
;
localS
tate
.
currentBranch
=
'
testing
'
;
store
.
s
tate
.
currentBranch
=
'
testing
'
;
});
});
it
(
'
creates new branch
'
,
(
done
)
=>
{
it
(
'
creates new branch
'
,
(
done
)
=>
{
testAction
(
store
.
dispatch
(
'
createNewBranch
'
,
'
master
'
)
actions
.
createNewBranch
,
.
then
(()
=>
{
'
master
'
,
expect
(
store
.
state
.
currentBranch
).
toBe
(
'
testing
'
);
localState
,
expect
(
service
.
createBranch
).
toHaveBeenCalledWith
(
2
,
{
[
branch
:
'
master
'
,
{
type
:
'
SET_CURRENT_BRANCH
'
,
payload
:
'
testing
'
},
ref
:
'
testing
'
,
],
});
).
then
(()
=>
{
expect
(
history
.
pushState
).
toHaveBeenCalled
();
expect
(
service
.
createBranch
).
toHaveBeenCalledWith
(
2
,
{
branch
:
'
master
'
,
ref
:
'
testing
'
,
});
expect
(
history
.
pushState
).
toHaveBeenCalled
();
done
();
done
();
}).
catch
(
done
.
fail
);
})
.
catch
(
done
.
fail
);
});
});
});
});
});
});
spec/javascripts/repo/stores/actions_spec.js
View file @
8ccbfa2f
import
*
as
actions
from
'
~/repo/stores/actions
'
;
import
store
from
'
~/repo/stores
'
;
import
state
from
'
~/repo/stores/state
'
;
import
service
from
'
~/repo/services
'
;
import
service
from
'
~/repo/services
'
;
import
testAction
,
{
testWithDispatch
}
from
'
../../helpers/vuex_action_helper
'
;
import
{
resetStore
,
file
}
from
'
../helpers
'
;
import
{
file
}
from
'
../helpers
'
;
describe
(
'
Multi-file store actions
'
,
()
=>
{
describe
(
'
Multi-file store actions
'
,
()
=>
{
let
localState
;
afterEach
(()
=>
{
resetStore
(
store
);
beforeEach
(()
=>
{
localState
=
state
();
});
});
describe
(
'
redirectToUrl
'
,
()
=>
{
describe
(
'
redirectToUrl
'
,
()
=>
{
it
(
'
calls visitUrl
'
,
()
=>
{
it
(
'
calls visitUrl
'
,
(
done
)
=>
{
spyOn
(
gl
.
utils
,
'
visitUrl
'
);
spyOn
(
gl
.
utils
,
'
visitUrl
'
);
actions
.
redirectToUrl
(
'
test
'
);
store
.
dispatch
(
'
redirectToUrl
'
,
'
test
'
)
.
then
(()
=>
{
expect
(
gl
.
utils
.
visitUrl
).
toHaveBeenCalledWith
(
'
test
'
);
expect
(
gl
.
utils
.
visitUrl
).
toHaveBeenCalledWith
(
'
test
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
});
});
describe
(
'
setInitialData
'
,
()
=>
{
describe
(
'
setInitialData
'
,
()
=>
{
it
(
'
commits initial data
'
,
(
done
)
=>
{
it
(
'
commits initial data
'
,
(
done
)
=>
{
testAction
(
store
.
dispatch
(
'
setInitialData
'
,
{
canCommit
:
true
})
actions
.
setInitialData
,
.
then
(()
=>
{
{
canCommit
:
true
},
expect
(
store
.
state
.
canCommit
).
toBeTruthy
();
localState
,
done
();
[
})
{
type
:
'
SET_INITIAL_DATA
'
,
payload
:
{
canCommit
:
true
}
},
.
catch
(
done
.
fail
);
],
done
,
);
});
});
});
});
describe
(
'
closeDiscardPopup
'
,
()
=>
{
describe
(
'
closeDiscardPopup
'
,
()
=>
{
it
(
'
closes the discard popup
'
,
(
done
)
=>
{
it
(
'
closes the discard popup
'
,
(
done
)
=>
{
testAction
(
store
.
dispatch
(
'
closeDiscardPopup
'
,
false
)
actions
.
closeDiscardPopup
,
.
then
(()
=>
{
false
,
expect
(
store
.
state
.
discardPopupOpen
).
toBeFalsy
();
localState
,
[
done
();
{
type
:
'
TOGGLE_DISCARD_POPUP
'
,
payload
:
false
},
})
],
.
catch
(
done
.
fail
);
done
,
);
});
});
});
});
describe
(
'
discardAllChanges
'
,
()
=>
{
describe
(
'
discardAllChanges
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
localS
tate
.
openFiles
.
push
(
file
());
store
.
s
tate
.
openFiles
.
push
(
file
());
localS
tate
.
openFiles
[
0
].
changed
=
true
;
store
.
s
tate
.
openFiles
[
0
].
changed
=
true
;
});
});
});
});
describe
(
'
closeAllFiles
'
,
()
=>
{
describe
(
'
closeAllFiles
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
localS
tate
.
openFiles
.
push
(
file
());
store
.
s
tate
.
openFiles
.
push
(
file
());
localState
.
openFiles
[
0
].
chang
ed
=
true
;
store
.
state
.
openFiles
[
0
].
open
ed
=
true
;
});
});
it
(
'
closes all open files
'
,
(
done
)
=>
{
it
(
'
closes all open files
'
,
(
done
)
=>
{
testWithDispatch
(
store
.
dispatch
(
'
closeAllFiles
'
)
actions
.
closeAllFiles
,
.
then
(()
=>
{
localState
.
openFiles
[
0
],
expect
(
store
.
state
.
openFiles
.
length
).
toBe
(
0
);
localState
,
[
done
();
{
type
:
'
closeFile
'
,
payload
:
{
file
:
localState
.
openFiles
[
0
]
}
},
})
],
.
catch
(
done
.
fail
);
done
,
);
});
});
});
});
...
@@ -81,47 +74,47 @@ describe('Multi-file store actions', () => {
...
@@ -81,47 +74,47 @@ describe('Multi-file store actions', () => {
describe
(
'
toggleBlobView
'
,
()
=>
{
describe
(
'
toggleBlobView
'
,
()
=>
{
it
(
'
sets edit mode view if in edit mode
'
,
(
done
)
=>
{
it
(
'
sets edit mode view if in edit mode
'
,
(
done
)
=>
{
localState
.
editMode
=
true
;
store
.
state
.
editMode
=
true
;
testAction
(
store
.
dispatch
(
'
toggleBlobView
'
)
actions
.
toggleBlobView
,
.
then
(()
=>
{
null
,
expect
(
store
.
state
.
currentBlobView
).
toBe
(
'
repo-editor
'
);
localState
,
[
done
();
{
type
:
'
SET_EDIT_MODE
'
},
})
],
.
catch
(
done
.
fail
);
done
,
);
});
});
it
(
'
sets preview mode view if not in edit mode
'
,
(
done
)
=>
{
it
(
'
sets preview mode view if not in edit mode
'
,
(
done
)
=>
{
testAction
(
store
.
dispatch
(
'
toggleBlobView
'
)
actions
.
toggleBlobView
,
.
then
(()
=>
{
null
,
expect
(
store
.
state
.
currentBlobView
).
toBe
(
'
repo-preview
'
);
localState
,
[
done
();
{
type
:
'
SET_PREVIEW_MODE
'
},
})
],
.
catch
(
done
.
fail
);
done
,
);
});
});
});
});
describe
(
'
checkCommitStatus
'
,
()
=>
{
describe
(
'
checkCommitStatus
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
localS
tate
.
project
.
id
=
2
;
store
.
s
tate
.
project
.
id
=
2
;
localS
tate
.
currentBranch
=
'
master
'
;
store
.
s
tate
.
currentBranch
=
'
master
'
;
localS
tate
.
currentRef
=
'
1
'
;
store
.
s
tate
.
currentRef
=
'
1
'
;
});
});
it
(
'
calls service
'
,
()
=>
{
it
(
'
calls service
'
,
(
done
)
=>
{
spyOn
(
service
,
'
getBranchData
'
).
and
.
returnValue
(
Promise
.
resolve
({
spyOn
(
service
,
'
getBranchData
'
).
and
.
returnValue
(
Promise
.
resolve
({
commit
:
{
id
:
'
123
'
},
commit
:
{
id
:
'
123
'
},
}));
}));
actions
.
checkCommitStatus
({
state
:
localState
});
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
(()
=>
{
expect
(
service
.
getBranchData
).
toHaveBeenCalledWith
(
2
,
'
master
'
);
expect
(
service
.
getBranchData
).
toHaveBeenCalledWith
(
2
,
'
master
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
it
(
'
returns true if current ref does not equal returned ID
'
,
(
done
)
=>
{
it
(
'
returns true if current ref does not equal returned ID
'
,
(
done
)
=>
{
...
@@ -129,7 +122,7 @@ describe('Multi-file store actions', () => {
...
@@ -129,7 +122,7 @@ describe('Multi-file store actions', () => {
commit
:
{
id
:
'
123
'
},
commit
:
{
id
:
'
123
'
},
}));
}));
actions
.
checkCommitStatus
({
state
:
localState
}
)
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
((
val
)
=>
{
.
then
((
val
)
=>
{
expect
(
val
).
toBeTruthy
();
expect
(
val
).
toBeTruthy
();
...
@@ -143,7 +136,7 @@ describe('Multi-file store actions', () => {
...
@@ -143,7 +136,7 @@ describe('Multi-file store actions', () => {
commit
:
{
id
:
'
1
'
},
commit
:
{
id
:
'
1
'
},
}));
}));
actions
.
checkCommitStatus
({
state
:
localState
}
)
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
((
val
)
=>
{
.
then
((
val
)
=>
{
expect
(
val
).
toBeFalsy
();
expect
(
val
).
toBeFalsy
();
...
@@ -159,35 +152,33 @@ describe('Multi-file store actions', () => {
...
@@ -159,35 +152,33 @@ describe('Multi-file store actions', () => {
describe
(
'
createTempEntry
'
,
()
=>
{
describe
(
'
createTempEntry
'
,
()
=>
{
it
(
'
creates a temp tree
'
,
(
done
)
=>
{
it
(
'
creates a temp tree
'
,
(
done
)
=>
{
testWithDispatch
(
store
.
dispatch
(
'
createTempEntry
'
,
{
actions
.
createTempEntry
,
name
:
'
test
'
,
{
name
:
'
test
'
,
type
:
'
tree
'
},
type
:
'
tree
'
,
localState
,
})
[
.
then
(()
=>
{
{
type
:
'
createTempTree
'
,
payload
:
'
test
'
},
expect
(
store
.
state
.
tree
.
length
).
toBe
(
1
);
],
expect
(
store
.
state
.
tree
[
0
].
tempFile
).
toBeTruthy
();
done
,
expect
(
store
.
state
.
tree
[
0
].
type
).
toBe
(
'
tree
'
);
);
done
();
})
.
catch
(
done
.
fail
);
});
});
it
(
'
creates temp file
'
,
(
done
)
=>
{
it
(
'
creates temp file
'
,
(
done
)
=>
{
testWithDispatch
(
store
.
dispatch
(
'
createTempEntry
'
,
{
actions
.
createTempEntry
,
name
:
'
test
'
,
{
name
:
'
test
'
,
type
:
'
blob
'
},
type
:
'
blob
'
,
localState
,
})
[
.
then
(()
=>
{
{
expect
(
store
.
state
.
tree
.
length
).
toBe
(
1
);
type
:
'
createTempFile
'
,
expect
(
store
.
state
.
tree
[
0
].
tempFile
).
toBeTruthy
();
payload
:
{
expect
(
store
.
state
.
tree
[
0
].
type
).
toBe
(
'
blob
'
);
tree
:
localState
,
name
:
'
test
'
,
done
();
base64
:
false
,
})
content
:
''
,
.
catch
(
done
.
fail
);
},
},
],
done
,
);
});
});
});
});
...
@@ -201,15 +192,17 @@ describe('Multi-file store actions', () => {
...
@@ -201,15 +192,17 @@ describe('Multi-file store actions', () => {
const
el
=
document
.
querySelector
(
'
.repo-tab
'
);
const
el
=
document
.
querySelector
(
'
.repo-tab
'
);
spyOn
(
el
,
'
focus
'
);
spyOn
(
el
,
'
focus
'
);
actions
.
scrollToTab
();
store
.
dispatch
(
'
scrollToTab
'
)
.
then
(()
=>
{
setTimeout
(()
=>
{
expect
(
el
.
focus
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
document
.
getElementById
(
'
tabs
'
).
remove
();
expect
(
el
.
focus
).
toHaveBeenCalled
();
document
.
getElementById
(
'
tabs
'
).
remov
e
();
don
e
();
});
done
();
})
}
);
.
catch
(
done
.
fail
);
});
});
});
});
});
});
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