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
12cb1a98
Commit
12cb1a98
authored
Feb 24, 2021
by
Greg Johnson
Committed by
Paul Slaughter
Feb 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve issue specs
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52135
parent
310c30ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
64 deletions
+74
-64
app/assets/javascripts/issue.js
app/assets/javascripts/issue.js
+9
-2
spec/frontend/issue_spec.js
spec/frontend/issue_spec.js
+65
-62
No files found.
app/assets/javascripts/issue.js
View file @
12cb1a98
...
@@ -6,6 +6,9 @@ import axios from './lib/utils/axios_utils';
...
@@ -6,6 +6,9 @@ import axios from './lib/utils/axios_utils';
import
{
addDelimiter
}
from
'
./lib/utils/text_utility
'
;
import
{
addDelimiter
}
from
'
./lib/utils/text_utility
'
;
import
{
__
}
from
'
./locale
'
;
import
{
__
}
from
'
./locale
'
;
// TODO: Update all references of "issuable_vue_app:change" https://gitlab.com/gitlab-org/gitlab/-/issues/322760
export
const
EVENT_ISSUABLE_VUE_APP_CHANGE
=
'
issuable_vue_app:change
'
;
export
default
class
Issue
{
export
default
class
Issue
{
constructor
()
{
constructor
()
{
if
(
$
(
'
.js-alert-moved-from-service-desk-warning
'
).
length
)
{
if
(
$
(
'
.js-alert-moved-from-service-desk-warning
'
).
length
)
{
...
@@ -23,9 +26,13 @@ export default class Issue {
...
@@ -23,9 +26,13 @@ export default class Issue {
}
}
// Listen to state changes in the Vue app
// Listen to state changes in the Vue app
document
.
addEventListener
(
'
issuable_vue_app:change
'
,
(
event
)
=>
{
this
.
issuableVueAppChangeHandler
=
(
event
)
=>
this
.
updateTopState
(
event
.
detail
.
isClosed
,
event
.
detail
.
data
);
this
.
updateTopState
(
event
.
detail
.
isClosed
,
event
.
detail
.
data
);
});
document
.
addEventListener
(
EVENT_ISSUABLE_VUE_APP_CHANGE
,
this
.
issuableVueAppChangeHandler
);
}
dispose
()
{
document
.
removeEventListener
(
EVENT_ISSUABLE_VUE_APP_CHANGE
,
this
.
issuableVueAppChangeHandler
);
}
}
/**
/**
...
...
spec/frontend/issue_spec.js
View file @
12cb1a98
import
{
getByText
}
from
'
@testing-library/dom
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
$
from
'
jquery
'
;
import
Issue
,
{
EVENT_ISSUABLE_VUE_APP_CHANGE
}
from
'
~/issue
'
;
import
Issue
from
'
~/issue
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
'
~/lib/utils/text_utility
'
;
describe
(
'
Issue
'
,
()
=>
{
describe
(
'
Issue
'
,
()
=>
{
let
$boxClosed
;
let
$boxOpen
;
let
testContext
;
let
testContext
;
let
mock
;
beforeEach
(()
=>
{
beforeAll
(()
=>
{
testContext
=
{};
});
preloadFixtures
(
'
issues/closed-issue.html
'
);
preloadFixtures
(
'
issues/closed-issue.html
'
);
preloadFixtures
(
'
issues/open-issue.html
'
);
preloadFixtures
(
'
issues/open-issue.html
'
);
});
function
expectVisibility
(
$element
,
shouldBeVisible
)
{
beforeEach
(()
=>
{
if
(
shouldBeVisible
)
{
mock
=
new
MockAdapter
(
axios
);
expect
(
$element
).
not
.
toHaveClass
(
'
hidden
'
);
mock
.
onGet
(
/
(
.*
)\/
related_branches$/
).
reply
(
200
,
{});
}
else
{
expect
(
$element
).
toHaveClass
(
'
hidden
'
);
}
}
function
expectIssueState
(
isIssueOpen
)
{
expectVisibility
(
$boxClosed
,
!
isIssueOpen
);
expectVisibility
(
$boxOpen
,
isIssueOpen
);
}
function
findElements
()
{
$boxClosed
=
$
(
'
div.status-box-issue-closed
'
);
expect
(
$boxClosed
).
toExist
();
expect
(
$boxClosed
).
toHaveText
(
'
Closed
'
);
$boxOpen
=
$
(
'
div.status-box-open
'
);
expect
(
$boxOpen
).
toExist
();
expect
(
$boxOpen
).
toHaveText
(
'
Open
'
);
}
[
true
,
false
].
forEach
((
isIssueInitiallyOpen
)
=>
{
describe
(
`with
${
isIssueInitiallyOpen
?
'
open
'
:
'
closed
'
}
issue`
,
()
=>
{
const
action
=
isIssueInitiallyOpen
?
'
close
'
:
'
reopen
'
;
let
mock
;
function
setup
()
{
testContext
=
{};
testContext
.
issue
=
new
Issue
();
testContext
.
issue
=
new
Issue
();
expectIssueState
(
isIssueInitiallyOpen
);
}
);
testContext
.
$projectIssuesCounter
=
$
(
'
.issue_counter
'
).
first
();
afterEach
(()
=>
{
testContext
.
$projectIssuesCounter
.
text
(
'
1,001
'
);
mock
.
restore
();
}
testContext
.
issue
.
dispose
();
});
const
getIssueCounter
=
()
=>
document
.
querySelector
(
'
.issue_counter
'
);
const
getOpenStatusBox
=
()
=>
getByText
(
document
,
(
_
,
el
)
=>
el
.
textContent
.
match
(
/Open/
),
{
selector
:
'
.status-box-open
'
,
});
const
getClosedStatusBox
=
()
=>
getByText
(
document
,
(
_
,
el
)
=>
el
.
textContent
.
match
(
/Closed/
),
{
selector
:
'
.status-box-issue-closed
'
,
});
describe
.
each
`
desc | isIssueInitiallyOpen | expectedCounterText
${
'
with an initially open issue
'
}
|
${
true
}
|
${
'
1,000
'
}
${
'
with an initially closed issue
'
}
|
${
false
}
|
${
'
1,002
'
}
`
(
'
$desc
'
,
({
isIssueInitiallyOpen
,
expectedCounterText
})
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
if
(
isIssueInitiallyOpen
)
{
if
(
isIssueInitiallyOpen
)
{
loadFixtures
(
'
issues/open-issue.html
'
);
loadFixtures
(
'
issues/open-issue.html
'
);
...
@@ -61,31 +47,48 @@ describe('Issue', () => {
...
@@ -61,31 +47,48 @@ describe('Issue', () => {
loadFixtures
(
'
issues/closed-issue.html
'
);
loadFixtures
(
'
issues/closed-issue.html
'
);
}
}
mock
=
new
MockAdapter
(
axios
);
testContext
.
issueCounter
=
getIssueCounter
(
);
mock
.
onGet
(
/
(
.*
)\/
related_branches$/
).
reply
(
200
,
{}
);
testContext
.
statusBoxClosed
=
getClosedStatusBox
(
);
jest
.
spyOn
(
axios
,
'
get
'
);
testContext
.
statusBoxOpen
=
getOpenStatusBox
(
);
findElements
(
isIssueInitiallyOpen
)
;
testContext
.
issueCounter
.
textContent
=
'
1,001
'
;
});
});
afterEach
(()
=>
{
it
(
`has the proper visible status box when
${
isIssueInitiallyOpen
?
'
open
'
:
'
closed
'
}
`
,
()
=>
{
mock
.
restore
();
if
(
isIssueInitiallyOpen
)
{
$
(
'
div.flash-alert
'
).
remove
();
expect
(
testContext
.
statusBoxClosed
).
toHaveClass
(
'
hidden
'
);
expect
(
testContext
.
statusBoxOpen
).
not
.
toHaveClass
(
'
hidden
'
);
}
else
{
expect
(
testContext
.
statusBoxClosed
).
not
.
toHaveClass
(
'
hidden
'
);
expect
(
testContext
.
statusBoxOpen
).
toHaveClass
(
'
hidden
'
);
}
});
});
it
(
`
${
action
}
s the issue on dispatch of issuable_vue_app:change event`
,
()
=>
{
describe
(
'
when vue app triggers change
'
,
()
=>
{
setup
();
beforeEach
(()
=>
{
document
.
dispatchEvent
(
document
.
dispatchEvent
(
new
CustomEvent
(
'
issuable_vue_app:change
'
,
{
new
CustomEvent
(
EVENT_ISSUABLE_VUE_APP_CHANGE
,
{
detail
:
{
detail
:
{
data
:
{
id
:
1
},
data
:
{
id
:
1
},
isClosed
:
isIssueInitiallyOpen
,
isClosed
:
isIssueInitiallyOpen
,
},
},
}),
}),
);
);
});
it
(
'
displays correct status box
'
,
()
=>
{
if
(
isIssueInitiallyOpen
)
{
expect
(
testContext
.
statusBoxClosed
).
not
.
toHaveClass
(
'
hidden
'
);
expect
(
testContext
.
statusBoxOpen
).
toHaveClass
(
'
hidden
'
);
}
else
{
expect
(
testContext
.
statusBoxClosed
).
toHaveClass
(
'
hidden
'
);
expect
(
testContext
.
statusBoxOpen
).
not
.
toHaveClass
(
'
hidden
'
);
}
});
expectIssueState
(
!
isIssueInitiallyOpen
);
it
(
'
updates issueCounter text
'
,
()
=>
{
expect
(
testContext
.
issueCounter
).
toBeVisible
();
expect
(
testContext
.
issueCounter
).
toHaveText
(
expectedCounterText
);
});
});
});
});
});
});
...
...
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