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
Boxiang Sun
gitlab-ce
Commits
470b8ca1
Commit
470b8ca1
authored
Mar 29, 2018
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dispatch mock to the test helper
parent
e26d2031
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
12 deletions
+62
-12
spec/javascripts/helpers/vuex_action_helper.js
spec/javascripts/helpers/vuex_action_helper.js
+47
-10
spec/javascripts/notes/stores/actions_spec.js
spec/javascripts/notes/stores/actions_spec.js
+11
-2
spec/javascripts/registry/stores/actions_spec.js
spec/javascripts/registry/stores/actions_spec.js
+4
-0
No files found.
spec/javascripts/helpers/vuex_action_helper.js
View file @
470b8ca1
/* eslint-disable */
/**
* helper for testing action with expected mutations
* helper for testing action with expected mutations
inspired in
* https://vuex.vuejs.org/en/testing.html
*
* @example
* testAction(
* actions.actionName, // action
* { }, // mocked response
* state, // state
* [
* { type: types.MUTATION}
* { type: types.MUTATION_1, payload: {}}
* ], // mutations
* [
* { type: 'actionName', payload: {}},
* { type: 'actionName1', payload: {}}
* ] //actions
* done,
* );
*/
export
default
(
action
,
payload
,
state
,
expectedMutations
,
done
)
=>
{
let
count
=
0
;
export
default
(
action
,
payload
,
state
,
expectedMutations
,
expectedActions
,
done
)
=>
{
let
mutationsCount
=
0
;
let
actionsCount
=
0
;
// mock commit
const
commit
=
(
type
,
mutationPayload
)
=>
{
const
mutation
=
expectedMutations
[
c
ount
];
const
mutation
=
expectedMutations
[
mutationsC
ount
];
expect
(
mutation
.
type
).
toEqual
(
type
);
...
...
@@ -17,18 +32,40 @@ export default (action, payload, state, expectedMutations, done) => {
expect
(
mutation
.
payload
).
toEqual
(
mutationPayload
);
}
count
++
;
if
(
count
>=
expectedMutations
.
length
)
{
mutationsCount
+=
1
;
if
(
mutationsCount
>=
expectedMutations
.
length
)
{
done
();
}
};
// mock dispatch
const
dispatch
=
(
type
,
actionPayload
)
=>
{
const
actionExpected
=
expectedActions
[
actionsCount
];
expect
(
actionExpected
.
type
).
toEqual
(
type
);
if
(
actionExpected
.
payload
)
{
expect
(
actionExpected
.
payload
).
toEqual
(
actionPayload
);
}
actionsCount
+=
1
;
if
(
actionsCount
>=
expectedActions
.
length
)
{
done
();
}
};
// call the action with mocked store and arguments
action
({
commit
,
state
},
payload
);
action
({
commit
,
state
,
dispatch
},
payload
);
// check if no mutations should have been dispatched
if
(
expectedMutations
.
length
===
0
)
{
expect
(
count
).
toEqual
(
0
);
expect
(
mutationsCount
).
toEqual
(
0
);
done
();
}
// check if no mutations should have been dispatched
if
(
expectedActions
.
length
===
0
)
{
expect
(
actionsCount
).
toEqual
(
0
);
done
();
}
};
spec/javascripts/notes/stores/actions_spec.js
View file @
470b8ca1
...
...
@@ -25,6 +25,7 @@ describe('Actions Notes Store', () => {
notesDataMock
,
{
notesData
:
{}
},
[{
type
:
'
SET_NOTES_DATA
'
,
payload
:
notesDataMock
}],
[],
done
,
);
});
...
...
@@ -37,6 +38,7 @@ describe('Actions Notes Store', () => {
noteableDataMock
,
{
noteableData
:
{}
},
[{
type
:
'
SET_NOTEABLE_DATA
'
,
payload
:
noteableDataMock
}],
[],
done
,
);
});
...
...
@@ -49,6 +51,7 @@ describe('Actions Notes Store', () => {
userDataMock
,
{
userData
:
{}
},
[{
type
:
'
SET_USER_DATA
'
,
payload
:
userDataMock
}],
[],
done
,
);
});
...
...
@@ -61,6 +64,7 @@ describe('Actions Notes Store', () => {
'
timestamp
'
,
{
lastFetchedAt
:
{}
},
[{
type
:
'
SET_LAST_FETCHED_AT
'
,
payload
:
'
timestamp
'
}],
[],
done
,
);
});
...
...
@@ -73,6 +77,7 @@ describe('Actions Notes Store', () => {
[
individualNote
],
{
notes
:
[]
},
[{
type
:
'
SET_INITIAL_NOTES
'
,
payload
:
[
individualNote
]
}],
[],
done
,
);
});
...
...
@@ -85,6 +90,7 @@ describe('Actions Notes Store', () => {
'
hash
'
,
{
notes
:
[]
},
[{
type
:
'
SET_TARGET_NOTE_HASH
'
,
payload
:
'
hash
'
}],
[],
done
,
);
});
...
...
@@ -97,6 +103,7 @@ describe('Actions Notes Store', () => {
{
discussionId
:
discussionMock
.
id
},
{
notes
:
[
discussionMock
]
},
[{
type
:
'
TOGGLE_DISCUSSION
'
,
payload
:
{
discussionId
:
discussionMock
.
id
}
}],
[],
done
,
);
});
...
...
@@ -164,6 +171,7 @@ describe('Actions Notes Store', () => {
true
,
{},
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
true
}],
[],
done
,
);
});
...
...
@@ -174,6 +182,7 @@ describe('Actions Notes Store', () => {
false
,
{},
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
false
}],
[],
done
,
);
});
...
...
@@ -181,11 +190,11 @@ describe('Actions Notes Store', () => {
describe
(
'
toggleIssueLocalState
'
,
()
=>
{
it
(
'
sets issue state as closed
'
,
done
=>
{
testAction
(
actions
.
toggleIssueLocalState
,
'
closed
'
,
{},
[{
type
:
'
CLOSE_ISSUE
'
}],
done
);
testAction
(
actions
.
toggleIssueLocalState
,
'
closed
'
,
{},
[{
type
:
'
CLOSE_ISSUE
'
}],
[],
done
);
});
it
(
'
sets issue state as reopened
'
,
done
=>
{
testAction
(
actions
.
toggleIssueLocalState
,
'
reopened
'
,
{},
[{
type
:
'
REOPEN_ISSUE
'
}],
done
);
testAction
(
actions
.
toggleIssueLocalState
,
'
reopened
'
,
{},
[{
type
:
'
REOPEN_ISSUE
'
}],
[],
done
);
});
});
...
...
spec/javascripts/registry/stores/actions_spec.js
View file @
470b8ca1
...
...
@@ -49,6 +49,7 @@ describe('Actions Registry Store', () => {
{
type
:
types
.
TOGGLE_MAIN_LOADING
},
{
type
:
types
.
SET_REPOS_LIST
,
payload
:
reposServerResponse
},
],
[],
done
,
);
});
...
...
@@ -88,6 +89,7 @@ describe('Actions Registry Store', () => {
},
},
],
[],
done
,
);
});
...
...
@@ -101,6 +103,7 @@ describe('Actions Registry Store', () => {
'
endpoint
'
,
mockedState
,
[{
type
:
types
.
SET_MAIN_ENDPOINT
,
payload
:
'
endpoint
'
}],
[],
done
,
);
});
...
...
@@ -113,6 +116,7 @@ describe('Actions Registry Store', () => {
null
,
mockedState
,
[{
type
:
types
.
TOGGLE_MAIN_LOADING
}],
[],
done
,
);
});
...
...
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