Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
David Goessmann
logging-scratch-gui
Commits
616281ea
Commit
616281ea
authored
6 years ago
by
Ray Schamp
Browse files
Options
Downloads
Patches
Plain Diff
Add VMManagerHOC tests
parent
739ee704
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/vm-manager-hoc.jsx
+6
-1
6 additions, 1 deletion
src/lib/vm-manager-hoc.jsx
test/unit/util/vm-manager-hoc.test.jsx
+101
-0
101 additions, 0 deletions
test/unit/util/vm-manager-hoc.test.jsx
with
107 additions
and
1 deletion
src/lib/vm-manager-hoc.jsx
+
6
−
1
View file @
616281ea
...
...
@@ -104,9 +104,14 @@ const vmManagerHOC = function (WrappedComponent) {
onLoadedProject
:
loadingState
=>
dispatch
(
onLoadedProject
(
loadingState
))
});
const
mergeProps
=
(
stateProps
,
dispatchProps
,
ownProps
)
=>
Object
.
assign
(
{},
stateProps
,
dispatchProps
,
ownProps
);
return
connect
(
mapStateToProps
,
mapDispatchToProps
mapDispatchToProps
,
mergeProps
)(
VMManager
);
};
...
...
This diff is collapsed.
Click to expand it.
test/unit/util/vm-manager-hoc.test.jsx
0 → 100644
+
101
−
0
View file @
616281ea
import
'
web-audio-test-api
'
;
import
React
from
'
react
'
;
import
configureStore
from
'
redux-mock-store
'
;
import
{
mount
}
from
'
enzyme
'
;
import
VM
from
'
scratch-vm
'
;
import
{
LoadingState
}
from
'
../../../src/reducers/project-state
'
;
import
vmManagerHOC
from
'
../../../src/lib/vm-manager-hoc.jsx
'
;
describe
(
'
VMManagerHOC
'
,
()
=>
{
const
mockStore
=
configureStore
();
let
store
;
let
vm
;
beforeEach
(()
=>
{
store
=
mockStore
({
scratchGui
:
{
projectState
:
{}
}
});
vm
=
new
VM
();
vm
.
attachAudioEngine
=
jest
.
fn
();
vm
.
setCompatibilityMode
=
jest
.
fn
();
vm
.
start
=
jest
.
fn
();
});
test
(
'
when it mounts, the vm is initialized
'
,
()
=>
{
const
Component
=
()
=>
(<
div
/>);
const
WrappedComponent
=
vmManagerHOC
(
Component
);
mount
(
<
WrappedComponent
store
=
{
store
}
vm
=
{
vm
}
/>
);
expect
(
vm
.
attachAudioEngine
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
vm
.
setCompatibilityMode
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
vm
.
start
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
vm
.
initialized
).
toBe
(
true
);
});
test
(
'
if it mounts with an initialized vm, it does not reinitialize the vm
'
,
()
=>
{
const
Component
=
()
=>
<
div
/>;
const
WrappedComponent
=
vmManagerHOC
(
Component
);
vm
.
initialized
=
true
;
mount
(
<
WrappedComponent
store
=
{
store
}
vm
=
{
vm
}
/>
);
expect
(
vm
.
attachAudioEngine
.
mock
.
calls
.
length
).
toBe
(
0
);
expect
(
vm
.
setCompatibilityMode
.
mock
.
calls
.
length
).
toBe
(
0
);
expect
(
vm
.
start
.
mock
.
calls
.
length
).
toBe
(
0
);
expect
(
vm
.
initialized
).
toBe
(
true
);
});
test
(
'
if the isLoadingWithId prop becomes true, it loads project data into the vm
'
,
()
=>
{
vm
.
loadProject
=
jest
.
fn
(()
=>
Promise
.
resolve
());
const
mockedOnLoadedProject
=
jest
.
fn
();
const
Component
=
()
=>
<
div
/>;
const
WrappedComponent
=
vmManagerHOC
(
Component
);
const
mounted
=
mount
(
<
WrappedComponent
isLoadingWithId
=
{
false
}
store
=
{
store
}
vm
=
{
vm
}
onLoadedProject
=
{
mockedOnLoadedProject
}
/>
);
mounted
.
setProps
({
isLoadingWithId
:
true
,
loadingState
:
LoadingState
.
LOADING_VM_WITH_ID
,
projectData
:
'
100
'
});
expect
(
vm
.
loadProject
).
toHaveBeenLastCalledWith
(
'
100
'
);
// nextTick needed since vm.loadProject is async, and we have to wait for it :/
process
.
nextTick
(()
=>
expect
(
mockedOnLoadedProject
).
toHaveBeenLastCalledWith
(
LoadingState
.
LOADING_VM_WITH_ID
));
});
test
(
'
if there is projectData, the child is rendered
'
,
()
=>
{
const
Component
=
()
=>
<
div
/>;
const
WrappedComponent
=
vmManagerHOC
(
Component
);
const
mounted
=
mount
(
<
WrappedComponent
projectData
=
"100"
store
=
{
store
}
vm
=
{
vm
}
/>
);
expect
(
mounted
.
find
(
'
div
'
).
length
).
toBe
(
1
);
});
test
(
'
if there is no projectData, nothing is rendered
'
,
()
=>
{
const
Component
=
()
=>
<
div
/>;
const
WrappedComponent
=
vmManagerHOC
(
Component
);
const
mounted
=
mount
(
<
WrappedComponent
store
=
{
store
}
vm
=
{
vm
}
/>
);
expect
(
mounted
.
find
(
'
div
'
).
length
).
toBe
(
0
);
});
});
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