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
8b01ef82
Commit
8b01ef82
authored
Aug 11, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds helper to test Vuex actions
parent
cbddad5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
14 deletions
+98
-14
spec/javascripts/notes/stores/actions_spec.js
spec/javascripts/notes/stores/actions_spec.js
+61
-14
spec/javascripts/notes/stores/helpers.js
spec/javascripts/notes/stores/helpers.js
+37
-0
No files found.
spec/javascripts/notes/stores/actions_spec.js
View file @
8b01ef82
import
*
as
actions
from
'
~/notes/stores/actions
'
;
import
*
as
actions
from
'
~/notes/stores/actions
'
;
import
testAction
from
'
./helpers
'
;
describe
(
'
Actions Notes Store
'
,
()
=>
{
import
{
note
,
discussionMock
,
notesDataMock
,
userDataMock
,
issueDataMock
,
individualNote
}
from
'
../mock_data
'
;
import
service
from
'
~/notes/services/issue_notes_service
'
;
// use require syntax for inline loaders.
// with inject-loader, this returns a module factory
// that allows us to inject mocked dependencies.
// const actionsInjector = require('inject-loader!./actions');
// const actions = actionsInjector({
// '../api/shop': {
// getProducts (cb) {
// setTimeout(() => {
// cb([ /* mocked response */ ])
// }, 100)
// }
// }
// });
fdescribe
(
'
Actions Notes Store
'
,
()
=>
{
describe
(
'
setNotesData
'
,
()
=>
{
describe
(
'
setNotesData
'
,
()
=>
{
it
(
'
should set received notes data
'
,
()
=>
{
it
(
'
should set received notes data
'
,
(
done
)
=>
{
testAction
(
actions
.
setNotesData
,
null
,
{
notesData
:
{}
},
[
{
type
:
'
SET_NOTES_DATA
'
,
payload
:
notesDataMock
},
],
done
);
});
});
});
});
describe
(
'
setIssueData
'
,
()
=>
{
describe
(
'
setIssueData
'
,
()
=>
{
it
(
'
should set received issue data
'
,
()
=>
{});
it
(
'
should set received issue data
'
,
(
done
)
=>
{
testAction
(
actions
.
setIssueData
,
null
,
{
issueData
:
{}
},
[
{
type
:
'
SET_ISSUE_DATA
'
,
payload
:
issueDataMock
},
],
done
);
});
});
});
describe
(
'
setUserData
'
,
()
=>
{
describe
(
'
setUserData
'
,
()
=>
{
it
(
'
should set received user data
'
,
()
=>
{});
it
(
'
should set received user data
'
,
(
done
)
=>
{
testAction
(
actions
.
setUserData
,
null
,
{
userData
:
{}
},
[
{
type
:
'
SET_USER_DATA
'
,
payload
:
userDataMock
},
],
done
);
});
});
});
describe
(
'
setLastFetchedAt
'
,
()
=>
{
describe
(
'
setLastFetchedAt
'
,
()
=>
{
it
(
'
should set received timestamp
'
,
()
=>
{});
it
(
'
should set received timestamp
'
,
(
done
)
=>
{
testAction
(
actions
.
setLastFetchedAt
,
null
,
{
lastFetchedAt
:
{}
},
[
{
type
:
'
SET_LAST_FETCHED_AT
'
,
payload
:
'
timestamp
'
},
],
done
);
});
});
});
describe
(
'
setInitialNotes
'
,
()
=>
{
describe
(
'
setInitialNotes
'
,
()
=>
{
it
(
'
should set initial notes
'
,
()
=>
{
it
(
'
should set initial notes
'
,
(
done
)
=>
{
testAction
(
actions
.
setInitialNotes
,
null
,
{
notes
:
[]
},
[
{
type
:
'
SET_INITAL_NOTES
'
,
payload
:
[
individualNote
]
},
],
done
);
});
});
});
});
describe
(
'
setTargetNoteHash
'
,
()
=>
{
describe
(
'
setTargetNoteHash
'
,
()
=>
{
it
(
'
should set target note hash
'
,
()
=>
{});
it
(
'
should set target note hash
'
,
(
done
)
=>
{
testAction
(
actions
.
setTargetNoteHash
,
null
,
{
notes
:
[]
},
[
{
type
:
'
SET_TARGET_NOTE_HASH
'
,
payload
:
'
hash
'
},
],
done
);
});
});
});
describe
(
'
toggleDiscussion
'
,
()
=>
{
describe
(
'
toggleDiscussion
'
,
()
=>
{
it
(
'
should toggle discussion
'
,
()
=>
{
it
(
'
should toggle discussion
'
,
(
done
)
=>
{
testAction
(
actions
.
toggleDiscussion
,
null
,
{
notes
:
[
discussionMock
]
},
[
{
type
:
'
TOGGLE_DISCUSSION
'
,
payload
:
{
discussionId
:
discussionMock
.
id
}
},
],
done
);
});
});
});
});
describe
(
'
fetchNotes
'
,
()
=>
{
describe
(
'
fetchNotes
'
,
()
=>
{
it
(
'
should request notes
'
,
()
=>
{
it
(
'
should request notes
'
,
(
done
)
=>
{
spyOn
(
service
,
'
fetchNotes
'
).
and
.
returnValue
(
Promise
.
resolve
({
json
()
{
return
[
individualNote
];
},
}));
testAction
(
actions
.
fetchNotes
,
null
,
{
notes
:
[]
},
[
{
type
:
'
TOGGLE_DISCUSSION
'
,
payload
:
[
individualNote
]
},
],
done
);
});
});
});
});
...
...
spec/javascripts/notes/stores/helpers.js
0 → 100644
View file @
8b01ef82
/* eslint-disable */
/**
* helper for testing action with expected mutations
* https://vuex.vuejs.org/en/testing.html
*/
export
default
(
action
,
payload
,
state
,
expectedMutations
,
done
)
=>
{
let
count
=
0
;
// mock commit
const
commit
=
(
type
,
payload
)
=>
{
const
mutation
=
expectedMutations
[
count
];
try
{
expect
(
mutation
.
type
).
to
.
equal
(
type
);
if
(
payload
)
{
expect
(
mutation
.
payload
).
to
.
deep
.
equal
(
payload
);
}
}
catch
(
error
)
{
done
(
error
);
}
count
++
;
if
(
count
>=
expectedMutations
.
length
)
{
done
();
}
};
// call the action with mocked store and arguments
action
({
commit
,
state
},
payload
);
// check if no mutations should have been dispatched
if
(
expectedMutations
.
length
===
0
)
{
expect
(
count
).
to
.
equal
(
0
);
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