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
Show 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';
import
service
from
'
../services
'
;
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
);
...
...
spec/javascripts/helpers/vuex_action_helper.js
View file @
8ccbfa2f
/* 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
* https://vuex.vuejs.org/en/testing.html
...
...
@@ -44,31 +12,26 @@ export default (action, payload, state, expectedMutations, done) => {
const
mutation
=
expectedMutations
[
count
];
try
{
expect
(
mutation
.
type
).
to
E
qual
(
type
);
if
(
payload
!==
null
)
{
expect
(
mutation
.
payload
).
to
E
qual
(
payload
);
expect
(
mutation
.
type
).
to
.
e
qual
(
type
);
if
(
payload
)
{
expect
(
mutation
.
payload
).
to
.
deep
.
e
qual
(
payload
);
}
}
catch
(
error
)
{
if
(
done
)
{
done
.
fail
(
error
);
}
done
(
error
);
}
count
++
;
if
(
count
>=
expectedMutations
.
length
&&
done
)
{
if
(
count
>=
expectedMutations
.
length
)
{
done
();
}
};
// 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
if
(
expectedMutations
.
length
===
0
)
{
expect
(
count
).
to
.
equal
(
0
);
if
(
done
)
{
done
();
}
}
};
spec/javascripts/repo/stores/actions/branch_spec.js
View file @
8ccbfa2f
import
*
as
actions
from
'
~/repo/stores/actions/branch
'
;
import
state
from
'
~/repo/stores/state
'
;
import
store
from
'
~/repo/stores
'
;
import
service
from
'
~/repo/services
'
;
import
testAction
from
'
../../../helpers/vuex_action_helper
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
describe
(
'
Multi-file store branch actions
'
,
()
=>
{
let
localState
;
beforeEach
(()
=>
{
localState
=
state
();
afterEach
(()
=>
{
resetStore
(
store
);
});
describe
(
'
createNewBranch
'
,
()
=>
{
...
...
@@ -19,19 +16,14 @@ describe('Multi-file store branch actions', () => {
}));
spyOn
(
history
,
'
pushState
'
);
localS
tate
.
project
.
id
=
2
;
localS
tate
.
currentBranch
=
'
testing
'
;
store
.
s
tate
.
project
.
id
=
2
;
store
.
s
tate
.
currentBranch
=
'
testing
'
;
});
it
(
'
creates new branch
'
,
(
done
)
=>
{
testAction
(
actions
.
createNewBranch
,
'
master
'
,
localState
,
[
{
type
:
'
SET_CURRENT_BRANCH
'
,
payload
:
'
testing
'
},
],
).
then
(()
=>
{
store
.
dispatch
(
'
createNewBranch
'
,
'
master
'
)
.
then
(()
=>
{
expect
(
store
.
state
.
currentBranch
).
toBe
(
'
testing
'
);
expect
(
service
.
createBranch
).
toHaveBeenCalledWith
(
2
,
{
branch
:
'
master
'
,
ref
:
'
testing
'
,
...
...
@@ -39,7 +31,8 @@ describe('Multi-file store branch actions', () => {
expect
(
history
.
pushState
).
toHaveBeenCalled
();
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
state
from
'
~/repo/stores/state
'
;
import
store
from
'
~/repo/stores
'
;
import
service
from
'
~/repo/services
'
;
import
testAction
,
{
testWithDispatch
}
from
'
../../helpers/vuex_action_helper
'
;
import
{
file
}
from
'
../helpers
'
;
import
{
resetStore
,
file
}
from
'
../helpers
'
;
describe
(
'
Multi-file store actions
'
,
()
=>
{
let
localState
;
beforeEach
(()
=>
{
localState
=
state
();
afterEach
(()
=>
{
resetStore
(
store
);
});
describe
(
'
redirectToUrl
'
,
()
=>
{
it
(
'
calls visitUrl
'
,
()
=>
{
it
(
'
calls visitUrl
'
,
(
done
)
=>
{
spyOn
(
gl
.
utils
,
'
visitUrl
'
);
actions
.
redirectToUrl
(
'
test
'
);
store
.
dispatch
(
'
redirectToUrl
'
,
'
test
'
)
.
then
(()
=>
{
expect
(
gl
.
utils
.
visitUrl
).
toHaveBeenCalledWith
(
'
test
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
setInitialData
'
,
()
=>
{
it
(
'
commits initial data
'
,
(
done
)
=>
{
testAction
(
actions
.
setInitialData
,
{
canCommit
:
true
},
localState
,
[
{
type
:
'
SET_INITIAL_DATA
'
,
payload
:
{
canCommit
:
true
}
},
],
done
,
);
store
.
dispatch
(
'
setInitialData
'
,
{
canCommit
:
true
})
.
then
(()
=>
{
expect
(
store
.
state
.
canCommit
).
toBeTruthy
();
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
closeDiscardPopup
'
,
()
=>
{
it
(
'
closes the discard popup
'
,
(
done
)
=>
{
testAction
(
actions
.
closeDiscardPopup
,
false
,
localState
,
[
{
type
:
'
TOGGLE_DISCARD_POPUP
'
,
payload
:
false
},
],
done
,
);
store
.
dispatch
(
'
closeDiscardPopup
'
,
false
)
.
then
(()
=>
{
expect
(
store
.
state
.
discardPopupOpen
).
toBeFalsy
();
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
discardAllChanges
'
,
()
=>
{
beforeEach
(()
=>
{
localS
tate
.
openFiles
.
push
(
file
());
localS
tate
.
openFiles
[
0
].
changed
=
true
;
store
.
s
tate
.
openFiles
.
push
(
file
());
store
.
s
tate
.
openFiles
[
0
].
changed
=
true
;
});
});
describe
(
'
closeAllFiles
'
,
()
=>
{
beforeEach
(()
=>
{
localS
tate
.
openFiles
.
push
(
file
());
localState
.
openFiles
[
0
].
chang
ed
=
true
;
store
.
s
tate
.
openFiles
.
push
(
file
());
store
.
state
.
openFiles
[
0
].
open
ed
=
true
;
});
it
(
'
closes all open files
'
,
(
done
)
=>
{
testWithDispatch
(
actions
.
closeAllFiles
,
localState
.
openFiles
[
0
],
localState
,
[
{
type
:
'
closeFile
'
,
payload
:
{
file
:
localState
.
openFiles
[
0
]
}
},
],
done
,
);
store
.
dispatch
(
'
closeAllFiles
'
)
.
then
(()
=>
{
expect
(
store
.
state
.
openFiles
.
length
).
toBe
(
0
);
done
();
})
.
catch
(
done
.
fail
);
});
});
...
...
@@ -81,47 +74,47 @@ describe('Multi-file store actions', () => {
describe
(
'
toggleBlobView
'
,
()
=>
{
it
(
'
sets edit mode view if in edit mode
'
,
(
done
)
=>
{
localS
tate
.
editMode
=
true
;
store
.
s
tate
.
editMode
=
true
;
testAction
(
actions
.
toggleBlobView
,
null
,
localState
,
[
{
type
:
'
SET_EDIT_MODE
'
},
],
done
,
);
store
.
dispatch
(
'
toggleBlobView
'
)
.
then
(()
=>
{
expect
(
store
.
state
.
currentBlobView
).
toBe
(
'
repo-editor
'
);
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'
sets preview mode view if not in edit mode
'
,
(
done
)
=>
{
testAction
(
actions
.
toggleBlobView
,
null
,
localState
,
[
{
type
:
'
SET_PREVIEW_MODE
'
},
],
done
,
);
store
.
dispatch
(
'
toggleBlobView
'
)
.
then
(()
=>
{
expect
(
store
.
state
.
currentBlobView
).
toBe
(
'
repo-preview
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
checkCommitStatus
'
,
()
=>
{
beforeEach
(()
=>
{
localS
tate
.
project
.
id
=
2
;
localS
tate
.
currentBranch
=
'
master
'
;
localS
tate
.
currentRef
=
'
1
'
;
store
.
s
tate
.
project
.
id
=
2
;
store
.
s
tate
.
currentBranch
=
'
master
'
;
store
.
s
tate
.
currentRef
=
'
1
'
;
});
it
(
'
calls service
'
,
()
=>
{
it
(
'
calls service
'
,
(
done
)
=>
{
spyOn
(
service
,
'
getBranchData
'
).
and
.
returnValue
(
Promise
.
resolve
({
commit
:
{
id
:
'
123
'
},
}));
actions
.
checkCommitStatus
({
state
:
localState
});
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
(()
=>
{
expect
(
service
.
getBranchData
).
toHaveBeenCalledWith
(
2
,
'
master
'
);
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'
returns true if current ref does not equal returned ID
'
,
(
done
)
=>
{
...
...
@@ -129,7 +122,7 @@ describe('Multi-file store actions', () => {
commit
:
{
id
:
'
123
'
},
}));
actions
.
checkCommitStatus
({
state
:
localState
}
)
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
((
val
)
=>
{
expect
(
val
).
toBeTruthy
();
...
...
@@ -143,7 +136,7 @@ describe('Multi-file store actions', () => {
commit
:
{
id
:
'
1
'
},
}));
actions
.
checkCommitStatus
({
state
:
localState
}
)
store
.
dispatch
(
'
checkCommitStatus
'
)
.
then
((
val
)
=>
{
expect
(
val
).
toBeFalsy
();
...
...
@@ -159,35 +152,33 @@ describe('Multi-file store actions', () => {
describe
(
'
createTempEntry
'
,
()
=>
{
it
(
'
creates a temp tree
'
,
(
done
)
=>
{
testWithDispatch
(
actions
.
createTempEntry
,
{
name
:
'
test
'
,
type
:
'
tree
'
},
localState
,
[
{
type
:
'
createTempTree
'
,
payload
:
'
test
'
},
],
done
,
);
store
.
dispatch
(
'
createTempEntry
'
,
{
name
:
'
test
'
,
type
:
'
tree
'
,
})
.
then
(()
=>
{
expect
(
store
.
state
.
tree
.
length
).
toBe
(
1
);
expect
(
store
.
state
.
tree
[
0
].
tempFile
).
toBeTruthy
();
expect
(
store
.
state
.
tree
[
0
].
type
).
toBe
(
'
tree
'
);
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'
creates temp file
'
,
(
done
)
=>
{
testWithDispatch
(
actions
.
createTempEntry
,
{
name
:
'
test
'
,
type
:
'
blob
'
},
localState
,
[
{
type
:
'
createTempFile
'
,
payload
:
{
tree
:
localState
,
store
.
dispatch
(
'
createTempEntry
'
,
{
name
:
'
test
'
,
base64
:
false
,
content
:
''
,
},
},
],
done
,
);
type
:
'
blob
'
,
})
.
then
(()
=>
{
expect
(
store
.
state
.
tree
.
length
).
toBe
(
1
);
expect
(
store
.
state
.
tree
[
0
].
tempFile
).
toBeTruthy
();
expect
(
store
.
state
.
tree
[
0
].
type
).
toBe
(
'
blob
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
...
...
@@ -201,8 +192,8 @@ describe('Multi-file store actions', () => {
const
el
=
document
.
querySelector
(
'
.repo-tab
'
);
spyOn
(
el
,
'
focus
'
);
actions
.
scrollToTab
();
store
.
dispatch
(
'
scrollToTab
'
)
.
then
(()
=>
{
setTimeout
(()
=>
{
expect
(
el
.
focus
).
toHaveBeenCalled
();
...
...
@@ -210,6 +201,8 @@ describe('Multi-file store actions', () => {
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