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
423bbfb1
Commit
423bbfb1
authored
Mar 02, 2020
by
Martin Wortschack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate issues analytics component spec to jest
parent
b7fa9dc4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
ee/spec/frontend/issues_analytics/components/issues_analytics_spec.js
...tend/issues_analytics/components/issues_analytics_spec.js
+103
-0
No files found.
ee/spec/
javascripts
/issues_analytics/components/issues_analytics_spec.js
→
ee/spec/
frontend
/issues_analytics/components/issues_analytics_spec.js
View file @
423bbfb1
import
axios
from
'
axios
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
Vuex
from
'
vuex
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
IssuesAnalytics
from
'
ee/issues_analytics/components/issues_analytics.vue
'
;
import
IssuesAnalytics
from
'
ee/issues_analytics/components/issues_analytics.vue
'
;
import
EmptyState
from
'
ee/issues_analytics/components/empty_state.vue
'
;
import
EmptyState
from
'
ee/issues_analytics/components/empty_state.vue
'
;
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
{
createStore
}
from
'
ee/issues_analytics/stores
'
;
import
{
createStore
}
from
'
ee/issues_analytics/stores
'
;
const
localVue
=
createLocalVue
();
const
localVue
=
createLocalVue
();
localVue
.
use
(
Vuex
);
describe
(
'
Issues Analytics component
'
,
()
=>
{
describe
(
'
Issues Analytics component
'
,
()
=>
{
let
vm
;
let
wrapper
;
let
store
;
let
store
;
let
mountComponent
;
let
mountComponent
;
let
axiosMock
;
const
mockChartData
=
{
'
2017-11
'
:
0
,
'
2017-12
'
:
2
};
const
mockChartData
=
{
'
2017-11
'
:
0
,
'
2017-12
'
:
2
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
axiosMock
=
new
MockAdapter
(
axios
);
store
=
createStore
();
store
=
createStore
();
spyOn
(
store
,
'
dispatch
'
).
and
.
stub
();
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
();
mountComponent
=
data
=>
{
mountComponent
=
data
=>
{
setFixtures
(
'
<div id="mock-filter"></div>
'
);
setFixtures
(
'
<div id="mock-filter"></div>
'
);
const
props
=
data
||
{
const
props
Data
=
data
||
{
endpoint
:
gl
.
TEST_HOST
,
endpoint
:
TEST_HOST
,
filterBlockEl
:
document
.
querySelector
(
'
#mock-filter
'
),
filterBlockEl
:
document
.
querySelector
(
'
#mock-filter
'
),
};
};
return
shallowMount
(
localVue
.
extend
(
IssuesAnalytics
),
{
return
shallowMount
(
IssuesAnalytics
,
{
propsData
:
props
,
localVue
,
propsData
,
stubs
:
{
stubs
:
{
GlColumnChart
:
true
,
GlColumnChart
:
true
,
EmptyState
,
},
},
store
,
store
,
localVue
,
});
}).
vm
;
};
};
vm
=
mountComponent
();
wrapper
=
mountComponent
();
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
vm
.
$destroy
();
wrapper
.
destroy
();
axiosMock
.
restore
();
});
});
const
findLoadingIcon
=
()
=>
wrapper
.
find
(
GlLoadingIcon
);
const
findChartContainer
=
()
=>
wrapper
.
find
(
'
.issues-analytics-chart
'
);
const
findEmptyState
=
()
=>
wrapper
.
find
(
EmptyState
);
it
(
'
fetches chart data when mounted
'
,
()
=>
{
it
(
'
fetches chart data when mounted
'
,
()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
issueAnalytics/fetchChartData
'
,
gl
.
TEST_HOST
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
issueAnalytics/fetchChartData
'
,
TEST_HOST
);
});
});
it
(
'
renders loading state when loading
'
,
done
=>
{
it
(
'
renders loading state when loading
'
,
()
=>
{
vm
.
$store
.
state
.
issueAnalytics
.
loading
=
true
;
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
loading
=
true
;
vm
.
$nextTick
(()
=>
{
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.issues-analytics-loading
'
)).
not
.
toBe
(
null
);
expect
(
findLoadingIcon
().
exists
()).
toBe
(
true
);
expect
(
vm
.
$el
.
querySelector
(
'
.issues-analytics-chart
'
)).
toBe
(
null
);
expect
(
findChartContainer
().
exists
()).
toBe
(
false
);
done
();
});
});
});
});
it
(
'
renders chart when data is present
'
,
done
=>
{
it
(
'
renders chart when data is present
'
,
()
=>
{
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
mockChartData
;
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
mockChartData
;
vm
.
$nextTick
(()
=>
{
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.issues-analytics-chart
'
)).
not
.
toBe
(
null
);
expect
(
findChartContainer
().
exists
()).
toBe
(
true
);
done
();
});
});
});
});
it
(
'
fetches data when filters are applied
'
,
done
=>
{
it
(
'
fetches data when filters are applied
'
,
()
=>
{
vm
.
$store
.
state
.
issueAnalytics
.
filters
=
'
?hello=world
'
;
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
filters
=
'
?hello=world
'
;
vm
.
$nextTick
(()
=>
{
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledTimes
(
2
);
expect
(
store
.
dispatch
).
toHaveBeenCalledTimes
(
2
);
expect
(
store
.
dispatch
.
calls
.
argsFor
(
1
)).
toEqual
([
expect
(
store
.
dispatch
.
mock
.
calls
[
1
]).
toEqual
([
'
issueAnalytics/fetchChartData
'
,
TEST_HOST
]);
'
issueAnalytics/fetchChartData
'
,
gl
.
TEST_HOST
,
]);
done
();
});
});
});
});
it
(
'
renders empty state when chart data is empty
'
,
done
=>
{
it
(
'
renders empty state when chart data is empty
'
,
()
=>
{
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
{};
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
{};
vm
.
$nextTick
(()
=>
{
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.empty-state
'
)).
not
.
toBe
(
null
);
expect
(
findEmptyState
().
exists
()).
toBe
(
true
);
expect
(
vm
.
showNoDataEmptyState
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
showNoDataEmptyState
).
toBe
(
true
);
done
();
});
});
});
});
it
(
'
renders filters empty state when filters are applied and chart data is empty
'
,
done
=>
{
it
(
'
renders filters empty state when filters are applied and chart data is empty
'
,
()
=>
{
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
{};
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
chartData
=
{};
vm
.
$store
.
state
.
issueAnalytics
.
filters
=
'
?hello=world
'
;
wrapper
.
vm
.
$store
.
state
.
issueAnalytics
.
filters
=
'
?hello=world
'
;
vm
.
$nextTick
(()
=>
{
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.empty-state
'
)).
not
.
toBe
(
null
);
expect
(
findEmptyState
().
exists
()).
toBe
(
true
);
expect
(
vm
.
showFiltersEmptyState
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
showFiltersEmptyState
).
toBe
(
true
);
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