summaryrefslogtreecommitdiff
path: root/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js')
-rw-r--r--spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js b/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
new file mode 100644
index 00000000000..e267cd59f50
--- /dev/null
+++ b/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
@@ -0,0 +1,69 @@
+import {
+ userListOptions,
+ hasUserLists,
+ isLoading,
+ hasError,
+} from '~/feature_flags/store/gitlab_user_list/getters';
+import statuses from '~/feature_flags/store/gitlab_user_list/status';
+import createState from '~/feature_flags/store/gitlab_user_list/state';
+import { userList } from '../../mock_data';
+
+describe('~/feature_flags/store/gitlab_user_list/getters', () => {
+ let mockedState;
+
+ beforeEach(() => {
+ mockedState = createState({ projectId: '8' });
+ mockedState.userLists = [userList];
+ });
+
+ describe('userListOption', () => {
+ it('should return user lists in a way usable by a dropdown', () => {
+ expect(userListOptions(mockedState)).toEqual([{ value: userList.id, text: userList.name }]);
+ });
+
+ it('should return an empty array if there are no lists', () => {
+ mockedState.userLists = [];
+ expect(userListOptions(mockedState)).toEqual([]);
+ });
+ });
+
+ describe('hasUserLists', () => {
+ it.each`
+ userLists | status | result
+ ${[userList]} | ${statuses.IDLE} | ${true}
+ ${[]} | ${statuses.IDLE} | ${false}
+ ${[]} | ${statuses.START} | ${true}
+ `(
+ 'should return $result if there are $userLists.length user lists and the status is $status',
+ ({ userLists, status, result }) => {
+ mockedState.userLists = userLists;
+ mockedState.status = status;
+ expect(hasUserLists(mockedState)).toBe(result);
+ },
+ );
+ });
+
+ describe('isLoading', () => {
+ it.each`
+ status | result
+ ${statuses.LOADING} | ${true}
+ ${statuses.ERROR} | ${false}
+ ${statuses.IDLE} | ${false}
+ `('should return $result if the status is "$status"', ({ status, result }) => {
+ mockedState.status = status;
+ expect(isLoading(mockedState)).toBe(result);
+ });
+ });
+
+ describe('hasError', () => {
+ it.each`
+ status | result
+ ${statuses.LOADING} | ${false}
+ ${statuses.ERROR} | ${true}
+ ${statuses.IDLE} | ${false}
+ `('should return $result if the status is "$status"', ({ status, result }) => {
+ mockedState.status = status;
+ expect(hasError(mockedState)).toBe(result);
+ });
+ });
+});