Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grady
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Maximilian Michal
grady
Commits
f15d6b21
Commit
f15d6b21
authored
6 years ago
by
Dominik Seeger
Committed by
robinwilliam.hundt
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
added tests for DataExport component
parent
c535b6b0
No related branches found
No related tags found
1 merge request
!128
Merge improve testing
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/tests/unit/components/DataExport.spec.ts
+97
-0
97 additions, 0 deletions
frontend/tests/unit/components/DataExport.spec.ts
with
97 additions
and
0 deletions
frontend/tests/unit/components/DataExport.spec.ts
0 → 100644
+
97
−
0
View file @
f15d6b21
import
Vuex
from
'
vuex
'
import
{
mount
,
createLocalVue
}
from
'
@vue/test-utils
'
import
DataExport
from
'
@/components/export/DataExport.vue
'
import
sinon
from
'
sinon
'
import
chai
from
'
chai
'
import
VueRouter
from
'
vue-router
'
import
*
as
api
from
'
@/api
'
chai
.
should
()
let
localVue
=
createLocalVue
()
localVue
.
use
(
Vuex
)
localVue
.
use
(
VueRouter
)
let
router
=
new
VueRouter
()
// @ts-ignore
global
.
requestAnimationFrame
=
cb
=>
cb
()
describe
(
'
DataExport Component Unit Tests
'
,
()
=>
{
let
store
:
any
=
null
let
consoleTemp
=
{
warn
:
console
.
warn
,
error
:
console
.
error
}
// for creating test data
let
students
=
[{
Matrikel
:
1000000
,
Name
:
'
test
'
,
Username
:
'
test
'
,
Sum
:
100
,
Exam
:
'
test
'
,
Password
:
'
test
'
,
Scores
:
{
type
:
'
test
'
,
score
:
100
}
}]
before
(
function
()
{
console
.
warn
=
function
()
{}
console
.
error
=
function
()
{}
})
after
(
function
()
{
console
.
warn
=
consoleTemp
.
warn
console
.
error
=
consoleTemp
.
error
})
beforeEach
(()
=>
{
store
=
new
Vuex
.
Store
({
state
:
{}
})
})
afterEach
(()
=>
{
sinon
.
restore
()
})
it
(
'
should download CSV when selected
'
,
()
=>
{
let
wrapper
=
mount
(
DataExport
,
{
localVue
:
localVue
,
store
})
wrapper
.
vm
.
$data
.
exportType
=
'
CSV
'
let
spy
=
sinon
.
spy
()
// @ts-ignore
sinon
.
replace
(
wrapper
.
vm
,
'
jsonToCSV
'
,
spy
)
// @ts-ignore
sinon
.
replace
(
wrapper
.
vm
,
'
createDownloadPopup
'
,
sinon
.
spy
())
// @ts-ignore
wrapper
.
vm
.
optionalConvertAndCreatePopup
(
students
)
spy
.
called
.
should
.
equal
(
true
)
})
it
(
'
should download JSON when selected
'
,
()
=>
{
let
wrapper
=
mount
(
DataExport
,
{
localVue
:
localVue
,
store
})
wrapper
.
vm
.
$data
.
exportType
=
'
JSON
'
let
spy
=
sinon
.
spy
()
// @ts-ignore
sinon
.
replace
(
wrapper
.
vm
,
'
jsonToCSV
'
,
spy
)
// @ts-ignore
sinon
.
replace
(
wrapper
.
vm
,
'
createDownloadPopup
'
,
sinon
.
spy
())
// @ts-ignore
wrapper
.
vm
.
optionalConvertAndCreatePopup
(
students
)
spy
.
called
.
should
.
equal
(
false
)
})
it
(
'
should download obfuscated data when no mapping was selected
'
,
async
()
=>
{
let
wrapper
=
mount
(
DataExport
,
{
localVue
:
localVue
,
store
})
let
stub
=
sinon
.
stub
().
returns
(
Promise
.
resolve
({
data
:
students
}))
let
spy
=
sinon
.
spy
()
// @ts-ignore replace ax.post because of fetch in getExportFile
sinon
.
replace
(
api
.
default
,
'
post
'
,
stub
)
// @ts-ignore
sinon
.
replace
(
wrapper
.
vm
,
'
optionalConvertAndCreatePopup
'
,
spy
)
// @ts-ignore
await
wrapper
.
vm
.
getExportFile
(
'
data
'
)
spy
.
called
.
should
.
equal
(
true
)
spy
.
calledWithExactly
(
students
).
should
.
equal
(
true
)
})
it
(
'
should download deobfuscated data when no mapping was selected
'
,
async
()
=>
{
})
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment