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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
a678f42e
Commit
a678f42e
authored
May 30, 2017
by
kushalpandya
Committed by
Jarka Kadlecova
Jun 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for `integration_settings_form`
parent
f57a4a94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
229 additions
and
0 deletions
+229
-0
spec/javascripts/fixtures/services.rb
spec/javascripts/fixtures/services.rb
+32
-0
spec/javascripts/integrations/integration_settings_form_spec.js
...avascripts/integrations/integration_settings_form_spec.js
+197
-0
No files found.
spec/javascripts/fixtures/services.rb
0 → 100644
View file @
a678f42e
require
'spec_helper'
describe
Projects
::
ServicesController
,
'(JavaScript fixtures)'
,
type: :controller
do
include
JavaScriptFixturesHelpers
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:project
)
{
create
(
:project_empty_repo
,
namespace:
namespace
,
path:
'services-project'
)
}
let!
(
:service
)
{
create
(
:custom_issue_tracker_service
,
project:
project
,
title:
'Custom Issue Tracker'
)
}
render_views
before
(
:all
)
do
clean_frontend_fixtures
(
'services/'
)
end
before
(
:each
)
do
sign_in
(
admin
)
end
it
'services/edit_service.html.raw'
do
|
example
|
get
:edit
,
namespace_id:
namespace
,
project_id:
project
,
id:
service
.
to_param
expect
(
response
).
to
be_success
store_frontend_fixture
(
response
,
example
.
description
)
end
end
spec/javascripts/integrations/integration_settings_form_spec.js
0 → 100644
View file @
a678f42e
import
IntegrationSettingsForm
from
'
~/integrations/integration_settings_form
'
;
describe
(
'
IntegrationSettingsForm
'
,
()
=>
{
const
FIXTURE
=
'
services/edit_service.html.raw
'
;
preloadFixtures
(
FIXTURE
);
beforeEach
(()
=>
{
loadFixtures
(
FIXTURE
);
});
describe
(
'
contructor
'
,
()
=>
{
let
integrationSettingsForm
;
beforeEach
(()
=>
{
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
spyOn
(
integrationSettingsForm
,
'
init
'
);
});
it
(
'
should initialize form element refs on class object
'
,
()
=>
{
// Form Reference
expect
(
integrationSettingsForm
.
$form
).
toBeDefined
();
expect
(
integrationSettingsForm
.
$form
.
prop
(
'
nodeName
'
)).
toEqual
(
'
FORM
'
);
// Form Child Elements
expect
(
integrationSettingsForm
.
$serviceToggle
).
toBeDefined
();
expect
(
integrationSettingsForm
.
$submitBtn
).
toBeDefined
();
expect
(
integrationSettingsForm
.
$submitBtnLoader
).
toBeDefined
();
expect
(
integrationSettingsForm
.
$submitBtnLabel
).
toBeDefined
();
});
it
(
'
should initialize form metadata on class object
'
,
()
=>
{
expect
(
integrationSettingsForm
.
endPoint
).
toBeDefined
();
expect
(
integrationSettingsForm
.
canTestService
).
toBeDefined
();
});
});
describe
(
'
toggleServiceState
'
,
()
=>
{
let
integrationSettingsForm
;
beforeEach
(()
=>
{
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
});
it
(
'
should remove `novalidate` attribute to form when called with `true`
'
,
()
=>
{
integrationSettingsForm
.
toggleServiceState
(
true
);
expect
(
integrationSettingsForm
.
$form
.
attr
(
'
novalidate
'
)).
not
.
toBeDefined
();
});
it
(
'
should set `novalidate` attribute to form when called with `false`
'
,
()
=>
{
integrationSettingsForm
.
toggleServiceState
(
false
);
expect
(
integrationSettingsForm
.
$form
.
attr
(
'
novalidate
'
)).
toBeDefined
();
});
});
describe
(
'
toggleSubmitBtnLabel
'
,
()
=>
{
let
integrationSettingsForm
;
beforeEach
(()
=>
{
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
});
it
(
'
should set Save button label to "Test settings and save changes" when serviceActive & canTestService are `true`
'
,
()
=>
{
integrationSettingsForm
.
toggleSubmitBtnLabel
(
true
,
true
);
expect
(
integrationSettingsForm
.
$submitBtnLabel
.
text
()).
toEqual
(
'
Test settings and save changes
'
);
});
it
(
'
should set Save button label to "Save changes" when either serviceActive or canTestService (or both) is `false`
'
,
()
=>
{
integrationSettingsForm
.
toggleSubmitBtnLabel
(
false
,
false
);
expect
(
integrationSettingsForm
.
$submitBtnLabel
.
text
()).
toEqual
(
'
Save changes
'
);
integrationSettingsForm
.
toggleSubmitBtnLabel
(
false
,
true
);
expect
(
integrationSettingsForm
.
$submitBtnLabel
.
text
()).
toEqual
(
'
Save changes
'
);
integrationSettingsForm
.
toggleSubmitBtnLabel
(
true
,
false
);
expect
(
integrationSettingsForm
.
$submitBtnLabel
.
text
()).
toEqual
(
'
Save changes
'
);
});
});
describe
(
'
toggleSubmitBtnState
'
,
()
=>
{
let
integrationSettingsForm
;
beforeEach
(()
=>
{
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'
.js-integration-settings-form
'
);
});
it
(
'
should disable Save button and show loader animation when called with `true`
'
,
()
=>
{
integrationSettingsForm
.
toggleSubmitBtnState
(
true
);
expect
(
integrationSettingsForm
.
$submitBtn
.
is
(
'
:disabled
'
)).
toBeTruthy
();
expect
(
integrationSettingsForm
.
$submitBtnLoader
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
});
it
(
'
should enable Save button and hide loader animation when called with `false`
'
,
()
=>
{
integrationSettingsForm
.
toggleSubmitBtnState
(
false
);
expect
(
integrationSettingsForm
.
$submitBtn
.
is
(
'
:disabled
'
)).
toBeFalsy
();
expect
(
integrationSettingsForm
.
$submitBtnLoader
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
});
});
describe
(
'
testSettings
'
,
()
=>
{
let
integrationSettingsForm
;
let
formData
;
beforeEach
(()
=>
{
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
());
integrationSettingsForm
.
testSettings
(
formData
);
expect
(
$
.
ajax
).
toHaveBeenCalledWith
({
type
:
'
PUT
'
,
url
:
`
${
integrationSettingsForm
.
endPoint
}
/test`
,
data
:
formData
,
});
});
it
(
'
should show error Flash with `Save anyway` action if ajax request responds with error in test
'
,
()
=>
{
const
errorMessage
=
'
Test failed.
'
;
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
deferred
.
resolve
({
error
:
true
,
message
:
errorMessage
});
const
$flashContainer
=
$
(
'
.flash-container
'
);
expect
(
$flashContainer
.
find
(
'
.flash-text
'
).
text
()).
toEqual
(
errorMessage
);
expect
(
$flashContainer
.
find
(
'
.flash-action
'
)).
toBeDefined
();
expect
(
$flashContainer
.
find
(
'
.flash-action
'
).
text
()).
toEqual
(
'
Save anyway
'
);
});
it
(
'
should submit form if ajax request responds without any error in test
'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
);
deferred
.
resolve
({
error
:
false
});
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
});
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
());
integrationSettingsForm
.
testSettings
(
formData
);
deferred
.
resolve
({
error
:
true
,
message
:
errorMessage
});
const
$flashAction
=
$
(
'
.flash-container .flash-action
'
);
expect
(
$flashAction
).
toBeDefined
();
spyOn
(
integrationSettingsForm
.
$form
,
'
submit
'
);
$flashAction
.
trigger
(
'
click
'
);
expect
(
integrationSettingsForm
.
$form
.
submit
).
toHaveBeenCalled
();
});
it
(
'
should show error Flash if ajax request failed
'
,
()
=>
{
const
errorMessage
=
'
Something went wrong on our end.
'
;
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
deferred
.
reject
();
expect
(
$
(
'
.flash-container .flash-text
'
).
text
()).
toEqual
(
errorMessage
);
});
it
(
'
should always call `toggleSubmitBtnState` with `false` once request is completed
'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
integrationSettingsForm
.
testSettings
(
formData
);
spyOn
(
integrationSettingsForm
,
'
toggleSubmitBtnState
'
);
deferred
.
reject
();
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