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
bf74b3ef
Commit
bf74b3ef
authored
6 years ago
by
Ray Schamp
Browse files
Options
Downloads
Patches
Plain Diff
Fix HashParserHOC tests
parent
91028a0a
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/hash-parser-hoc.jsx
+5
-1
5 additions, 1 deletion
src/lib/hash-parser-hoc.jsx
test/unit/util/hash-project-loader-hoc.test.jsx
+47
-11
47 additions, 11 deletions
test/unit/util/hash-project-loader-hoc.test.jsx
with
52 additions
and
12 deletions
src/lib/hash-parser-hoc.jsx
+
5
−
1
View file @
bf74b3ef
...
...
@@ -79,9 +79,13 @@ const HashParserHOC = function (WrappedComponent) {
const
mapDispatchToProps
=
dispatch
=>
({
setProjectId
:
projectId
=>
dispatch
(
setProjectId
(
projectId
))
});
const
mergeProps
=
(
stateProps
,
dispatchProps
,
ownProps
)
=>
Object
.
assign
(
{},
stateProps
,
dispatchProps
,
ownProps
);
return
connect
(
mapStateToProps
,
mapDispatchToProps
mapDispatchToProps
,
mergeProps
)(
HashParserComponent
);
};
...
...
This diff is collapsed.
Click to expand it.
test/unit/util/hash-project-loader-hoc.test.jsx
+
47
−
11
View file @
bf74b3ef
import
React
from
'
react
'
;
import
HashParserHOC
from
'
../../../src/lib/hash-parser-hoc.jsx
'
;
import
configureStore
from
'
redux-mock-store
'
;
import
{
mount
}
from
'
enzyme
'
;
import
HashParserHOC
from
'
../../../src/lib/hash-parser-hoc.jsx
'
;
jest
.
mock
(
'
react-ga
'
);
describe
(
'
HashParserHOC
'
,
()
=>
{
const
mockStore
=
configureStore
();
let
store
;
beforeEach
(()
=>
{
store
=
mockStore
({
scratchGui
:
{
projectState
:
{}
}
});
});
test
(
'
when there is a hash, it passes the hash as projectId
'
,
()
=>
{
const
Component
=
({
projectId
})
=>
<
div
>
{
projectId
}
</
div
>;
const
WrappedComponent
=
HashParserHOC
(
Component
);
window
.
location
.
hash
=
'
#1234567
'
;
const
mounted
=
mount
(<
WrappedComponent
/>);
expect
(
mounted
.
state
().
projectId
).
toEqual
(
'
1234567
'
);
const
mockSetProjectIdFunc
=
jest
.
fn
();
mount
(
<
WrappedComponent
setProjectId
=
{
mockSetProjectIdFunc
}
store
=
{
store
}
/>
);
expect
(
mockSetProjectIdFunc
.
mock
.
calls
[
0
][
0
]).
toBe
(
'
1234567
'
);
});
test
(
'
when there is no hash, it passes 0 as the projectId
'
,
()
=>
{
const
Component
=
({
projectId
})
=>
<
div
>
{
projectId
}
</
div
>;
const
WrappedComponent
=
HashParserHOC
(
Component
);
window
.
location
.
hash
=
''
;
const
mounted
=
mount
(<
WrappedComponent
/>);
expect
(
mounted
.
state
().
projectId
).
toEqual
(
0
);
const
mockSetProjectIdFunc
=
jest
.
fn
();
mount
(
<
WrappedComponent
setProjectId
=
{
mockSetProjectIdFunc
}
store
=
{
store
}
/>
);
expect
(
mockSetProjectIdFunc
.
mock
.
calls
[
0
][
0
]).
toBe
(
0
);
});
test
(
'
when the hash is not a number, it passes 0 as projectId
'
,
()
=>
{
const
Component
=
({
projectId
})
=>
<
div
>
{
projectId
}
</
div
>;
const
WrappedComponent
=
HashParserHOC
(
Component
);
window
.
location
.
hash
=
'
#winning
'
;
const
mounted
=
mount
(<
WrappedComponent
/>);
expect
(
mounted
.
state
().
projectId
).
toEqual
(
0
);
const
mockSetProjectIdFunc
=
jest
.
fn
();
mount
(
<
WrappedComponent
setProjectId
=
{
mockSetProjectIdFunc
}
store
=
{
store
}
/>
);
expect
(
mockSetProjectIdFunc
.
mock
.
calls
[
0
][
0
]).
toBe
(
0
);
});
test
(
'
when hash change happens, the projectId state is changed
'
,
()
=>
{
const
Component
=
({
projectId
})
=>
<
div
>
{
projectId
}
</
div
>;
const
WrappedComponent
=
HashParserHOC
(
Component
);
window
.
location
.
hash
=
''
;
const
mounted
=
mount
(<
WrappedComponent
/>);
expect
(
mounted
.
state
().
projectId
).
toEqual
(
0
);
const
mockSetProjectIdFunc
=
jest
.
fn
();
const
mounted
=
mount
(
<
WrappedComponent
setProjectId
=
{
mockSetProjectIdFunc
}
store
=
{
store
}
/>
);
window
.
location
.
hash
=
'
#1234567
'
;
mounted
.
instance
().
handleHashChange
();
expect
(
mo
unted
.
state
().
projectId
).
toEqual
(
'
1234567
'
);
mounted
.
childAt
(
0
).
instance
().
handleHashChange
();
expect
(
mo
ckSetProjectIdFunc
.
mock
.
calls
.
length
).
toBe
(
2
);
});
});
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