BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0c2c8773
Unverified
Commit
0c2c8773
authored
Jan 29, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted integration_settings_form to axios
parent
5792faf4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
75 deletions
+101
-75
integration_settings_form.js
...ets/javascripts/integrations/integration_settings_form.js
+23
-25
integration_settings_form_spec.js
...avascripts/integrations/integration_settings_form_spec.js
+78
-50
No files found.
app/assets/javascripts/integrations/integration_settings_form.js
View file @
0c2c8773
import
Flash
from
'../flash'
;
import
axios
from
'../lib/utils/axios_utils'
;
import
flash
from
'../flash'
;
export
default
class
IntegrationSettingsForm
{
constructor
(
formSelector
)
{
...
...
@@ -95,29 +96,26 @@ export default class IntegrationSettingsForm {
*/
testSettings
(
formData
)
{
this
.
toggleSubmitBtnState
(
true
);
$
.
ajax
({
type
:
'PUT'
,
url
:
this
.
testEndPoint
,
data
:
formData
,
})
.
done
((
res
)
=>
{
if
(
res
.
error
)
{
new
Flash
(
`
${
res
.
message
}
${
res
.
service_response
}
`
,
'alert'
,
document
,
{
title
:
'Save anyway'
,
clickHandler
:
(
e
)
=>
{
e
.
preventDefault
();
this
.
$form
.
submit
();
},
});
}
else
{
this
.
$form
.
submit
();
}
})
.
fail
(()
=>
{
new
Flash
(
'Something went wrong on our end.'
);
})
.
always
(()
=>
{
this
.
toggleSubmitBtnState
(
false
);
});
return
axios
.
put
(
this
.
testEndPoint
,
formData
)
.
then
(({
data
})
=>
{
if
(
data
.
error
)
{
flash
(
`
${
data
.
message
}
${
data
.
service_response
}
`
,
'alert'
,
document
,
{
title
:
'Save anyway'
,
clickHandler
:
(
e
)
=>
{
e
.
preventDefault
();
this
.
$form
.
submit
();
},
});
}
else
{
this
.
$form
.
submit
();
}
this
.
toggleSubmitBtnState
(
false
);
})
.
catch
(()
=>
{
flash
(
'Something went wrong on our end.'
);
this
.
toggleSubmitBtnState
(
false
);
});
}
}
spec/javascripts/integrations/integration_settings_form_spec.js
View file @
0c2c8773
import
MockAdaptor
from
'axios-mock-adapter'
;
import
axios
from
'~/lib/utils/axios_utils'
;
import
IntegrationSettingsForm
from
'~/integrations/integration_settings_form'
;
describe
(
'IntegrationSettingsForm'
,
()
=>
{
...
...
@@ -109,91 +111,117 @@ describe('IntegrationSettingsForm', () => {
describe
(
'testSettings'
,
()
=>
{
let
integrationSettingsForm
;
let
formData
;
let
mock
;
beforeEach
(()
=>
{
mock
=
new
MockAdaptor
(
axios
);
spyOn
(
axios
,
'put'
).
and
.
callThrough
();
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'.js-integration-settings-form'
);
formData
=
integrationSettingsForm
.
$form
.
serialize
();
});
it
(
'should make an ajax request with provided `formData`'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
()
);
afterEach
(
()
=>
{
mock
.
restore
();
}
);
integrationSettingsForm
.
testSettings
(
formData
);
it
(
'should make an ajax request with provided `formData`'
,
(
done
)
=>
{
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
axios
.
put
).
toHaveBeenCalledWith
(
integrationSettingsForm
.
testEndPoint
,
formData
);
expect
(
$
.
ajax
).
toHaveBeenCalledWith
({
type
:
'PUT'
,
url
:
integrationSettingsForm
.
testEndPoint
,
data
:
formData
,
});
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'should show error Flash with `Save anyway` action if ajax request responds with error in test'
,
()
=>
{
it
(
'should show error Flash with `Save anyway` action if ajax request responds with error in test'
,
(
done
)
=>
{
const
errorMessage
=
'Test failed.'
;
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
true
,
message
:
errorMessage
,
service_response
:
'some error'
,
});
deferred
.
resolve
({
error
:
true
,
message
:
errorMessage
,
service_response
:
'some error'
});
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'
);
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
);
});
it
(
'should submit form if ajax request responds without any error in test'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should submit form if ajax request responds without any error in test'
,
(
done
)
=>
{
spyOn
(
integrationSettingsForm
.
$form
,
'submit'
);
integrationSettingsForm
.
testSettings
(
formData
);
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
false
,
});
spyOn
(
integrationSettingsForm
.
$form
,
'submit'
);
deferred
.
resolve
({
error
:
false
});
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'should submit form when clicked on `Save anyway` action of error Flash'
,
()
=>
{
const
errorMessage
=
'Test failed.'
;
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should submit form when clicked on `Save anyway` action of error Flash'
,
(
done
)
=>
{
spyOn
(
integrationSettingsForm
.
$form
,
'submit'
);
integrationSettingsForm
.
testSettings
(
formData
);
const
errorMessage
=
'Test failed.'
;
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
reply
(
200
,
{
error
:
true
,
message
:
errorMessage
,
});
deferred
.
resolve
({
error
:
true
,
message
:
errorMessage
});
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
const
$flashAction
=
$
(
'.flash-container .flash-action'
);
expect
(
$flashAction
).
toBeDefined
();
const
$flashAction
=
$
(
'.flash-container .flash-action'
);
expect
(
$flashAction
).
toBeDefined
();
$flashAction
.
get
(
0
).
click
();
})
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
spyOn
(
integrationSettingsForm
.
$form
,
'submit'
);
$flashAction
.
get
(
0
).
click
();
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
(
);
done
(
);
})
.
catch
(
done
.
fail
);
});
it
(
'should show error Flash if ajax request failed'
,
()
=>
{
it
(
'should show error Flash if ajax request failed'
,
(
done
)
=>
{
const
errorMessage
=
'Something went wrong on our end.'
;
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
networkError
(
);
deferred
.
reject
();
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
$
(
'.flash-container .flash-text'
).
text
().
trim
()).
toEqual
(
errorMessage
);
expect
(
$
(
'.flash-container .flash-text'
).
text
().
trim
()).
toEqual
(
errorMessage
);
done
();
})
.
catch
(
done
.
fail
);
});
it
(
'should always call `toggleSubmitBtnState` with `false` once request is completed'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
it
(
'should always call `toggleSubmitBtnState` with `false` once request is completed'
,
(
done
)
=>
{
mock
.
onPut
(
integrationSettingsForm
.
testEndPoint
).
networkError
();
spyOn
(
integrationSettingsForm
,
'toggleSubmitBtnState'
);
deferred
.
reject
();
expect
(
integrationSettingsForm
.
toggleSubmitBtnState
).
toHaveBeenCalledWith
(
false
);
integrationSettingsForm
.
testSettings
(
formData
)
.
then
(()
=>
{
expect
(
integrationSettingsForm
.
toggleSubmitBtnState
).
toHaveBeenCalledWith
(
false
);
done
();
})
.
catch
(
done
.
fail
);
});
});
});
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