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
60bcc616
Commit
60bcc616
authored
Mar 31, 2020
by
Vitaly Slobodin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate ee/insights to Jest
Closes
https://gitlab.com/gitlab-org/gitlab/-/issues/194290
parent
a516e498
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
112 additions
and
136 deletions
+112
-136
ee/spec/frontend/insights/components/insights_chart_error_spec.js
...frontend/insights/components/insights_chart_error_spec.js
+3
-3
ee/spec/frontend/insights/components/insights_chart_spec.js
ee/spec/frontend/insights/components/insights_chart_spec.js
+6
-1
ee/spec/frontend/insights/components/insights_config_warning_spec.js
...ntend/insights/components/insights_config_warning_spec.js
+2
-2
ee/spec/frontend/insights/components/insights_page_spec.js
ee/spec/frontend/insights/components/insights_page_spec.js
+15
-22
ee/spec/frontend/insights/components/insights_spec.js
ee/spec/frontend/insights/components/insights_spec.js
+24
-25
ee/spec/frontend/insights/insights_router_spec.js
ee/spec/frontend/insights/insights_router_spec.js
+1
-1
ee/spec/frontend/insights/mock_data.js
ee/spec/frontend/insights/mock_data.js
+0
-0
ee/spec/frontend/insights/stores/insights/actions_spec.js
ee/spec/frontend/insights/stores/insights/actions_spec.js
+60
-81
ee/spec/frontend/insights/stores/insights/mutations_spec.js
ee/spec/frontend/insights/stores/insights/mutations_spec.js
+1
-1
No files found.
ee/spec/
javascripts
/insights/components/insights_chart_error_spec.js
→
ee/spec/
frontend
/insights/components/insights_chart_error_spec.js
View file @
60bcc616
...
@@ -20,11 +20,11 @@ describe('Insights chart error component', () => {
...
@@ -20,11 +20,11 @@ describe('Insights chart error component', () => {
});
});
it
(
'
renders the component
'
,
()
=>
{
it
(
'
renders the component
'
,
()
=>
{
expect
(
wrapper
.
find
(
'
.content-title
'
).
text
()).
to
Equal
(
`
${
title
}
: "
${
chartName
}
"`
);
expect
(
wrapper
.
find
(
'
.content-title
'
).
text
()).
to
Be
(
`
${
title
}
: "
${
chartName
}
"`
);
const
summaries
=
wrapper
.
findAll
(
'
.content-summary
'
);
const
summaries
=
wrapper
.
findAll
(
'
.content-summary
'
);
expect
(
summaries
.
at
(
0
).
text
()).
to
Equal
(
summary
);
expect
(
summaries
.
at
(
0
).
text
()).
to
Be
(
summary
);
expect
(
summaries
.
at
(
1
).
text
()).
to
Equal
(
error
);
expect
(
summaries
.
at
(
1
).
text
()).
to
Be
(
error
);
});
});
});
});
ee/spec/
javascripts
/insights/components/insights_chart_spec.js
→
ee/spec/
frontend
/insights/components/insights_chart_spec.js
View file @
60bcc616
import
{
GlColumnChart
,
GlLineChart
,
GlStackedColumnChart
}
from
'
@gitlab/ui/dist/charts
'
;
import
{
GlColumnChart
,
GlLineChart
,
GlStackedColumnChart
}
from
'
@gitlab/ui/dist/charts
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
chartInfo
,
barChartData
,
lineChartData
,
stackedBarChartData
}
from
'
../mock_data
'
;
import
{
chartInfo
,
barChartData
,
lineChartData
,
stackedBarChartData
,
}
from
'
ee_jest/insights/mock_data
'
;
import
InsightsChart
from
'
ee/insights/components/insights_chart.vue
'
;
import
InsightsChart
from
'
ee/insights/components/insights_chart.vue
'
;
import
InsightsChartError
from
'
ee/insights/components/insights_chart_error.vue
'
;
import
InsightsChartError
from
'
ee/insights/components/insights_chart_error.vue
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
...
...
ee/spec/
javascripts
/insights/components/insights_config_warning_spec.js
→
ee/spec/
frontend
/insights/components/insights_config_warning_spec.js
View file @
60bcc616
...
@@ -27,7 +27,7 @@ describe('Insights config warning component', () => {
...
@@ -27,7 +27,7 @@ describe('Insights config warning component', () => {
.
attributes
(
'
src
'
),
.
attributes
(
'
src
'
),
).
toContain
(
image
);
).
toContain
(
image
);
expect
(
wrapper
.
find
(
'
.content-title
'
).
text
()).
to
Equal
(
title
);
expect
(
wrapper
.
find
(
'
.content-title
'
).
text
()).
to
Be
(
title
);
expect
(
wrapper
.
find
(
'
.content-summary
'
).
text
()).
to
Equal
(
summary
);
expect
(
wrapper
.
find
(
'
.content-summary
'
).
text
()).
to
Be
(
summary
);
});
});
});
});
ee/spec/
javascripts
/insights/components/insights_page_spec.js
→
ee/spec/
frontend
/insights/components/insights_page_spec.js
View file @
60bcc616
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
InsightsPage
from
'
ee/insights/components/insights_page.vue
'
;
import
InsightsPage
from
'
ee/insights/components/insights_page.vue
'
;
import
{
createStore
}
from
'
ee/insights/stores
'
;
import
{
createStore
}
from
'
ee/insights/stores
'
;
import
{
mountComponentWithStore
}
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
mountComponentWithStore
}
from
'
helpers/vue_mount_component_helper
'
;
import
{
chartInfo
,
pageInfo
,
pageInfoNoCharts
}
from
'
../mock_data
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
{
chartInfo
,
pageInfo
,
pageInfoNoCharts
}
from
'
ee_jest/insights/mock_data
'
;
describe
(
'
Insights page component
'
,
()
=>
{
describe
(
'
Insights page component
'
,
()
=>
{
let
component
;
let
component
;
...
@@ -11,7 +12,7 @@ describe('Insights page component', () => {
...
@@ -11,7 +12,7 @@ describe('Insights page component', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
store
=
createStore
();
store
=
createStore
();
spyOn
(
store
,
'
dispatch
'
).
and
.
stub
(
);
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
(()
=>
{}
);
Component
=
Vue
.
extend
(
InsightsPage
);
Component
=
Vue
.
extend
(
InsightsPage
);
});
});
...
@@ -20,17 +21,16 @@ describe('Insights page component', () => {
...
@@ -20,17 +21,16 @@ describe('Insights page component', () => {
});
});
describe
(
'
no chart config available
'
,
()
=>
{
describe
(
'
no chart config available
'
,
()
=>
{
it
(
'
shows an empty state
'
,
done
=>
{
it
(
'
shows an empty state
'
,
()
=>
{
component
=
mountComponentWithStore
(
Component
,
{
component
=
mountComponentWithStore
(
Component
,
{
store
,
store
,
props
:
{
props
:
{
queryEndpoint
:
`
${
gl
.
TEST_HOST
}
/query`
,
queryEndpoint
:
`
${
TEST_HOST
}
/query`
,
pageConfig
:
pageInfoNoCharts
,
pageConfig
:
pageInfoNoCharts
,
},
},
});
});
expect
(
component
.
$el
.
querySelector
(
'
.js-empty-state
'
)).
not
.
toBe
(
null
);
expect
(
component
.
$el
.
querySelector
(
'
.js-empty-state
'
)).
not
.
toBe
(
null
);
done
();
});
});
});
});
...
@@ -39,18 +39,17 @@ describe('Insights page component', () => {
...
@@ -39,18 +39,17 @@ describe('Insights page component', () => {
component
=
mountComponentWithStore
(
Component
,
{
component
=
mountComponentWithStore
(
Component
,
{
store
,
store
,
props
:
{
props
:
{
queryEndpoint
:
`
${
gl
.
TEST_HOST
}
/query`
,
queryEndpoint
:
`
${
TEST_HOST
}
/query`
,
pageConfig
:
pageInfo
,
pageConfig
:
pageInfo
,
},
},
});
});
});
});
it
(
'
fetches chart data when mounted
'
,
done
=>
{
it
(
'
fetches chart data when mounted
'
,
()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/fetchChartData
'
,
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/fetchChartData
'
,
{
endpoint
:
`
${
gl
.
TEST_HOST
}
/query`
,
endpoint
:
`
${
TEST_HOST
}
/query`
,
chart
:
chartInfo
,
chart
:
chartInfo
,
});
});
done
();
});
});
describe
(
'
when charts loading
'
,
()
=>
{
describe
(
'
when charts loading
'
,
()
=>
{
...
@@ -58,35 +57,29 @@ describe('Insights page component', () => {
...
@@ -58,35 +57,29 @@ describe('Insights page component', () => {
component
.
$store
.
state
.
insights
.
pageLoading
=
true
;
component
.
$store
.
state
.
insights
.
pageLoading
=
true
;
});
});
it
(
'
renders loading state
'
,
done
=>
{
it
(
'
renders loading state
'
,
()
=>
{
Vue
.
nextTick
(()
=>
{
return
component
.
$
nextTick
(()
=>
{
expect
(
expect
(
component
.
$el
.
querySelector
(
'
.js-insights-page-container .insights-chart-loading
'
),
component
.
$el
.
querySelector
(
'
.js-insights-page-container .insights-chart-loading
'
),
).
not
.
toBe
(
null
);
).
not
.
toBe
(
null
);
done
();
});
});
});
});
it
(
'
does not display chart area
'
,
done
=>
{
it
(
'
does not display chart area
'
,
()
=>
{
Vue
.
nextTick
(()
=>
{
return
component
.
$
nextTick
(()
=>
{
expect
(
component
.
$el
.
querySelector
(
'
.js-insights-page-container .insights-charts
'
)).
toBe
(
expect
(
component
.
$el
.
querySelector
(
'
.js-insights-page-container .insights-charts
'
)).
toBe
(
null
,
null
,
);
);
done
();
});
});
});
});
});
});
describe
(
'
pageConfig changes
'
,
()
=>
{
describe
(
'
pageConfig changes
'
,
()
=>
{
it
(
'
reflects new state
'
,
done
=>
{
it
(
'
reflects new state
'
,
()
=>
{
// Establish rendered state
component
.
$nextTick
();
component
.
pageConfig
=
pageInfoNoCharts
;
component
.
pageConfig
=
pageInfoNoCharts
;
component
.
$nextTick
(()
=>
{
return
component
.
$nextTick
(()
=>
{
expect
(
component
.
$el
.
querySelector
(
'
.js-empty-state
'
)).
not
.
toBe
(
null
);
expect
(
component
.
$el
.
querySelector
(
'
.js-empty-state
'
)).
not
.
toBe
(
null
);
done
();
});
});
});
});
});
});
...
...
ee/spec/
javascripts
/insights/components/insights_spec.js
→
ee/spec/
frontend
/insights/components/insights_spec.js
View file @
60bcc616
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
Insights
from
'
ee/insights/components/insights.vue
'
;
import
Insights
from
'
ee/insights/components/insights.vue
'
;
import
{
createStore
}
from
'
ee/insights/stores
'
;
import
{
createStore
}
from
'
ee/insights/stores
'
;
import
createRouter
from
'
ee/insights/insights_router
'
;
import
createRouter
from
'
ee/insights/insights_router
'
;
import
{
pageInfo
}
from
'
..
/mock_data
'
;
import
{
pageInfo
}
from
'
ee_jest/insights
/mock_data
'
;
describe
(
'
Insights component
'
,
()
=>
{
describe
(
'
Insights component
'
,
()
=>
{
let
vm
;
let
vm
;
...
@@ -13,14 +14,14 @@ describe('Insights component', () => {
...
@@ -13,14 +14,14 @@ describe('Insights component', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
store
=
createStore
();
store
=
createStore
();
spyOn
(
store
,
'
dispatch
'
).
and
.
stub
(
);
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
(()
=>
{}
);
mountComponent
=
data
=>
{
mountComponent
=
data
=>
{
const
el
=
null
;
const
el
=
null
;
const
props
=
data
||
{
const
props
=
data
||
{
endpoint
:
gl
.
TEST_HOST
,
endpoint
:
TEST_HOST
,
queryEndpoint
:
`
${
gl
.
TEST_HOST
}
/query`
,
queryEndpoint
:
`
${
TEST_HOST
}
/query`
,
};
};
return
new
Component
({
return
new
Component
({
...
@@ -34,22 +35,21 @@ describe('Insights component', () => {
...
@@ -34,22 +35,21 @@ describe('Insights component', () => {
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
store
.
dispatch
.
mockReset
();
vm
.
$destroy
();
vm
.
$destroy
();
});
});
it
(
'
fetches config data when mounted
'
,
done
=>
{
it
(
'
fetches config data when mounted
'
,
()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/fetchConfigData
'
,
gl
.
TEST_HOST
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/fetchConfigData
'
,
TEST_HOST
);
done
();
});
});
describe
(
'
when loading config
'
,
()
=>
{
describe
(
'
when loading config
'
,
()
=>
{
it
(
'
renders config loading state
'
,
done
=>
{
it
(
'
renders config loading state
'
,
()
=>
{
vm
.
$store
.
state
.
insights
.
configLoading
=
true
;
vm
.
$store
.
state
.
insights
.
configLoading
=
true
;
vm
.
$nextTick
(()
=>
{
return
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.insights-config-loading
'
)).
not
.
toBe
(
null
);
expect
(
vm
.
$el
.
querySelector
(
'
.insights-config-loading
'
)).
not
.
toBe
(
null
);
expect
(
vm
.
$el
.
querySelector
(
'
.insights-wrapper
'
)).
toBe
(
null
);
expect
(
vm
.
$el
.
querySelector
(
'
.insights-wrapper
'
)).
toBe
(
null
);
done
();
});
});
});
});
});
});
...
@@ -68,13 +68,12 @@ describe('Insights component', () => {
...
@@ -68,13 +68,12 @@ describe('Insights component', () => {
};
};
});
});
it
(
'
has the correct nav tabs
'
,
done
=>
{
it
(
'
has the correct nav tabs
'
,
()
=>
{
vm
.
$nextTick
(()
=>
{
return
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown
'
)).
not
.
toBe
(
null
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown
'
)).
not
.
toBe
(
null
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown .dropdown-item
'
).
innerText
.
trim
()).
toBe
(
expect
(
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown .dropdown-item
'
).
innerText
.
trim
()).
toBe
(
title
,
title
,
);
);
done
();
});
});
});
});
...
@@ -83,12 +82,11 @@ describe('Insights component', () => {
...
@@ -83,12 +82,11 @@ describe('Insights component', () => {
vm
.
$store
.
state
.
insights
.
pageLoading
=
true
;
vm
.
$store
.
state
.
insights
.
pageLoading
=
true
;
});
});
it
(
'
disables the tab selector
'
,
done
=>
{
it
(
'
disables the tab selector
'
,
()
=>
{
vm
.
$nextTick
(()
=>
{
return
vm
.
$nextTick
(()
=>
{
expect
(
expect
(
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown > button
'
).
getAttribute
(
'
disabled
'
),
vm
.
$el
.
querySelector
(
'
.js-insights-dropdown > button
'
).
getAttribute
(
'
disabled
'
),
).
toBe
(
'
disabled
'
);
).
toBe
(
'
disabled
'
);
done
();
});
});
});
});
});
});
...
@@ -100,12 +98,11 @@ describe('Insights component', () => {
...
@@ -100,12 +98,11 @@ describe('Insights component', () => {
vm
.
$store
.
state
.
insights
.
configData
=
null
;
vm
.
$store
.
state
.
insights
.
configData
=
null
;
});
});
it
(
'
it displays a warning
'
,
done
=>
{
it
(
'
it displays a warning
'
,
()
=>
{
vm
.
$nextTick
(()
=>
{
return
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.js-empty-state
'
).
innerText
.
trim
()).
toContain
(
expect
(
vm
.
$el
.
querySelector
(
'
.js-empty-state
'
).
innerText
.
trim
()).
toContain
(
'
Invalid Insights config file detected
'
,
'
Invalid Insights config file detected
'
,
);
);
done
();
});
});
});
});
});
});
...
@@ -128,22 +125,24 @@ describe('Insights component', () => {
...
@@ -128,22 +125,24 @@ describe('Insights component', () => {
window
.
location
.
hash
=
''
;
window
.
location
.
hash
=
''
;
});
});
it
(
'
selects the first tab if invalid
'
,
done
=>
{
it
(
'
selects the first tab if invalid
'
,
()
=>
{
window
.
location
.
hash
=
'
#/invalid
'
;
window
.
location
.
hash
=
'
#/invalid
'
;
vm
.
$nextTick
(()
=>
{
jest
.
runOnlyPendingTimers
();
return
vm
.
$nextTick
(()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/setActiveTab
'
,
defaultKey
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/setActiveTab
'
,
defaultKey
);
});
});
done
();
});
});
it
(
'
selects the specified tab if valid
'
,
done
=>
{
it
(
'
selects the specified tab if valid
'
,
()
=>
{
window
.
location
.
hash
=
`#/
${
selectedKey
}
`
;
window
.
location
.
hash
=
`#/
${
selectedKey
}
`
;
vm
.
$nextTick
(()
=>
{
jest
.
runOnlyPendingTimers
();
return
vm
.
$nextTick
(()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/setActiveTab
'
,
selectedKey
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
insights/setActiveTab
'
,
selectedKey
);
});
});
done
();
});
});
});
});
});
});
ee/spec/
javascripts
/insights/insights_router_spec.js
→
ee/spec/
frontend
/insights/insights_router_spec.js
View file @
60bcc616
...
@@ -11,7 +11,7 @@ describe('insights router', () => {
...
@@ -11,7 +11,7 @@ describe('insights router', () => {
it
(
`sets the activeTab when route changed`
,
()
=>
{
it
(
`sets the activeTab when route changed`
,
()
=>
{
const
route
=
'
route
'
;
const
route
=
'
route
'
;
spyOn
(
store
,
'
dispatch
'
).
and
.
stub
(
);
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
(()
=>
{}
);
router
.
push
(
`/
${
route
}
`
);
router
.
push
(
`/
${
route
}
`
);
...
...
ee/spec/
javascripts
/insights/mock_data.js
→
ee/spec/
frontend
/insights/mock_data.js
View file @
60bcc616
File moved
ee/spec/
javascripts
/insights/stores/insights/actions_spec.js
→
ee/spec/
frontend
/insights/stores/insights/actions_spec.js
View file @
60bcc616
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
testAction
from
'
spec/helpers/vuex_action_helper
'
;
import
createFlash
from
'
~/flash
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
actionsModule
,
*
as
actions
from
'
ee/insights/stores/modules/insights/actions
'
;
import
*
as
actions
from
'
ee/insights/stores/modules/insights/actions
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
const
ERROR_MESSAGE
=
'
TEST_ERROR_MESSAGE
'
;
const
ERROR_MESSAGE
=
'
TEST_ERROR_MESSAGE
'
;
jest
.
mock
(
'
~/flash
'
);
describe
(
'
Insights store actions
'
,
()
=>
{
describe
(
'
Insights store actions
'
,
()
=>
{
const
key
=
'
bugsPerTeam
'
;
const
key
=
'
bugsPerTeam
'
;
const
chart
=
{
const
chart
=
{
...
@@ -32,59 +36,50 @@ describe('Insights store actions', () => {
...
@@ -32,59 +36,50 @@ describe('Insights store actions', () => {
});
});
describe
(
'
requestConfig
'
,
()
=>
{
describe
(
'
requestConfig
'
,
()
=>
{
it
(
'
commits REQUEST_CONFIG
'
,
done
=>
{
it
(
'
commits REQUEST_CONFIG
'
,
()
=>
{
testAction
(
actions
.
requestConfig
,
null
,
null
,
[{
type
:
'
REQUEST_CONFIG
'
}],
[],
done
);
return
testAction
(
actions
.
requestConfig
,
null
,
null
,
[{
type
:
'
REQUEST_CONFIG
'
}],
[]
);
});
});
});
});
describe
(
'
receiveConfigSuccess
'
,
()
=>
{
describe
(
'
receiveConfigSuccess
'
,
()
=>
{
it
(
'
commits RECEIVE_CONFIG_SUCCESS
'
,
done
=>
{
it
(
'
commits RECEIVE_CONFIG_SUCCESS
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
receiveConfigSuccess
,
actions
.
receiveConfigSuccess
,
[
configData
],
[
configData
],
null
,
null
,
[{
type
:
'
RECEIVE_CONFIG_SUCCESS
'
,
payload
:
[
configData
]
}],
[{
type
:
'
RECEIVE_CONFIG_SUCCESS
'
,
payload
:
[
configData
]
}],
[],
[],
done
,
);
);
});
});
});
});
describe
(
'
receiveConfigError
'
,
()
=>
{
describe
(
'
receiveConfigError
'
,
()
=>
{
let
flashSpy
;
it
(
'
commits RECEIVE_CONFIG_ERROR and shows flash message
'
,
()
=>
{
return
testAction
(
beforeEach
(()
=>
{
flashSpy
=
spyOnDependency
(
actionsModule
,
'
createFlash
'
);
});
it
(
'
commits RECEIVE_CONFIG_ERROR and shows flash message
'
,
done
=>
{
testAction
(
actions
.
receiveConfigError
,
actions
.
receiveConfigError
,
ERROR_MESSAGE
,
ERROR_MESSAGE
,
null
,
null
,
[{
type
:
'
RECEIVE_CONFIG_ERROR
'
}],
[{
type
:
'
RECEIVE_CONFIG_ERROR
'
}],
[],
[],
()
=>
{
()
=>
{
expect
(
flashSpy
).
toHaveBeenCalledWith
(
expect
(
createFlash
).
toHaveBeenCalledWith
(
`There was an error fetching configuration for charts:
${
ERROR_MESSAGE
}
`
,
`There was an error fetching configuration for charts:
${
ERROR_MESSAGE
}
`
,
);
);
done
();
},
},
);
);
});
});
it
(
'
flashes Unknown Error when error message is falsey
'
,
done
=>
{
it
(
'
flashes Unknown Error when error message is falsey
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
receiveConfigError
,
actions
.
receiveConfigError
,
null
,
null
,
null
,
null
,
jasmine
.
any
(
Array
),
jasmine
.
any
(
Array
),
jasmine
.
any
(
Array
),
jasmine
.
any
(
Array
),
()
=>
{
()
=>
{
expect
(
flashSpy
).
toHaveBeenCalledWith
(
expect
(
createFlash
).
toHaveBeenCalledWith
(
`There was an error fetching configuration for charts: Unknown Error`
,
`There was an error fetching configuration for charts: Unknown Error`
,
);
);
done
();
},
},
);
);
});
});
...
@@ -103,51 +98,48 @@ describe('Insights store actions', () => {
...
@@ -103,51 +98,48 @@ describe('Insights store actions', () => {
describe
(
'
success calls
'
,
()
=>
{
describe
(
'
success calls
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
.
onGet
(
gl
.
TEST_HOST
).
reply
(
200
,
configData
);
mock
.
onGet
(
TEST_HOST
).
reply
(
200
,
configData
);
});
});
it
(
'
calls requestConfig and receiveConfigSuccess
'
,
done
=>
{
it
(
'
calls requestConfig and receiveConfigSuccess
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
fetchConfigData
,
actions
.
fetchConfigData
,
gl
.
TEST_HOST
,
TEST_HOST
,
{},
{},
[],
[],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigSuccess
'
,
payload
:
configData
}],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigSuccess
'
,
payload
:
configData
}],
done
,
);
);
});
});
});
});
describe
(
'
failed calls
'
,
()
=>
{
describe
(
'
failed calls
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
.
onGet
(
gl
.
TEST_HOST
).
reply
(
500
,
{
message
:
ERROR_MESSAGE
});
mock
.
onGet
(
TEST_HOST
).
reply
(
500
,
{
message
:
ERROR_MESSAGE
});
});
});
it
(
'
calls receiveConfigError upon error from service
'
,
done
=>
{
it
(
'
calls receiveConfigError upon error from service
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
fetchConfigData
,
actions
.
fetchConfigData
,
gl
.
TEST_HOST
,
TEST_HOST
,
{},
{},
[],
[],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigError
'
,
payload
:
ERROR_MESSAGE
}],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigError
'
,
payload
:
ERROR_MESSAGE
}],
done
,
);
);
});
});
});
});
describe
(
'
success calls with null data
'
,
()
=>
{
describe
(
'
success calls with null data
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
.
onGet
(
gl
.
TEST_HOST
).
reply
(
200
,
null
);
mock
.
onGet
(
TEST_HOST
).
reply
(
200
,
null
);
});
});
it
(
'
calls receiveConfigError upon null config data returned
'
,
done
=>
{
it
(
'
calls receiveConfigError upon null config data returned
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
fetchConfigData
,
actions
.
fetchConfigData
,
gl
.
TEST_HOST
,
TEST_HOST
,
{},
{},
[],
[],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigError
'
}],
[{
type
:
'
requestConfig
'
},
{
type
:
'
receiveConfigError
'
}],
done
,
);
);
});
});
});
});
...
@@ -156,8 +148,8 @@ describe('Insights store actions', () => {
...
@@ -156,8 +148,8 @@ describe('Insights store actions', () => {
describe
(
'
receiveChartDataSuccess
'
,
()
=>
{
describe
(
'
receiveChartDataSuccess
'
,
()
=>
{
const
chartData
=
{
type
:
CHART_TYPES
.
BAR
,
data
:
{}
};
const
chartData
=
{
type
:
CHART_TYPES
.
BAR
,
data
:
{}
};
it
(
'
commits RECEIVE_CHART_SUCCESS
'
,
done
=>
{
it
(
'
commits RECEIVE_CHART_SUCCESS
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
receiveChartDataSuccess
,
actions
.
receiveChartDataSuccess
,
{
chart
,
data
:
chartData
},
{
chart
,
data
:
chartData
},
null
,
null
,
...
@@ -168,7 +160,6 @@ describe('Insights store actions', () => {
...
@@ -168,7 +160,6 @@ describe('Insights store actions', () => {
},
},
],
],
[],
[],
done
,
);
);
});
});
});
});
...
@@ -176,8 +167,8 @@ describe('Insights store actions', () => {
...
@@ -176,8 +167,8 @@ describe('Insights store actions', () => {
describe
(
'
receiveChartDataError
'
,
()
=>
{
describe
(
'
receiveChartDataError
'
,
()
=>
{
const
error
=
'
myError
'
;
const
error
=
'
myError
'
;
it
(
'
commits RECEIVE_CHART_ERROR
'
,
done
=>
{
it
(
'
commits RECEIVE_CHART_ERROR
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
receiveChartDataError
,
actions
.
receiveChartDataError
,
{
chart
,
error
},
{
chart
,
error
},
null
,
null
,
...
@@ -188,7 +179,6 @@ describe('Insights store actions', () => {
...
@@ -188,7 +179,6 @@ describe('Insights store actions', () => {
},
},
],
],
[],
[],
done
,
);
);
});
});
});
});
...
@@ -196,7 +186,7 @@ describe('Insights store actions', () => {
...
@@ -196,7 +186,7 @@ describe('Insights store actions', () => {
describe
(
'
fetchChartData
'
,
()
=>
{
describe
(
'
fetchChartData
'
,
()
=>
{
let
mock
;
let
mock
;
let
dispatch
;
let
dispatch
;
const
payload
=
{
endpoint
:
`
${
gl
.
TEST_HOST
}
/query`
,
chart
};
const
payload
=
{
endpoint
:
`
${
TEST_HOST
}
/query`
,
chart
};
const
chartData
=
{
const
chartData
=
{
labels
:
[
'
January
'
,
'
February
'
],
labels
:
[
'
January
'
,
'
February
'
],
...
@@ -217,7 +207,7 @@ describe('Insights store actions', () => {
...
@@ -217,7 +207,7 @@ describe('Insights store actions', () => {
};
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
dispatch
=
j
est
.
fn
().
mockName
(
'
dispatch
'
);
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
});
});
...
@@ -227,47 +217,39 @@ describe('Insights store actions', () => {
...
@@ -227,47 +217,39 @@ describe('Insights store actions', () => {
describe
(
'
successful request
'
,
()
=>
{
describe
(
'
successful request
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
.
onPost
(
`
${
gl
.
TEST_HOST
}
/query`
,
chart
).
reply
(
200
,
chartData
);
mock
.
onPost
(
`
${
TEST_HOST
}
/query`
,
chart
).
reply
(
200
,
chartData
);
});
});
it
(
'
calls receiveChartDataSuccess with chart data
'
,
done
=>
{
it
(
'
calls receiveChartDataSuccess with chart data
'
,
()
=>
{
const
context
=
{
const
context
=
{
dispatch
,
dispatch
,
};
};
actions
return
actions
.
fetchChartData
(
context
,
payload
).
then
(()
=>
{
.
fetchChartData
(
context
,
payload
)
expect
(
dispatch
.
mock
.
calls
[
0
]).
toEqual
([
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
argsFor
(
0
)).
toEqual
([
'
receiveChartDataSuccess
'
,
'
receiveChartDataSuccess
'
,
{
chart
,
data
:
chartData
},
{
chart
,
data
:
chartData
},
]);
]);
})
});
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
});
describe
(
'
failed request
'
,
()
=>
{
describe
(
'
failed request
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
.
onPost
(
`
${
gl
.
TEST_HOST
}
/query`
,
chart
).
reply
(
500
);
mock
.
onPost
(
`
${
TEST_HOST
}
/query`
,
chart
).
reply
(
500
);
});
});
it
(
'
calls receiveChartDataError with error message
'
,
done
=>
{
it
(
'
calls receiveChartDataError with error message
'
,
()
=>
{
const
context
=
{
const
context
=
{
dispatch
,
dispatch
,
};
};
actions
return
actions
.
fetchChartData
(
context
,
payload
).
then
(()
=>
{
.
fetchChartData
(
context
,
payload
)
expect
(
dispatch
.
mock
.
calls
[
0
]).
toEqual
([
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
argsFor
(
0
)).
toEqual
([
'
receiveChartDataError
'
,
'
receiveChartDataError
'
,
{
chart
,
error
:
'
There was an error gathering the chart data
'
},
{
chart
,
error
:
'
There was an error gathering the chart data
'
},
]);
]);
})
});
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
});
});
});
...
@@ -279,54 +261,51 @@ describe('Insights store actions', () => {
...
@@ -279,54 +261,51 @@ describe('Insights store actions', () => {
state
=
{
configData
};
state
=
{
configData
};
});
});
it
(
'
commits SET_ACTIVE_TAB and SET_ACTIVE_PAGE
'
,
done
=>
{
it
(
'
commits SET_ACTIVE_TAB and SET_ACTIVE_PAGE
'
,
()
=>
{
testAction
(
return
testAction
(
actions
.
setActiveTab
,
actions
.
setActiveTab
,
key
,
key
,
state
,
state
,
[{
type
:
'
SET_ACTIVE_TAB
'
,
payload
:
key
},
{
type
:
'
SET_ACTIVE_PAGE
'
,
payload
:
page
}],
[{
type
:
'
SET_ACTIVE_TAB
'
,
payload
:
key
},
{
type
:
'
SET_ACTIVE_PAGE
'
,
payload
:
page
}],
[],
[],
done
,
);
);
});
});
it
(
'
does not mutate with no configData
'
,
done
=>
{
it
(
'
does not mutate with no configData
'
,
()
=>
{
state
=
{
configData
:
null
};
state
=
{
configData
:
null
};
testAction
(
actions
.
setActiveTab
,
key
,
state
,
[],
[]
,
done
);
testAction
(
actions
.
setActiveTab
,
key
,
state
,
[],
[]);
});
});
it
(
'
does not mutate with no matching tab
'
,
done
=>
{
it
(
'
does not mutate with no matching tab
'
,
()
=>
{
testAction
(
actions
.
setActiveTab
,
'
invalidTab
'
,
state
,
[],
[]
,
done
);
testAction
(
actions
.
setActiveTab
,
'
invalidTab
'
,
state
,
[],
[]);
});
});
});
});
describe
(
'
initChartData
'
,
()
=>
{
describe
(
'
initChartData
'
,
()
=>
{
it
(
'
commits INIT_CHART_DATA
'
,
done
=>
{
it
(
'
commits INIT_CHART_DATA
'
,
()
=>
{
const
keys
=
[
'
a
'
,
'
b
'
];
const
keys
=
[
'
a
'
,
'
b
'
];
testAction
(
return
testAction
(
actions
.
initChartData
,
actions
.
initChartData
,
keys
,
keys
,
null
,
null
,
[{
type
:
'
INIT_CHART_DATA
'
,
payload
:
keys
}],
[{
type
:
'
INIT_CHART_DATA
'
,
payload
:
keys
}],
[],
[],
done
,
);
);
});
});
});
});
describe
(
'
setPageLoading
'
,
()
=>
{
describe
(
'
setPageLoading
'
,
()
=>
{
it
(
'
commits SET_PAGE_LOADING
'
,
done
=>
{
it
(
'
commits SET_PAGE_LOADING
'
,
()
=>
{
const
pageLoading
=
false
;
const
pageLoading
=
false
;
testAction
(
return
testAction
(
actions
.
setPageLoading
,
actions
.
setPageLoading
,
pageLoading
,
pageLoading
,
null
,
null
,
[{
type
:
'
SET_PAGE_LOADING
'
,
payload
:
false
}],
[{
type
:
'
SET_PAGE_LOADING
'
,
payload
:
false
}],
[],
[],
done
,
);
);
});
});
});
});
...
...
ee/spec/frontend/insights/stores/insights/mutations_spec.js
View file @
60bcc616
...
@@ -3,7 +3,7 @@ import mutations from 'ee/insights/stores/modules/insights/mutations';
...
@@ -3,7 +3,7 @@ import mutations from 'ee/insights/stores/modules/insights/mutations';
import
*
as
types
from
'
ee/insights/stores/modules/insights/mutation_types
'
;
import
*
as
types
from
'
ee/insights/stores/modules/insights/mutation_types
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
import
{
CHART_TYPES
}
from
'
ee/insights/constants
'
;
import
{
configData
}
from
'
../../../../javascripts
/insights/mock_data
'
;
import
{
configData
}
from
'
ee_jest
/insights/mock_data
'
;
describe
(
'
Insights mutations
'
,
()
=>
{
describe
(
'
Insights mutations
'
,
()
=>
{
let
state
;
let
state
;
...
...
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