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
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
* 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
)
=>
{
export
default
(
action
,
payload
,
state
,
expectedMutations
,
expectedActions
,
done
)
=>
{
let
count
=
0
;
let
mutationsCount
=
0
;
let
actionsCount
=
0
;
// mock commit
// mock commit
const
commit
=
(
type
,
mutationPayload
)
=>
{
const
commit
=
(
type
,
mutationPayload
)
=>
{
const
mutation
=
expectedMutations
[
c
ount
];
const
mutation
=
expectedMutations
[
mutationsC
ount
];
expect
(
mutation
.
type
).
toEqual
(
type
);
expect
(
mutation
.
type
).
toEqual
(
type
);
...
@@ -17,18 +32,40 @@ export default (action, payload, state, expectedMutations, done) => {
...
@@ -17,18 +32,40 @@ export default (action, payload, state, expectedMutations, done) => {
expect
(
mutation
.
payload
).
toEqual
(
mutationPayload
);
expect
(
mutation
.
payload
).
toEqual
(
mutationPayload
);
}
}
count
++
;
mutationsCount
+=
1
;
if
(
count
>=
expectedMutations
.
length
)
{
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
();
done
();
}
}
};
};
// call the action with mocked store and arguments
// 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
// check if no mutations should have been dispatched
if
(
expectedMutations
.
length
===
0
)
{
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
();
done
();
}
}
};
};
spec/javascripts/notes/stores/actions_spec.js
View file @
470b8ca1
...
@@ -25,6 +25,7 @@ describe('Actions Notes Store', () => {
...
@@ -25,6 +25,7 @@ describe('Actions Notes Store', () => {
notesDataMock
,
notesDataMock
,
{
notesData
:
{}
},
{
notesData
:
{}
},
[{
type
:
'
SET_NOTES_DATA
'
,
payload
:
notesDataMock
}],
[{
type
:
'
SET_NOTES_DATA
'
,
payload
:
notesDataMock
}],
[],
done
,
done
,
);
);
});
});
...
@@ -37,6 +38,7 @@ describe('Actions Notes Store', () => {
...
@@ -37,6 +38,7 @@ describe('Actions Notes Store', () => {
noteableDataMock
,
noteableDataMock
,
{
noteableData
:
{}
},
{
noteableData
:
{}
},
[{
type
:
'
SET_NOTEABLE_DATA
'
,
payload
:
noteableDataMock
}],
[{
type
:
'
SET_NOTEABLE_DATA
'
,
payload
:
noteableDataMock
}],
[],
done
,
done
,
);
);
});
});
...
@@ -49,6 +51,7 @@ describe('Actions Notes Store', () => {
...
@@ -49,6 +51,7 @@ describe('Actions Notes Store', () => {
userDataMock
,
userDataMock
,
{
userData
:
{}
},
{
userData
:
{}
},
[{
type
:
'
SET_USER_DATA
'
,
payload
:
userDataMock
}],
[{
type
:
'
SET_USER_DATA
'
,
payload
:
userDataMock
}],
[],
done
,
done
,
);
);
});
});
...
@@ -61,6 +64,7 @@ describe('Actions Notes Store', () => {
...
@@ -61,6 +64,7 @@ describe('Actions Notes Store', () => {
'
timestamp
'
,
'
timestamp
'
,
{
lastFetchedAt
:
{}
},
{
lastFetchedAt
:
{}
},
[{
type
:
'
SET_LAST_FETCHED_AT
'
,
payload
:
'
timestamp
'
}],
[{
type
:
'
SET_LAST_FETCHED_AT
'
,
payload
:
'
timestamp
'
}],
[],
done
,
done
,
);
);
});
});
...
@@ -73,6 +77,7 @@ describe('Actions Notes Store', () => {
...
@@ -73,6 +77,7 @@ describe('Actions Notes Store', () => {
[
individualNote
],
[
individualNote
],
{
notes
:
[]
},
{
notes
:
[]
},
[{
type
:
'
SET_INITIAL_NOTES
'
,
payload
:
[
individualNote
]
}],
[{
type
:
'
SET_INITIAL_NOTES
'
,
payload
:
[
individualNote
]
}],
[],
done
,
done
,
);
);
});
});
...
@@ -85,6 +90,7 @@ describe('Actions Notes Store', () => {
...
@@ -85,6 +90,7 @@ describe('Actions Notes Store', () => {
'
hash
'
,
'
hash
'
,
{
notes
:
[]
},
{
notes
:
[]
},
[{
type
:
'
SET_TARGET_NOTE_HASH
'
,
payload
:
'
hash
'
}],
[{
type
:
'
SET_TARGET_NOTE_HASH
'
,
payload
:
'
hash
'
}],
[],
done
,
done
,
);
);
});
});
...
@@ -97,6 +103,7 @@ describe('Actions Notes Store', () => {
...
@@ -97,6 +103,7 @@ describe('Actions Notes Store', () => {
{
discussionId
:
discussionMock
.
id
},
{
discussionId
:
discussionMock
.
id
},
{
notes
:
[
discussionMock
]
},
{
notes
:
[
discussionMock
]
},
[{
type
:
'
TOGGLE_DISCUSSION
'
,
payload
:
{
discussionId
:
discussionMock
.
id
}
}],
[{
type
:
'
TOGGLE_DISCUSSION
'
,
payload
:
{
discussionId
:
discussionMock
.
id
}
}],
[],
done
,
done
,
);
);
});
});
...
@@ -164,6 +171,7 @@ describe('Actions Notes Store', () => {
...
@@ -164,6 +171,7 @@ describe('Actions Notes Store', () => {
true
,
true
,
{},
{},
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
true
}],
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
true
}],
[],
done
,
done
,
);
);
});
});
...
@@ -174,6 +182,7 @@ describe('Actions Notes Store', () => {
...
@@ -174,6 +182,7 @@ describe('Actions Notes Store', () => {
false
,
false
,
{},
{},
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
false
}],
[{
type
:
'
TOGGLE_STATE_BUTTON_LOADING
'
,
payload
:
false
}],
[],
done
,
done
,
);
);
});
});
...
@@ -181,11 +190,11 @@ describe('Actions Notes Store', () => {
...
@@ -181,11 +190,11 @@ describe('Actions Notes Store', () => {
describe
(
'
toggleIssueLocalState
'
,
()
=>
{
describe
(
'
toggleIssueLocalState
'
,
()
=>
{
it
(
'
sets issue state as closed
'
,
done
=>
{
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
=>
{
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', () => {
...
@@ -49,6 +49,7 @@ describe('Actions Registry Store', () => {
{
type
:
types
.
TOGGLE_MAIN_LOADING
},
{
type
:
types
.
TOGGLE_MAIN_LOADING
},
{
type
:
types
.
SET_REPOS_LIST
,
payload
:
reposServerResponse
},
{
type
:
types
.
SET_REPOS_LIST
,
payload
:
reposServerResponse
},
],
],
[],
done
,
done
,
);
);
});
});
...
@@ -88,6 +89,7 @@ describe('Actions Registry Store', () => {
...
@@ -88,6 +89,7 @@ describe('Actions Registry Store', () => {
},
},
},
},
],
],
[],
done
,
done
,
);
);
});
});
...
@@ -101,6 +103,7 @@ describe('Actions Registry Store', () => {
...
@@ -101,6 +103,7 @@ describe('Actions Registry Store', () => {
'
endpoint
'
,
'
endpoint
'
,
mockedState
,
mockedState
,
[{
type
:
types
.
SET_MAIN_ENDPOINT
,
payload
:
'
endpoint
'
}],
[{
type
:
types
.
SET_MAIN_ENDPOINT
,
payload
:
'
endpoint
'
}],
[],
done
,
done
,
);
);
});
});
...
@@ -113,6 +116,7 @@ describe('Actions Registry Store', () => {
...
@@ -113,6 +116,7 @@ describe('Actions Registry Store', () => {
null
,
null
,
mockedState
,
mockedState
,
[{
type
:
types
.
TOGGLE_MAIN_LOADING
}],
[{
type
:
types
.
TOGGLE_MAIN_LOADING
}],
[],
done
,
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