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
c7cc41e8
Commit
c7cc41e8
authored
Feb 25, 2020
by
Muhammad Fawwaz
Committed by
Paul Slaughter
Feb 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate spec/javascripts/badges/ to Jest
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25118
parent
ddccf62d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
106 additions
and
89 deletions
+106
-89
spec/frontend/badges/components/badge_form_spec.js
spec/frontend/badges/components/badge_form_spec.js
+16
-11
spec/frontend/badges/components/badge_list_row_spec.js
spec/frontend/badges/components/badge_list_row_spec.js
+13
-10
spec/frontend/badges/components/badge_list_spec.js
spec/frontend/badges/components/badge_list_spec.js
+7
-3
spec/frontend/badges/components/badge_settings_spec.js
spec/frontend/badges/components/badge_settings_spec.js
+13
-14
spec/frontend/badges/components/badge_spec.js
spec/frontend/badges/components/badge_spec.js
+8
-6
spec/frontend/badges/dummy_badge.js
spec/frontend/badges/dummy_badge.js
+0
-0
spec/frontend/badges/store/actions_spec.js
spec/frontend/badges/store/actions_spec.js
+49
-45
spec/frontend/badges/store/mutations_spec.js
spec/frontend/badges/store/mutations_spec.js
+0
-0
No files found.
spec/
javascripts
/badges/components/badge_form_spec.js
→
spec/
frontend
/badges/components/badge_form_spec.js
View file @
c7cc41e8
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
mountComponentWithStore
}
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
{
mountComponentWithStore
}
from
'
helpers/vue_mount_component_helper
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
store
from
'
~/badges/store
'
;
import
store
from
'
~/badges/store
'
;
import
createEmptyBadge
from
'
~/badges/empty_badge
'
;
import
createEmptyBadge
from
'
~/badges/empty_badge
'
;
import
BadgeForm
from
'
~/badges/components/badge_form.vue
'
;
import
BadgeForm
from
'
~/badges/components/badge_form.vue
'
;
import
{
DUMMY_IMAGE_URL
,
TEST_HOST
}
from
'
../..
/test_constants
'
;
import
{
DUMMY_IMAGE_URL
,
TEST_HOST
}
from
'
helpers
/test_constants
'
;
// avoid preview background process
// avoid preview background process
BadgeForm
.
methods
.
debouncedPreview
=
()
=>
{};
BadgeForm
.
methods
.
debouncedPreview
=
()
=>
{};
...
@@ -41,7 +41,7 @@ describe('BadgeForm component', () => {
...
@@ -41,7 +41,7 @@ describe('BadgeForm component', () => {
describe
(
'
onCancel
'
,
()
=>
{
describe
(
'
onCancel
'
,
()
=>
{
it
(
'
calls stopEditing
'
,
()
=>
{
it
(
'
calls stopEditing
'
,
()
=>
{
spyOn
(
vm
,
'
stopEditing
'
);
jest
.
spyOn
(
vm
,
'
stopEditing
'
).
mockImplementation
(()
=>
{}
);
vm
.
onCancel
();
vm
.
onCancel
();
...
@@ -68,14 +68,14 @@ describe('BadgeForm component', () => {
...
@@ -68,14 +68,14 @@ describe('BadgeForm component', () => {
const
expectInvalidInput
=
inputElementSelector
=>
{
const
expectInvalidInput
=
inputElementSelector
=>
{
const
inputElement
=
vm
.
$el
.
querySelector
(
inputElementSelector
);
const
inputElement
=
vm
.
$el
.
querySelector
(
inputElementSelector
);
expect
(
inputElement
).
toBeMatchedBy
(
'
:invalid
'
);
expect
(
inputElement
.
checkValidity
()).
toBe
(
false
);
const
feedbackElement
=
vm
.
$el
.
querySelector
(
`
${
inputElementSelector
}
+ .invalid-feedback`
);
const
feedbackElement
=
vm
.
$el
.
querySelector
(
`
${
inputElementSelector
}
+ .invalid-feedback`
);
expect
(
feedbackElement
).
toBeVisible
();
expect
(
feedbackElement
).
toBeVisible
();
};
};
beforeEach
(
()
=>
{
beforeEach
(
done
=>
{
spyOn
(
vm
,
submitAction
).
and
.
r
eturnValue
(
Promise
.
resolve
());
jest
.
spyOn
(
vm
,
submitAction
).
mockR
eturnValue
(
Promise
.
resolve
());
store
.
replaceState
({
store
.
replaceState
({
...
store
.
state
,
...
store
.
state
,
badgeInAddForm
:
createEmptyBadge
(),
badgeInAddForm
:
createEmptyBadge
(),
...
@@ -83,9 +83,14 @@ describe('BadgeForm component', () => {
...
@@ -83,9 +83,14 @@ describe('BadgeForm component', () => {
isSaving
:
false
,
isSaving
:
false
,
});
});
setValue
(
nameSelector
,
'
TestBadge
'
);
Vue
.
nextTick
()
setValue
(
linkUrlSelector
,
`
${
TEST_HOST
}
/link/url`
);
.
then
(()
=>
{
setValue
(
imageUrlSelector
,
`
${
window
.
location
.
origin
}${
DUMMY_IMAGE_URL
}
`
);
setValue
(
nameSelector
,
'
TestBadge
'
);
setValue
(
linkUrlSelector
,
`
${
TEST_HOST
}
/link/url`
);
setValue
(
imageUrlSelector
,
`
${
window
.
location
.
origin
}${
DUMMY_IMAGE_URL
}
`
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
it
(
'
returns immediately if imageUrl is empty
'
,
()
=>
{
it
(
'
returns immediately if imageUrl is empty
'
,
()
=>
{
...
@@ -131,8 +136,8 @@ describe('BadgeForm component', () => {
...
@@ -131,8 +136,8 @@ describe('BadgeForm component', () => {
it
(
`calls
${
submitAction
}
`
,
()
=>
{
it
(
`calls
${
submitAction
}
`
,
()
=>
{
submitForm
();
submitForm
();
expect
(
findImageUrlElement
()
).
toBeMatchedBy
(
'
:valid
'
);
expect
(
findImageUrlElement
()
.
checkValidity
()).
toBe
(
true
);
expect
(
findLinkUrlElement
()
).
toBeMatchedBy
(
'
:valid
'
);
expect
(
findLinkUrlElement
()
.
checkValidity
()).
toBe
(
true
);
expect
(
vm
[
submitAction
]).
toHaveBeenCalled
();
expect
(
vm
[
submitAction
]).
toHaveBeenCalled
();
});
});
};
};
...
...
spec/
javascripts
/badges/components/badge_list_row_spec.js
→
spec/
frontend
/badges/components/badge_list_row_spec.js
View file @
c7cc41e8
import
$
from
'
jquery
'
;
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
mountComponentWithStore
}
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
{
mountComponentWithStore
}
from
'
helpers/vue_mount_component_helper
'
;
import
{
GROUP_BADGE
,
PROJECT_BADGE
}
from
'
~/badges/constants
'
;
import
{
GROUP_BADGE
,
PROJECT_BADGE
}
from
'
~/badges/constants
'
;
import
store
from
'
~/badges/store
'
;
import
store
from
'
~/badges/store
'
;
import
BadgeListRow
from
'
~/badges/components/badge_list_row.vue
'
;
import
BadgeListRow
from
'
~/badges/components/badge_list_row.vue
'
;
...
@@ -40,15 +39,15 @@ describe('BadgeListRow component', () => {
...
@@ -40,15 +39,15 @@ describe('BadgeListRow component', () => {
});
});
it
(
'
renders the badge name
'
,
()
=>
{
it
(
'
renders the badge name
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
badge
.
name
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
badge
.
name
);
});
});
it
(
'
renders the badge link
'
,
()
=>
{
it
(
'
renders the badge link
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
badge
.
linkUrl
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
badge
.
linkUrl
);
});
});
it
(
'
renders the badge kind
'
,
()
=>
{
it
(
'
renders the badge kind
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
Project Badge
'
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
'
Project Badge
'
);
});
});
it
(
'
shows edit and delete buttons
'
,
()
=>
{
it
(
'
shows edit and delete buttons
'
,
()
=>
{
...
@@ -66,7 +65,7 @@ describe('BadgeListRow component', () => {
...
@@ -66,7 +65,7 @@ describe('BadgeListRow component', () => {
});
});
it
(
'
calls editBadge when clicking then edit button
'
,
()
=>
{
it
(
'
calls editBadge when clicking then edit button
'
,
()
=>
{
spyOn
(
vm
,
'
editBadge
'
);
jest
.
spyOn
(
vm
,
'
editBadge
'
).
mockImplementation
(()
=>
{}
);
const
editButton
=
vm
.
$el
.
querySelector
(
'
.table-button-footer button:first-of-type
'
);
const
editButton
=
vm
.
$el
.
querySelector
(
'
.table-button-footer button:first-of-type
'
);
editButton
.
click
();
editButton
.
click
();
...
@@ -75,13 +74,17 @@ describe('BadgeListRow component', () => {
...
@@ -75,13 +74,17 @@ describe('BadgeListRow component', () => {
});
});
it
(
'
calls updateBadgeInModal and shows modal when clicking then delete button
'
,
done
=>
{
it
(
'
calls updateBadgeInModal and shows modal when clicking then delete button
'
,
done
=>
{
spyOn
(
vm
,
'
updateBadgeInModal
'
);
jest
.
spyOn
(
vm
,
'
updateBadgeInModal
'
).
mockImplementation
(()
=>
{});
$
(
'
#delete-badge-modal
'
).
on
(
'
shown.bs.modal
'
,
()
=>
done
());
const
deleteButton
=
vm
.
$el
.
querySelector
(
'
.table-button-footer button:last-of-type
'
);
const
deleteButton
=
vm
.
$el
.
querySelector
(
'
.table-button-footer button:last-of-type
'
);
deleteButton
.
click
();
deleteButton
.
click
();
expect
(
vm
.
updateBadgeInModal
).
toHaveBeenCalled
();
Vue
.
nextTick
()
.
then
(()
=>
{
expect
(
vm
.
updateBadgeInModal
).
toHaveBeenCalled
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
describe
(
'
for a group badge
'
,
()
=>
{
describe
(
'
for a group badge
'
,
()
=>
{
...
@@ -94,7 +97,7 @@ describe('BadgeListRow component', () => {
...
@@ -94,7 +97,7 @@ describe('BadgeListRow component', () => {
});
});
it
(
'
renders the badge kind
'
,
()
=>
{
it
(
'
renders the badge kind
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
Group Badge
'
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
'
Group Badge
'
);
});
});
it
(
'
hides edit and delete buttons
'
,
()
=>
{
it
(
'
hides edit and delete buttons
'
,
()
=>
{
...
...
spec/
javascripts
/badges/components/badge_list_spec.js
→
spec/
frontend
/badges/components/badge_list_spec.js
View file @
c7cc41e8
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
mountComponentWithStore
}
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
{
mountComponentWithStore
}
from
'
helpers/vue_mount_component_helper
'
;
import
{
GROUP_BADGE
,
PROJECT_BADGE
}
from
'
~/badges/constants
'
;
import
{
GROUP_BADGE
,
PROJECT_BADGE
}
from
'
~/badges/constants
'
;
import
store
from
'
~/badges/store
'
;
import
store
from
'
~/badges/store
'
;
import
BadgeList
from
'
~/badges/components/badge_list.vue
'
;
import
BadgeList
from
'
~/badges/components/badge_list.vue
'
;
...
@@ -22,6 +22,10 @@ describe('BadgeList component', () => {
...
@@ -22,6 +22,10 @@ describe('BadgeList component', () => {
kind
:
PROJECT_BADGE
,
kind
:
PROJECT_BADGE
,
isLoading
:
false
,
isLoading
:
false
,
});
});
// Can be removed once GlLoadingIcon no longer throws a warning
jest
.
spyOn
(
global
.
console
,
'
warn
'
).
mockImplementation
(()
=>
jest
.
fn
());
vm
=
mountComponentWithStore
(
Component
,
{
vm
=
mountComponentWithStore
(
Component
,
{
el
:
'
#dummy-element
'
,
el
:
'
#dummy-element
'
,
store
,
store
,
...
@@ -49,7 +53,7 @@ describe('BadgeList component', () => {
...
@@ -49,7 +53,7 @@ describe('BadgeList component', () => {
Vue
.
nextTick
()
Vue
.
nextTick
()
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
This project has no badges
'
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
'
This project has no badges
'
);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -82,7 +86,7 @@ describe('BadgeList component', () => {
...
@@ -82,7 +86,7 @@ describe('BadgeList component', () => {
Vue
.
nextTick
()
Vue
.
nextTick
()
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
This group has no badges
'
);
expect
(
vm
.
$el
.
innerText
).
toMatch
(
'
This group has no badges
'
);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
...
spec/
javascripts
/badges/components/badge_settings_spec.js
→
spec/
frontend
/badges/components/badge_settings_spec.js
View file @
c7cc41e8
import
$
from
'
jquery
'
;
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
mountComponentWithStore
}
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
{
mountComponentWithStore
}
from
'
helpers/vue_mount_component_helper
'
;
import
store
from
'
~/badges/store
'
;
import
store
from
'
~/badges/store
'
;
import
BadgeSettings
from
'
~/badges/components/badge_settings.vue
'
;
import
BadgeSettings
from
'
~/badges/components/badge_settings.vue
'
;
import
{
createDummyBadge
}
from
'
../dummy_badge
'
;
import
{
createDummyBadge
}
from
'
../dummy_badge
'
;
...
@@ -19,6 +18,10 @@ describe('BadgeSettings component', () => {
...
@@ -19,6 +18,10 @@ describe('BadgeSettings component', () => {
data-target="#delete-badge-modal"
data-target="#delete-badge-modal"
>Show modal</button>
>Show modal</button>
`
);
`
);
// Can be removed once GlLoadingIcon no longer throws a warning
jest
.
spyOn
(
global
.
console
,
'
warn
'
).
mockImplementation
(()
=>
jest
.
fn
());
vm
=
mountComponentWithStore
(
Component
,
{
vm
=
mountComponentWithStore
(
Component
,
{
el
:
'
#dummy-element
'
,
el
:
'
#dummy-element
'
,
store
,
store
,
...
@@ -35,20 +38,16 @@ describe('BadgeSettings component', () => {
...
@@ -35,20 +38,16 @@ describe('BadgeSettings component', () => {
const
modal
=
vm
.
$el
.
querySelector
(
'
#delete-badge-modal
'
);
const
modal
=
vm
.
$el
.
querySelector
(
'
#delete-badge-modal
'
);
const
button
=
document
.
getElementById
(
'
dummy-modal-button
'
);
const
button
=
document
.
getElementById
(
'
dummy-modal-button
'
);
$
(
modal
).
on
(
'
shown.bs.modal
'
,
()
=>
{
button
.
click
();
expect
(
modal
).
toContainText
(
'
Delete badge?
'
);
const
badgeElement
=
modal
.
querySelector
(
'
img.project-badge
'
);
expect
(
badgeElement
).
not
.
toBe
(
null
);
expect
(
badgeElement
.
getAttribute
(
'
src
'
)).
toBe
(
badge
.
renderedImageUrl
);
done
();
});
Vue
.
nextTick
()
Vue
.
nextTick
()
.
then
(()
=>
{
.
then
(()
=>
{
button
.
click
();
expect
(
modal
.
innerText
).
toMatch
(
'
Delete badge?
'
);
const
badgeElement
=
modal
.
querySelector
(
'
img.project-badge
'
);
expect
(
badgeElement
).
not
.
toBe
(
null
);
expect
(
badgeElement
.
getAttribute
(
'
src
'
)).
toBe
(
badge
.
renderedImageUrl
);
})
})
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
});
});
...
@@ -67,7 +66,7 @@ describe('BadgeSettings component', () => {
...
@@ -67,7 +66,7 @@ describe('BadgeSettings component', () => {
expect
(
badgeListElement
).
not
.
toBe
(
null
);
expect
(
badgeListElement
).
not
.
toBe
(
null
);
expect
(
badgeListElement
).
toBeVisible
();
expect
(
badgeListElement
).
toBeVisible
();
expect
(
badgeListElement
).
toContainText
(
'
Your badges
'
);
expect
(
badgeListElement
.
innerText
).
toMatch
(
'
Your badges
'
);
});
});
describe
(
'
when editing
'
,
()
=>
{
describe
(
'
when editing
'
,
()
=>
{
...
@@ -103,7 +102,7 @@ describe('BadgeSettings component', () => {
...
@@ -103,7 +102,7 @@ describe('BadgeSettings component', () => {
describe
(
'
methods
'
,
()
=>
{
describe
(
'
methods
'
,
()
=>
{
describe
(
'
onSubmitModal
'
,
()
=>
{
describe
(
'
onSubmitModal
'
,
()
=>
{
it
(
'
triggers
'
,
()
=>
{
it
(
'
triggers
'
,
()
=>
{
spyOn
(
vm
,
'
deleteBadge
'
).
and
.
callFake
(()
=>
Promise
.
resolve
());
jest
.
spyOn
(
vm
,
'
deleteBadge
'
).
mockImplementation
(()
=>
Promise
.
resolve
());
const
modal
=
vm
.
$el
.
querySelector
(
'
#delete-badge-modal
'
);
const
modal
=
vm
.
$el
.
querySelector
(
'
#delete-badge-modal
'
);
const
deleteButton
=
modal
.
querySelector
(
'
.btn-danger
'
);
const
deleteButton
=
modal
.
querySelector
(
'
.btn-danger
'
);
...
...
spec/
javascripts
/badges/components/badge_spec.js
→
spec/
frontend
/badges/components/badge_spec.js
View file @
c7cc41e8
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
mountComponent
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
mountComponent
from
'
helpers/vue_mount_component_helper
'
;
import
{
DUMMY_IMAGE_URL
,
TEST_HOST
}
from
'
spec/test_constants
'
;
import
{
DUMMY_IMAGE_URL
,
TEST_HOST
}
from
'
spec/test_constants
'
;
import
Badge
from
'
~/badges/components/badge.vue
'
;
import
Badge
from
'
~/badges/components/badge.vue
'
;
...
@@ -23,9 +23,11 @@ describe('Badge component', () => {
...
@@ -23,9 +23,11 @@ describe('Badge component', () => {
const
createComponent
=
(
props
,
el
=
null
)
=>
{
const
createComponent
=
(
props
,
el
=
null
)
=>
{
vm
=
mountComponent
(
Component
,
props
,
el
);
vm
=
mountComponent
(
Component
,
props
,
el
);
const
{
badgeImage
}
=
findElements
();
const
{
badgeImage
}
=
findElements
();
return
new
Promise
(
resolve
=>
badgeImage
.
addEventListener
(
'
load
'
,
resolve
)).
then
(()
=>
return
new
Promise
(
resolve
=>
{
Vue
.
nextTick
(),
badgeImage
.
addEventListener
(
'
load
'
,
resolve
);
);
// Manually dispatch load event as it is not triggered
badgeImage
.
dispatchEvent
(
new
Event
(
'
load
'
));
}).
then
(()
=>
Vue
.
nextTick
());
};
};
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -111,7 +113,7 @@ describe('Badge component', () => {
...
@@ -111,7 +113,7 @@ describe('Badge component', () => {
expect
(
badgeImage
).
toBeVisible
();
expect
(
badgeImage
).
toBeVisible
();
expect
(
loadingIcon
).
toBeHidden
();
expect
(
loadingIcon
).
toBeHidden
();
expect
(
reloadButton
).
toBeHidden
();
expect
(
reloadButton
).
toBeHidden
();
expect
(
vm
.
$el
.
innerText
).
toBe
(
''
);
expect
(
vm
.
$el
.
querySelector
(
'
.btn-group
'
)).
toBeHidden
(
);
});
});
it
(
'
shows a loading icon when loading
'
,
done
=>
{
it
(
'
shows a loading icon when loading
'
,
done
=>
{
...
@@ -124,7 +126,7 @@ describe('Badge component', () => {
...
@@ -124,7 +126,7 @@ describe('Badge component', () => {
expect
(
badgeImage
).
toBeHidden
();
expect
(
badgeImage
).
toBeHidden
();
expect
(
loadingIcon
).
toBeVisible
();
expect
(
loadingIcon
).
toBeVisible
();
expect
(
reloadButton
).
toBeHidden
();
expect
(
reloadButton
).
toBeHidden
();
expect
(
vm
.
$el
.
innerText
).
toBe
(
''
);
expect
(
vm
.
$el
.
querySelector
(
'
.btn-group
'
)).
toBeHidden
(
);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
...
spec/
javascripts
/badges/dummy_badge.js
→
spec/
frontend
/badges/dummy_badge.js
View file @
c7cc41e8
File moved
spec/
javascripts
/badges/store/actions_spec.js
→
spec/
frontend
/badges/store/actions_spec.js
View file @
c7cc41e8
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
import
testAction
from
'
spec/
helpers/vuex_action_helper
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
actions
,
{
transformBackendBadge
}
from
'
~/badges/store/actions
'
;
import
actions
,
{
transformBackendBadge
}
from
'
~/badges/store/actions
'
;
import
mutationTypes
from
'
~/badges/store/mutation_types
'
;
import
mutationTypes
from
'
~/badges/store/mutation_types
'
;
...
@@ -76,7 +76,7 @@ describe('Badges store actions', () => {
...
@@ -76,7 +76,7 @@ describe('Badges store actions', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
endpointMock
=
axiosMock
.
onPost
(
dummyEndpointUrl
);
endpointMock
=
axiosMock
.
onPost
(
dummyEndpointUrl
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
(
);
badgeInAddForm
=
createDummyBadge
();
badgeInAddForm
=
createDummyBadge
();
state
=
{
state
=
{
...
state
,
...
state
,
...
@@ -96,8 +96,8 @@ describe('Badges store actions', () => {
...
@@ -96,8 +96,8 @@ describe('Badges store actions', () => {
}),
}),
);
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestNewBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestNewBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
200
,
dummyResponse
];
return
[
200
,
dummyResponse
];
});
});
...
@@ -105,7 +105,7 @@ describe('Badges store actions', () => {
...
@@ -105,7 +105,7 @@ describe('Badges store actions', () => {
actions
actions
.
addBadge
({
state
,
dispatch
})
.
addBadge
({
state
,
dispatch
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveNewBadge
'
,
dummyBadge
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveNewBadge
'
,
dummyBadge
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -121,8 +121,8 @@ describe('Badges store actions', () => {
...
@@ -121,8 +121,8 @@ describe('Badges store actions', () => {
}),
}),
);
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestNewBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestNewBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
500
,
''
];
return
[
500
,
''
];
});
});
...
@@ -130,7 +130,7 @@ describe('Badges store actions', () => {
...
@@ -130,7 +130,7 @@ describe('Badges store actions', () => {
.
addBadge
({
state
,
dispatch
})
.
addBadge
({
state
,
dispatch
})
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
catch
(()
=>
{
.
catch
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveNewBadgeError
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveNewBadgeError
'
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -182,20 +182,20 @@ describe('Badges store actions', () => {
...
@@ -182,20 +182,20 @@ describe('Badges store actions', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
endpointMock
=
axiosMock
.
onDelete
(
`
${
dummyEndpointUrl
}
/
${
badgeId
}
`
);
endpointMock
=
axiosMock
.
onDelete
(
`
${
dummyEndpointUrl
}
/
${
badgeId
}
`
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
(
);
});
});
it
(
'
dispatches requestDeleteBadge and receiveDeleteBadge for successful response
'
,
done
=>
{
it
(
'
dispatches requestDeleteBadge and receiveDeleteBadge for successful response
'
,
done
=>
{
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestDeleteBadge
'
,
badgeId
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestDeleteBadge
'
,
badgeId
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
200
,
''
];
return
[
200
,
''
];
});
});
actions
actions
.
deleteBadge
({
state
,
dispatch
},
{
id
:
badgeId
})
.
deleteBadge
({
state
,
dispatch
},
{
id
:
badgeId
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveDeleteBadge
'
,
badgeId
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveDeleteBadge
'
,
badgeId
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -203,8 +203,8 @@ describe('Badges store actions', () => {
...
@@ -203,8 +203,8 @@ describe('Badges store actions', () => {
it
(
'
dispatches requestDeleteBadge and receiveDeleteBadgeError for error response
'
,
done
=>
{
it
(
'
dispatches requestDeleteBadge and receiveDeleteBadgeError for error response
'
,
done
=>
{
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestDeleteBadge
'
,
badgeId
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestDeleteBadge
'
,
badgeId
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
500
,
''
];
return
[
500
,
''
];
});
});
...
@@ -212,7 +212,7 @@ describe('Badges store actions', () => {
...
@@ -212,7 +212,7 @@ describe('Badges store actions', () => {
.
deleteBadge
({
state
,
dispatch
},
{
id
:
badgeId
})
.
deleteBadge
({
state
,
dispatch
},
{
id
:
badgeId
})
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
catch
(()
=>
{
.
catch
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveDeleteBadgeError
'
,
badgeId
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveDeleteBadgeError
'
,
badgeId
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -280,7 +280,7 @@ describe('Badges store actions', () => {
...
@@ -280,7 +280,7 @@ describe('Badges store actions', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
endpointMock
=
axiosMock
.
onGet
(
dummyEndpointUrl
);
endpointMock
=
axiosMock
.
onGet
(
dummyEndpointUrl
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
(
);
});
});
it
(
'
dispatches requestLoadBadges and receiveLoadBadges for successful response
'
,
done
=>
{
it
(
'
dispatches requestLoadBadges and receiveLoadBadges for successful response
'
,
done
=>
{
...
@@ -291,8 +291,8 @@ describe('Badges store actions', () => {
...
@@ -291,8 +291,8 @@ describe('Badges store actions', () => {
createDummyBadgeResponse
(),
createDummyBadgeResponse
(),
];
];
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestLoadBadges
'
,
dummyData
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestLoadBadges
'
,
dummyData
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
200
,
dummyReponse
];
return
[
200
,
dummyReponse
];
});
});
...
@@ -301,7 +301,7 @@ describe('Badges store actions', () => {
...
@@ -301,7 +301,7 @@ describe('Badges store actions', () => {
.
then
(()
=>
{
.
then
(()
=>
{
const
badges
=
dummyReponse
.
map
(
transformBackendBadge
);
const
badges
=
dummyReponse
.
map
(
transformBackendBadge
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveLoadBadges
'
,
badges
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveLoadBadges
'
,
badges
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -310,8 +310,8 @@ describe('Badges store actions', () => {
...
@@ -310,8 +310,8 @@ describe('Badges store actions', () => {
it
(
'
dispatches requestLoadBadges and receiveLoadBadgesError for error response
'
,
done
=>
{
it
(
'
dispatches requestLoadBadges and receiveLoadBadgesError for error response
'
,
done
=>
{
const
dummyData
=
'
this is just some data
'
;
const
dummyData
=
'
this is just some data
'
;
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestLoadBadges
'
,
dummyData
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestLoadBadges
'
,
dummyData
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
500
,
''
];
return
[
500
,
''
];
});
});
...
@@ -319,7 +319,7 @@ describe('Badges store actions', () => {
...
@@ -319,7 +319,7 @@ describe('Badges store actions', () => {
.
loadBadges
({
state
,
dispatch
},
dummyData
)
.
loadBadges
({
state
,
dispatch
},
dummyData
)
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
catch
(()
=>
{
.
catch
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveLoadBadgesError
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveLoadBadgesError
'
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -382,11 +382,11 @@ describe('Badges store actions', () => {
...
@@ -382,11 +382,11 @@ describe('Badges store actions', () => {
`image_url=
${
encodeURIComponent
(
badgeInForm
.
imageUrl
)}
`
,
`image_url=
${
encodeURIComponent
(
badgeInForm
.
imageUrl
)}
`
,
].
join
(
'
&
'
);
].
join
(
'
&
'
);
endpointMock
=
axiosMock
.
onGet
(
`
${
dummyEndpointUrl
}
/render?
${
urlParameters
}
`
);
endpointMock
=
axiosMock
.
onGet
(
`
${
dummyEndpointUrl
}
/render?
${
urlParameters
}
`
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
(
);
});
});
it
(
'
returns immediately if imageUrl is empty
'
,
done
=>
{
it
(
'
returns immediately if imageUrl is empty
'
,
done
=>
{
spyOn
(
axios
,
'
get
'
);
jest
.
spyOn
(
axios
,
'
get
'
).
mockImplementation
(()
=>
{}
);
badgeInForm
.
imageUrl
=
''
;
badgeInForm
.
imageUrl
=
''
;
actions
actions
...
@@ -399,7 +399,7 @@ describe('Badges store actions', () => {
...
@@ -399,7 +399,7 @@ describe('Badges store actions', () => {
});
});
it
(
'
returns immediately if linkUrl is empty
'
,
done
=>
{
it
(
'
returns immediately if linkUrl is empty
'
,
done
=>
{
spyOn
(
axios
,
'
get
'
);
jest
.
spyOn
(
axios
,
'
get
'
).
mockImplementation
(()
=>
{}
);
badgeInForm
.
linkUrl
=
''
;
badgeInForm
.
linkUrl
=
''
;
actions
actions
...
@@ -412,19 +412,23 @@ describe('Badges store actions', () => {
...
@@ -412,19 +412,23 @@ describe('Badges store actions', () => {
});
});
it
(
'
escapes user input
'
,
done
=>
{
it
(
'
escapes user input
'
,
done
=>
{
spyOn
(
axios
,
'
get
'
).
and
.
callFake
(()
=>
Promise
.
resolve
({
data
:
createDummyBadgeResponse
()
}));
jest
.
spyOn
(
axios
,
'
get
'
)
.
mockImplementation
(()
=>
Promise
.
resolve
({
data
:
createDummyBadgeResponse
()
}));
badgeInForm
.
imageUrl
=
'
&make-sandwich=true
'
;
badgeInForm
.
imageUrl
=
'
&make-sandwich=true
'
;
badgeInForm
.
linkUrl
=
'
<script>I am dangerous!</script>
'
;
badgeInForm
.
linkUrl
=
'
<script>I am dangerous!</script>
'
;
actions
actions
.
renderBadge
({
state
,
dispatch
})
.
renderBadge
({
state
,
dispatch
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
axios
.
get
.
calls
.
count
()).
toBe
(
1
);
expect
(
axios
.
get
.
mock
.
calls
.
length
).
toBe
(
1
);
const
url
=
axios
.
get
.
calls
.
argsFor
(
0
)[
0
];
const
url
=
axios
.
get
.
mock
.
calls
[
0
][
0
];
expect
(
url
).
toMatch
(
`^
${
dummyEndpointUrl
}
/render?`
);
expect
(
url
).
toMatch
(
new
RegExp
(
`^
${
dummyEndpointUrl
}
/render?`
));
expect
(
url
).
toMatch
(
'
\\
?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&
'
);
expect
(
url
).
toMatch
(
expect
(
url
).
toMatch
(
'
&image_url=%26make-sandwich%3Dtrue$
'
);
new
RegExp
(
'
\\
?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&
'
),
);
expect
(
url
).
toMatch
(
new
RegExp
(
'
&image_url=%26make-sandwich%3Dtrue$
'
));
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -433,8 +437,8 @@ describe('Badges store actions', () => {
...
@@ -433,8 +437,8 @@ describe('Badges store actions', () => {
it
(
'
dispatches requestRenderedBadge and receiveRenderedBadge for successful response
'
,
done
=>
{
it
(
'
dispatches requestRenderedBadge and receiveRenderedBadge for successful response
'
,
done
=>
{
const
dummyReponse
=
createDummyBadgeResponse
();
const
dummyReponse
=
createDummyBadgeResponse
();
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestRenderedBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestRenderedBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
200
,
dummyReponse
];
return
[
200
,
dummyReponse
];
});
});
...
@@ -443,7 +447,7 @@ describe('Badges store actions', () => {
...
@@ -443,7 +447,7 @@ describe('Badges store actions', () => {
.
then
(()
=>
{
.
then
(()
=>
{
const
renderedBadge
=
transformBackendBadge
(
dummyReponse
);
const
renderedBadge
=
transformBackendBadge
(
dummyReponse
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveRenderedBadge
'
,
renderedBadge
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveRenderedBadge
'
,
renderedBadge
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -451,8 +455,8 @@ describe('Badges store actions', () => {
...
@@ -451,8 +455,8 @@ describe('Badges store actions', () => {
it
(
'
dispatches requestRenderedBadge and receiveRenderedBadgeError for error response
'
,
done
=>
{
it
(
'
dispatches requestRenderedBadge and receiveRenderedBadgeError for error response
'
,
done
=>
{
endpointMock
.
replyOnce
(()
=>
{
endpointMock
.
replyOnce
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestRenderedBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestRenderedBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
500
,
''
];
return
[
500
,
''
];
});
});
...
@@ -460,7 +464,7 @@ describe('Badges store actions', () => {
...
@@ -460,7 +464,7 @@ describe('Badges store actions', () => {
.
renderBadge
({
state
,
dispatch
})
.
renderBadge
({
state
,
dispatch
})
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
catch
(()
=>
{
.
catch
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveRenderedBadgeError
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveRenderedBadgeError
'
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -519,7 +523,7 @@ describe('Badges store actions', () => {
...
@@ -519,7 +523,7 @@ describe('Badges store actions', () => {
badgeInEditForm
,
badgeInEditForm
,
};
};
endpointMock
=
axiosMock
.
onPut
(
`
${
dummyEndpointUrl
}
/
${
badgeInEditForm
.
id
}
`
);
endpointMock
=
axiosMock
.
onPut
(
`
${
dummyEndpointUrl
}
/
${
badgeInEditForm
.
id
}
`
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
(
);
});
});
it
(
'
dispatches requestUpdatedBadge and receiveUpdatedBadge for successful response
'
,
done
=>
{
it
(
'
dispatches requestUpdatedBadge and receiveUpdatedBadge for successful response
'
,
done
=>
{
...
@@ -534,8 +538,8 @@ describe('Badges store actions', () => {
...
@@ -534,8 +538,8 @@ describe('Badges store actions', () => {
}),
}),
);
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestUpdatedBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestUpdatedBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
200
,
dummyResponse
];
return
[
200
,
dummyResponse
];
});
});
...
@@ -543,7 +547,7 @@ describe('Badges store actions', () => {
...
@@ -543,7 +547,7 @@ describe('Badges store actions', () => {
actions
actions
.
saveBadge
({
state
,
dispatch
})
.
saveBadge
({
state
,
dispatch
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveUpdatedBadge
'
,
updatedBadge
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveUpdatedBadge
'
,
updatedBadge
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
@@ -559,8 +563,8 @@ describe('Badges store actions', () => {
...
@@ -559,8 +563,8 @@ describe('Badges store actions', () => {
}),
}),
);
);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
requestUpdatedBadge
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
requestUpdatedBadge
'
]]);
dispatch
.
calls
.
reset
();
dispatch
.
mockClear
();
return
[
500
,
''
];
return
[
500
,
''
];
});
});
...
@@ -568,7 +572,7 @@ describe('Badges store actions', () => {
...
@@ -568,7 +572,7 @@ describe('Badges store actions', () => {
.
saveBadge
({
state
,
dispatch
})
.
saveBadge
({
state
,
dispatch
})
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
then
(()
=>
done
.
fail
(
'
Expected Ajax call to fail!
'
))
.
catch
(()
=>
{
.
catch
(()
=>
{
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
receiveUpdatedBadgeError
'
]]);
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
receiveUpdatedBadgeError
'
]]);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
...
...
spec/
javascripts
/badges/store/mutations_spec.js
→
spec/
frontend
/badges/store/mutations_spec.js
View file @
c7cc41e8
File moved
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