Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
88fcf47e
Commit
88fcf47e
authored
6 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add EditUserModal.integ.spec.js and integration test helpers
parent
3a31c436
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/test/__support__/integration_tests.js
+52
-0
52 additions, 0 deletions
frontend/test/__support__/integration_tests.js
frontend/test/metabase/admin/people/containers/EditUserModal.integ.spec.js
+33
-0
33 additions, 0 deletions
...abase/admin/people/containers/EditUserModal.integ.spec.js
with
85 additions
and
0 deletions
frontend/test/__support__/integration_tests.js
0 → 100644
+
52
−
0
View file @
88fcf47e
import
React
from
"
react
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
{
mount
}
from
"
enzyme
"
;
import
reducers
from
"
metabase/reducers-main
"
;
import
{
getStore
}
from
"
metabase/store
"
;
import
{
MockResponse
}
from
"
xhr-mock
"
;
// helper for JSON responses, also defaults to 200 status code
MockResponse
.
prototype
.
json
=
function
(
object
)
{
return
this
.
status
(
this
.
_status
||
200
)
.
header
(
"
Content-Type
"
,
"
application/json
"
)
.
body
(
JSON
.
stringify
(
object
));
};
export
function
getTestStore
(
reducers
)
{
const
dispatchSpy
=
jest
.
fn
(()
=>
({}));
const
reducerSpy
=
(
state
,
action
)
=>
dispatchSpy
(
action
);
const
store
=
getStore
({
...
reducers
,
reducerSpy
});
store
.
waitForAction
=
function
(
type
)
{
return
new
Promise
(
resolve
=>
{
let
existingCallsCount
=
dispatchSpy
.
mock
.
calls
.
length
;
const
unsubscribe
=
store
.
subscribe
(()
=>
{
const
newCalls
=
dispatchSpy
.
mock
.
calls
.
slice
(
existingCallsCount
);
if
(
newCalls
.
find
(
call
=>
call
[
0
].
type
===
type
))
{
unsubscribe
();
resolve
();
}
else
{
existingCallsCount
=
dispatchSpy
.
mock
.
calls
.
length
;
}
});
});
};
return
store
;
}
export
function
mountWithStore
(
element
)
{
const
store
=
getTestStore
(
reducers
);
const
wrapper
=
mount
(
<
Provider
store
=
{
store
}
>
{
element
}
<
/Provider>
)
;
// NOTE: automatically call wrapper.update when the store changes:
// https://github.com/airbnb/enzyme/blob/ed5848085051ac7afef64a7d045d53b1153a8fe7/docs/guides/migration-from-2-to-3.md#for-mount-updates-are-sometimes-required-when-they-werent-before
store
.
subscribe
(()
=>
wrapper
.
update
());
return
{
wrapper
,
store
};
}
This diff is collapsed.
Click to expand it.
frontend/test/metabase/admin/people/containers/EditUserModal.integ.spec.js
0 → 100644
+
33
−
0
View file @
88fcf47e
import
React
from
"
react
"
;
import
mock
from
"
xhr-mock
"
;
import
{
mountWithStore
}
from
"
__support__/integration_tests
"
;
import
EditUserModal
from
"
metabase/admin/people/containers/EditUserModal
"
;
const
MOCK_USER
=
{
id
:
42
,
first_name
:
"
Testy
"
,
last_name
:
"
McTestFace
"
,
email
:
"
test@metabase.com
"
,
};
describe
(
"
EditUserModal
"
,
()
=>
{
beforeEach
(()
=>
mock
.
setup
());
afterEach
(()
=>
mock
.
teardown
());
it
(
"
should load the user
"
,
async
()
=>
{
mock
.
get
(
"
/api/user/42
"
,
(
req
,
res
)
=>
res
.
json
(
MOCK_USER
));
const
{
wrapper
,
store
}
=
mountWithStore
(
<
EditUserModal
params
=
{{
userId
:
42
}}
/>
,
);
await
store
.
waitForAction
(
"
metabase/requests/SET_REQUEST_STATE
"
);
expect
(
wrapper
.
find
(
"
input
"
).
map
(
i
=>
i
.
props
().
value
)).
toEqual
([
"
Testy
"
,
"
McTestFace
"
,
"
test@metabase.com
"
,
]);
expect
(
wrapper
.
find
(
"
.Icon-close
"
).
exists
()).
toBe
(
true
);
});
});
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