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
6d94b32a
Commit
6d94b32a
authored
Jan 10, 2020
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate issue_spec to Jest
parent
b9f0e202
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
40 deletions
+54
-40
spec/frontend/issue_spec.js
spec/frontend/issue_spec.js
+54
-40
No files found.
spec/
javascripts
/issue_spec.js
→
spec/
frontend
/issue_spec.js
View file @
6d94b32a
...
@@ -6,7 +6,13 @@ import axios from '~/lib/utils/axios_utils';
...
@@ -6,7 +6,13 @@ import axios from '~/lib/utils/axios_utils';
import
Issue
from
'
~/issue
'
;
import
Issue
from
'
~/issue
'
;
import
'
~/lib/utils/text_utility
'
;
import
'
~/lib/utils/text_utility
'
;
describe
(
'
Issue
'
,
function
()
{
describe
(
'
Issue
'
,
()
=>
{
let
testContext
;
beforeEach
(()
=>
{
testContext
=
{};
});
let
$boxClosed
,
$boxOpen
,
$btn
;
let
$boxClosed
,
$boxOpen
,
$btn
;
preloadFixtures
(
'
issues/closed-issue.html
'
);
preloadFixtures
(
'
issues/closed-issue.html
'
);
...
@@ -80,10 +86,18 @@ describe('Issue', function() {
...
@@ -80,10 +86,18 @@ describe('Issue', function() {
}
}
[
true
,
false
].
forEach
(
isIssueInitiallyOpen
=>
{
[
true
,
false
].
forEach
(
isIssueInitiallyOpen
=>
{
describe
(
`with
${
isIssueInitiallyOpen
?
'
open
'
:
'
closed
'
}
issue`
,
function
()
{
describe
(
`with
${
isIssueInitiallyOpen
?
'
open
'
:
'
closed
'
}
issue`
,
()
=>
{
const
action
=
isIssueInitiallyOpen
?
'
close
'
:
'
reopen
'
;
const
action
=
isIssueInitiallyOpen
?
'
close
'
:
'
reopen
'
;
let
mock
;
let
mock
;
function
setup
()
{
testContext
.
issue
=
new
Issue
();
expectIssueState
(
isIssueInitiallyOpen
);
testContext
.
$projectIssuesCounter
=
$
(
'
.issue_counter
'
).
first
();
testContext
.
$projectIssuesCounter
.
text
(
'
1,001
'
);
}
function
mockCloseButtonResponseSuccess
(
url
,
response
)
{
function
mockCloseButtonResponseSuccess
(
url
,
response
)
{
mock
.
onPut
(
url
).
reply
(()
=>
{
mock
.
onPut
(
url
).
reply
(()
=>
{
expectNewBranchButtonState
(
true
,
false
);
expectNewBranchButtonState
(
true
,
false
);
...
@@ -103,7 +117,7 @@ describe('Issue', function() {
...
@@ -103,7 +117,7 @@ describe('Issue', function() {
});
});
}
}
beforeEach
(
function
()
{
beforeEach
(
()
=>
{
if
(
isIssueInitiallyOpen
)
{
if
(
isIssueInitiallyOpen
)
{
loadFixtures
(
'
issues/open-issue.html
'
);
loadFixtures
(
'
issues/open-issue.html
'
);
}
else
{
}
else
{
...
@@ -111,19 +125,11 @@ describe('Issue', function() {
...
@@ -111,19 +125,11 @@ describe('Issue', function() {
}
}
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
(
/
(
.*
)\/
related_branches$/
).
reply
(
200
,
{});
mock
.
onGet
(
/
(
.*
)\/
related_branches$/
).
reply
(
200
,
{});
jest
.
spyOn
(
axios
,
'
get
'
);
findElements
(
isIssueInitiallyOpen
);
findElements
(
isIssueInitiallyOpen
);
this
.
issue
=
new
Issue
();
testContext
.
$triggeredButton
=
$btn
;
expectIssueState
(
isIssueInitiallyOpen
);
this
.
$triggeredButton
=
$btn
;
this
.
$projectIssuesCounter
=
$
(
'
.issue_counter
'
).
first
();
this
.
$projectIssuesCounter
.
text
(
'
1,001
'
);
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -131,82 +137,90 @@ describe('Issue', function() {
...
@@ -131,82 +137,90 @@ describe('Issue', function() {
$
(
'
div.flash-alert
'
).
remove
();
$
(
'
div.flash-alert
'
).
remove
();
});
});
it
(
`
${
action
}
s the issue`
,
function
(
done
)
{
it
(
`
${
action
}
s the issue`
,
done
=>
{
mockCloseButtonResponseSuccess
(
t
his
.
$triggeredButton
.
attr
(
'
href
'
),
{
mockCloseButtonResponseSuccess
(
t
estContext
.
$triggeredButton
.
attr
(
'
href
'
),
{
id
:
34
,
id
:
34
,
});
});
mockCanCreateBranch
(
!
isIssueInitiallyOpen
);
mockCanCreateBranch
(
!
isIssueInitiallyOpen
);
this
.
$triggeredButton
.
trigger
(
'
click
'
);
setup
();
testContext
.
$triggeredButton
.
trigger
(
'
click
'
);
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expectIssueState
(
!
isIssueInitiallyOpen
);
expectIssueState
(
!
isIssueInitiallyOpen
);
expect
(
this
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expect
(
testContext
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expect
(
this
.
$projectIssuesCounter
.
text
()).
toBe
(
isIssueInitiallyOpen
?
'
1,000
'
:
'
1,002
'
);
expect
(
testContext
.
$projectIssuesCounter
.
text
()).
toBe
(
isIssueInitiallyOpen
?
'
1,000
'
:
'
1,002
'
,
);
expectNewBranchButtonState
(
false
,
!
isIssueInitiallyOpen
);
expectNewBranchButtonState
(
false
,
!
isIssueInitiallyOpen
);
done
();
done
();
});
});
});
});
it
(
`fails to
${
action
}
the issue if saved:false`
,
function
(
done
)
{
it
(
`fails to
${
action
}
the issue if saved:false`
,
done
=>
{
mockCloseButtonResponseSuccess
(
t
his
.
$triggeredButton
.
attr
(
'
href
'
),
{
mockCloseButtonResponseSuccess
(
t
estContext
.
$triggeredButton
.
attr
(
'
href
'
),
{
saved
:
false
,
saved
:
false
,
});
});
mockCanCreateBranch
(
isIssueInitiallyOpen
);
mockCanCreateBranch
(
isIssueInitiallyOpen
);
this
.
$triggeredButton
.
trigger
(
'
click
'
);
setup
();
testContext
.
$triggeredButton
.
trigger
(
'
click
'
);
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expectIssueState
(
isIssueInitiallyOpen
);
expectIssueState
(
isIssueInitiallyOpen
);
expect
(
t
his
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expect
(
t
estContext
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expectErrorMessage
();
expectErrorMessage
();
expect
(
t
his
.
$projectIssuesCounter
.
text
()).
toBe
(
'
1,001
'
);
expect
(
t
estContext
.
$projectIssuesCounter
.
text
()).
toBe
(
'
1,001
'
);
expectNewBranchButtonState
(
false
,
isIssueInitiallyOpen
);
expectNewBranchButtonState
(
false
,
isIssueInitiallyOpen
);
done
();
done
();
});
});
});
});
it
(
`fails to
${
action
}
the issue if HTTP error occurs`
,
function
(
done
)
{
it
(
`fails to
${
action
}
the issue if HTTP error occurs`
,
done
=>
{
mockCloseButtonResponseError
(
t
his
.
$triggeredButton
.
attr
(
'
href
'
));
mockCloseButtonResponseError
(
t
estContext
.
$triggeredButton
.
attr
(
'
href
'
));
mockCanCreateBranch
(
isIssueInitiallyOpen
);
mockCanCreateBranch
(
isIssueInitiallyOpen
);
this
.
$triggeredButton
.
trigger
(
'
click
'
);
setup
();
testContext
.
$triggeredButton
.
trigger
(
'
click
'
);
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expectIssueState
(
isIssueInitiallyOpen
);
expectIssueState
(
isIssueInitiallyOpen
);
expect
(
t
his
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expect
(
t
estContext
.
$triggeredButton
.
get
(
0
).
getAttribute
(
'
disabled
'
)).
toBeNull
();
expectErrorMessage
();
expectErrorMessage
();
expect
(
t
his
.
$projectIssuesCounter
.
text
()).
toBe
(
'
1,001
'
);
expect
(
t
estContext
.
$projectIssuesCounter
.
text
()).
toBe
(
'
1,001
'
);
expectNewBranchButtonState
(
false
,
isIssueInitiallyOpen
);
expectNewBranchButtonState
(
false
,
isIssueInitiallyOpen
);
done
();
done
();
});
});
});
});
it
(
'
disables the new branch button if Ajax call fails
'
,
function
()
{
it
(
'
disables the new branch button if Ajax call fails
'
,
()
=>
{
mockCloseButtonResponseError
(
t
his
.
$triggeredButton
.
attr
(
'
href
'
));
mockCloseButtonResponseError
(
t
estContext
.
$triggeredButton
.
attr
(
'
href
'
));
mock
.
onGet
(
/
(
.*
)\/
can_create_branch$/
).
networkError
();
mock
.
onGet
(
/
(
.*
)\/
can_create_branch$/
).
networkError
();
this
.
$triggeredButton
.
trigger
(
'
click
'
);
setup
();
testContext
.
$triggeredButton
.
trigger
(
'
click
'
);
expectNewBranchButtonState
(
false
,
false
);
expectNewBranchButtonState
(
false
,
false
);
});
});
it
(
'
does not trigger Ajax call if new branch button is missing
'
,
function
(
done
)
{
it
(
'
does not trigger Ajax call if new branch button is missing
'
,
done
=>
{
mockCloseButtonResponseError
(
this
.
$triggeredButton
.
attr
(
'
href
'
));
mockCloseButtonResponseError
(
testContext
.
$triggeredButton
.
attr
(
'
href
'
));
Issue
.
$btnNewBranch
=
$
();
this
.
canCreateBranchDeferred
=
null
;
document
.
querySelector
(
'
#related-branches
'
).
remove
();
document
.
querySelector
(
'
.create-mr-dropdown-wrap
'
).
remove
();
this
.
$triggeredButton
.
trigger
(
'
click
'
);
setup
();
testContext
.
$triggeredButton
.
trigger
(
'
click
'
);
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
axios
.
get
).
not
.
toHaveBeenCalled
();
expect
(
axios
.
get
).
not
.
toHaveBeenCalled
();
done
();
done
();
...
...
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