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
181da5bc
Commit
181da5bc
authored
Mar 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
aa537756
9b812763
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
235 additions
and
0 deletions
+235
-0
spec/frontend/helpers/class_spec_helper.js
spec/frontend/helpers/class_spec_helper.js
+9
-0
spec/frontend/helpers/locale_helper.js
spec/frontend/helpers/locale_helper.js
+11
-0
spec/frontend/helpers/scroll_into_view_promise.js
spec/frontend/helpers/scroll_into_view_promise.js
+28
-0
spec/frontend/helpers/set_timeout_promise_helper.js
spec/frontend/helpers/set_timeout_promise_helper.js
+4
-0
spec/frontend/helpers/user_mock_data_helper.js
spec/frontend/helpers/user_mock_data_helper.js
+14
-0
spec/frontend/helpers/vue_component_helper.js
spec/frontend/helpers/vue_component_helper.js
+18
-0
spec/frontend/helpers/vue_resource_helper.js
spec/frontend/helpers/vue_resource_helper.js
+11
-0
spec/frontend/helpers/vue_test_utils_helper.js
spec/frontend/helpers/vue_test_utils_helper.js
+19
-0
spec/frontend/helpers/vuex_action_helper.js
spec/frontend/helpers/vuex_action_helper.js
+104
-0
spec/frontend/helpers/wait_for_attribute_change.js
spec/frontend/helpers/wait_for_attribute_change.js
+16
-0
spec/frontend/helpers/wait_for_promises.js
spec/frontend/helpers/wait_for_promises.js
+1
-0
No files found.
spec/frontend/helpers/class_spec_helper.js
0 → 100644
View file @
181da5bc
export
default
class
ClassSpecHelper
{
static
itShouldBeAStaticMethod
(
base
,
method
)
{
return
it
(
'
should be a static method
'
,
()
=>
{
expect
(
Object
.
prototype
.
hasOwnProperty
.
call
(
base
,
method
)).
toBeTruthy
();
});
}
}
window
.
ClassSpecHelper
=
ClassSpecHelper
;
spec/frontend/helpers/locale_helper.js
0 → 100644
View file @
181da5bc
/* eslint-disable import/prefer-default-export */
export
const
setLanguage
=
languageCode
=>
{
const
htmlElement
=
document
.
querySelector
(
'
html
'
);
if
(
languageCode
)
{
htmlElement
.
setAttribute
(
'
lang
'
,
languageCode
);
}
else
{
htmlElement
.
removeAttribute
(
'
lang
'
);
}
};
spec/frontend/helpers/scroll_into_view_promise.js
0 → 100644
View file @
181da5bc
export
default
function
scrollIntoViewPromise
(
intersectionTarget
,
timeout
=
100
,
maxTries
=
5
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
intersectionObserver
;
let
retry
=
0
;
const
intervalId
=
setInterval
(()
=>
{
if
(
retry
>=
maxTries
)
{
intersectionObserver
.
disconnect
();
clearInterval
(
intervalId
);
reject
(
new
Error
(
`Could not scroll target into viewPort within
${
timeout
*
maxTries
}
ms`
));
}
retry
+=
1
;
intersectionTarget
.
scrollIntoView
();
},
timeout
);
intersectionObserver
=
new
IntersectionObserver
(
entries
=>
{
if
(
entries
[
0
].
isIntersecting
)
{
intersectionObserver
.
disconnect
();
clearInterval
(
intervalId
);
resolve
();
}
});
intersectionObserver
.
observe
(
intersectionTarget
);
intersectionTarget
.
scrollIntoView
();
});
}
spec/frontend/helpers/set_timeout_promise_helper.js
0 → 100644
View file @
181da5bc
export
default
(
time
=
0
)
=>
new
Promise
(
resolve
=>
{
setTimeout
(
resolve
,
time
);
});
spec/frontend/helpers/user_mock_data_helper.js
0 → 100644
View file @
181da5bc
export
default
{
createNumberRandomUsers
(
numberUsers
)
{
const
users
=
[];
for
(
let
i
=
0
;
i
<
numberUsers
;
i
+=
1
)
{
users
.
push
({
avatar
:
'
https://gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon
'
,
id
:
i
+
1
,
name
:
`GitLab User
${
i
}
`
,
username
:
`gitlab
${
i
}
`
,
});
}
return
users
;
},
};
spec/frontend/helpers/vue_component_helper.js
0 → 100644
View file @
181da5bc
/**
* Replaces line break with an empty space
* @param {*} data
*/
export
const
removeBreakLine
=
data
=>
data
.
replace
(
/
\r?\n
|
\r
/g
,
'
'
);
/**
* Removes line breaks, spaces and trims the given text
* @param {String} str
* @returns {String}
*/
export
const
trimText
=
str
=>
str
.
replace
(
/
\r?\n
|
\r
/g
,
''
)
.
replace
(
/
\s\s
+/g
,
'
'
)
.
trim
();
export
const
removeWhitespace
=
str
=>
str
.
replace
(
/
\s\s
+/g
,
'
'
);
spec/frontend/helpers/vue_resource_helper.js
0 → 100644
View file @
181da5bc
// eslint-disable-next-line import/prefer-default-export
export
const
headersInterceptor
=
(
request
,
next
)
=>
{
next
(
response
=>
{
const
headers
=
{};
response
.
headers
.
forEach
((
value
,
key
)
=>
{
headers
[
key
]
=
value
;
});
// eslint-disable-next-line no-param-reassign
response
.
headers
=
headers
;
});
};
spec/frontend/helpers/vue_test_utils_helper.js
0 → 100644
View file @
181da5bc
/* eslint-disable import/prefer-default-export */
const
vNodeContainsText
=
(
vnode
,
text
)
=>
(
vnode
.
text
&&
vnode
.
text
.
includes
(
text
))
||
(
vnode
.
children
&&
vnode
.
children
.
filter
(
child
=>
vNodeContainsText
(
child
,
text
)).
length
);
/**
* Determines whether a `shallowMount` Wrapper contains text
* within one of it's slots. This will also work on Wrappers
* acquired with `find()`, but only if it's parent Wrapper
* was shallowMounted.
* NOTE: Prefer checking the rendered output of a component
* wherever possible using something like `text()` instead.
* @param {Wrapper} shallowWrapper - Vue test utils wrapper (shallowMounted)
* @param {String} slotName
* @param {String} text
*/
export
const
shallowWrapperContainsSlotText
=
(
shallowWrapper
,
slotName
,
text
)
=>
!!
shallowWrapper
.
vm
.
$slots
[
slotName
].
filter
(
vnode
=>
vNodeContainsText
(
vnode
,
text
)).
length
;
spec/frontend/helpers/vuex_action_helper.js
0 → 100644
View file @
181da5bc
const
noop
=
()
=>
{};
/**
* Helper for testing action with expected mutations inspired in
* https://vuex.vuejs.org/en/testing.html
*
* @param {Function} action to be tested
* @param {Object} payload will be provided to the action
* @param {Object} state will be provided to the action
* @param {Array} [expectedMutations=[]] mutations expected to be committed
* @param {Array} [expectedActions=[]] actions expected to be dispatched
* @param {Function} [done=noop] to be executed after the tests
* @return {Promise}
*
* @example
* testAction(
* actions.actionName, // action
* { }, // mocked payload
* state, //state
* // expected mutations
* [
* { type: types.MUTATION}
* { type: types.MUTATION_1, payload: jasmine.any(Number)}
* ],
* // expected actions
* [
* { type: 'actionName', payload: {param: 'foobar'}},
* { type: 'actionName1'}
* ]
* done,
* );
*
* @example
* testAction(
* actions.actionName, // action
* { }, // mocked payload
* state, //state
* [ { type: types.MUTATION} ], // expected mutations
* [], // expected actions
* ).then(done)
* .catch(done.fail);
*/
export
default
(
action
,
payload
,
state
,
expectedMutations
=
[],
expectedActions
=
[],
done
=
noop
,
)
=>
{
const
mutations
=
[];
const
actions
=
[];
// mock commit
const
commit
=
(
type
,
mutationPayload
)
=>
{
const
mutation
=
{
type
};
if
(
typeof
mutationPayload
!==
'
undefined
'
)
{
mutation
.
payload
=
mutationPayload
;
}
mutations
.
push
(
mutation
);
};
// mock dispatch
const
dispatch
=
(
type
,
actionPayload
)
=>
{
const
dispatchedAction
=
{
type
};
if
(
typeof
actionPayload
!==
'
undefined
'
)
{
dispatchedAction
.
payload
=
actionPayload
;
}
actions
.
push
(
dispatchedAction
);
};
const
validateResults
=
()
=>
{
expect
({
mutations
,
actions
,
}).
toEqual
({
mutations
:
expectedMutations
,
actions
:
expectedActions
,
});
done
();
};
const
result
=
action
(
{
commit
,
state
,
dispatch
,
rootState
:
state
,
rootGetters
:
state
,
getters
:
state
},
payload
,
);
return
new
Promise
(
resolve
=>
{
setImmediate
(
resolve
);
})
.
then
(()
=>
result
)
.
catch
(
error
=>
{
validateResults
();
throw
error
;
})
.
then
(
data
=>
{
validateResults
();
return
data
;
});
};
spec/frontend/helpers/wait_for_attribute_change.js
0 → 100644
View file @
181da5bc
export
default
(
domElement
,
attributes
,
timeout
=
1500
)
=>
new
Promise
((
resolve
,
reject
)
=>
{
let
observer
;
const
timeoutId
=
setTimeout
(()
=>
{
observer
.
disconnect
();
reject
(
new
Error
(
`Could not see an attribute update within
${
timeout
}
ms`
));
},
timeout
);
observer
=
new
MutationObserver
(()
=>
{
clearTimeout
(
timeoutId
);
observer
.
disconnect
();
resolve
();
});
observer
.
observe
(
domElement
,
{
attributes
:
true
,
attributeFilter
:
attributes
});
});
spec/frontend/helpers/wait_for_promises.js
0 → 100644
View file @
181da5bc
export
default
()
=>
new
Promise
(
resolve
=>
requestAnimationFrame
(
resolve
));
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