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
454d525f
Commit
454d525f
authored
Apr 29, 2020
by
Nicolò Maria Mezzopera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate integration_setting_form_spec to jest
parent
52661728
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
99 deletions
+66
-99
spec/frontend/integrations/integration_settings_form_spec.js
spec/frontend/integrations/integration_settings_form_spec.js
+66
-99
No files found.
spec/
javascripts
/integrations/integration_settings_form_spec.js
→
spec/
frontend
/integrations/integration_settings_form_spec.js
View file @
454d525f
...
...
@@ -16,7 +16,7 @@ describe('IntegrationSettingsForm', () => {
beforeEach
(()
=>
{
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
spyOn
(
integrationSettingsForm
,
'
init
'
);
jest
.
spyOn
(
integrationSettingsForm
,
'
init
'
).
mockImplementation
(()
=>
{}
);
});
it
(
'
should initialize form element refs on class object
'
,
()
=>
{
...
...
@@ -130,7 +130,7 @@ describe('IntegrationSettingsForm', () => {
beforeEach
(()
=>
{
mock
=
new
MockAdaptor
(
axios
);
spyOn
(
axios
,
'
put
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
axios
,
'
put
'
);
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
// eslint-disable-next-line no-jquery/no-serialize
...
...
@@ -141,18 +141,13 @@ describe('IntegrationSettingsForm', () => {
mock
.
restore
();
});
it
(
'
should make an ajax request with provided `formData`
'
,
done
=>
{
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
axios
.
put
).
toHaveBeenCalledWith
(
integrationSettingsForm
.
testEndPoint
,
formData
);
done
();
})
.
catch
(
done
.
fail
);
it
(
'
should make an ajax request with provided `formData`
'
,
()
=>
{
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
expect
(
axios
.
put
).
toHaveBeenCalledWith
(
integrationSettingsForm
.
testEndPoint
,
formData
);
});
});
it
(
'
should show error Flash with `Save anyway` action if ajax request responds with error in test
'
,
done
=>
{
it
(
'
should show error Flash with `Save anyway` action if ajax request responds with error in test
'
,
()
=>
{
const
errorMessage
=
'
Test failed.
'
;
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
true
,
...
...
@@ -161,32 +156,27 @@ describe('IntegrationSettingsForm', () => {
test_failed
:
true
,
});
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
const
$flashContainer
=
$
(
'
.flash-container
'
);
expect
(
$flashContainer
.
find
(
'
.flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Test failed. some error
'
);
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)).
toBeDefined
();
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Save anyway
'
);
done
();
})
.
catch
(
done
.
fail
);
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
const
$flashContainer
=
$
(
'
.flash-container
'
);
expect
(
$flashContainer
.
find
(
'
.flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Test failed. some error
'
);
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)).
toBeDefined
();
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Save anyway
'
);
});
});
it
(
'
should not show error Flash with `Save anyway` action if ajax request responds with error in validation
'
,
done
=>
{
it
(
'
should not show error Flash with `Save anyway` action if ajax request responds with error in validation
'
,
()
=>
{
const
errorMessage
=
'
Validations failed.
'
;
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
true
,
...
...
@@ -195,50 +185,40 @@ describe('IntegrationSettingsForm', () => {
test_failed
:
false
,
});
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
const
$flashContainer
=
$
(
'
.flash-container
'
);
expect
(
$flashContainer
.
find
(
'
.flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Validations failed. some error
'
);
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)).
toBeDefined
();
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)
.
text
()
.
trim
(),
).
toEqual
(
''
);
done
();
})
.
catch
(
done
.
fail
);
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
const
$flashContainer
=
$
(
'
.flash-container
'
);
expect
(
$flashContainer
.
find
(
'
.flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
'
Validations failed. some error
'
);
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)).
toBeDefined
();
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)
.
text
()
.
trim
(),
).
toEqual
(
''
);
});
});
it
(
'
should submit form if ajax request responds without any error in test
'
,
done
=>
{
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
);
it
(
'
should submit form if ajax request responds without any error in test
'
,
()
=>
{
jest
.
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
).
mockImplementation
(()
=>
{}
);
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
false
,
});
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
done
();
})
.
catch
(
done
.
fail
);
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
});
});
it
(
'
should submit form when clicked on `Save anyway` action of error Flash
'
,
done
=>
{
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
);
it
(
'
should submit form when clicked on `Save anyway` action of error Flash
'
,
()
=>
{
jest
.
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
).
mockImplementation
(()
=>
{}
);
const
errorMessage
=
'
Test failed.
'
;
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
...
...
@@ -247,7 +227,7 @@ describe('IntegrationSettingsForm', () => {
test_failed
:
true
,
});
integrationSettingsForm
return
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
const
$flashAction
=
$
(
'
.flash-container .flash-action
'
);
...
...
@@ -258,44 +238,31 @@ describe('IntegrationSettingsForm', () => {
})
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
done
();
})
.
catch
(
done
.
fail
);
});
});
it
(
'
should show error Flash if ajax request failed
'
,
done
=>
{
it
(
'
should show error Flash if ajax request failed
'
,
()
=>
{
const
errorMessage
=
'
Something went wrong on our end.
'
;
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
networkError
();
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
$
(
'
.flash-container .flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
errorMessage
);
done
();
})
.
catch
(
done
.
fail
);
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
expect
(
$
(
'
.flash-container .flash-text
'
)
.
text
()
.
trim
(),
).
toEqual
(
errorMessage
);
});
});
it
(
'
should always call `toggleSubmitBtnState` with `false` once request is completed
'
,
done
=>
{
it
(
'
should always call `toggleSubmitBtnState` with `false` once request is completed
'
,
()
=>
{
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
networkError
();
spyOn
(
integrationSettingsForm
,
'
toggleSubmitBtnState
'
);
jest
.
spyOn
(
integrationSettingsForm
,
'
toggleSubmitBtnState
'
).
mockImplementation
(()
=>
{}
);
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
toggleSubmitBtnState
).
toHaveBeenCalledWith
(
false
);
done
();
})
.
catch
(
done
.
fail
);
return
integrationSettingsForm
.
testSettings
(
formData
).
then
(()
=>
{
expect
(
integrationSettingsForm
.
toggleSubmitBtnState
).
toHaveBeenCalledWith
(
false
);
});
});
});
});
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