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
8d50d4d1
Commit
8d50d4d1
authored
Jan 10, 2022
by
Kev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update spec with changes from component
parent
d697981c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
45 deletions
+87
-45
spec/frontend/vue_mr_widget/components/mr_widget_rebase_spec.js
...rontend/vue_mr_widget/components/mr_widget_rebase_spec.js
+87
-45
No files found.
spec/frontend/vue_mr_widget/components/mr_widget_rebase_spec.js
View file @
8d50d4d1
...
@@ -2,10 +2,15 @@ import { shallowMount } from '@vue/test-utils';
...
@@ -2,10 +2,15 @@ import { shallowMount } from '@vue/test-utils';
import
{
nextTick
}
from
'
vue
'
;
import
{
nextTick
}
from
'
vue
'
;
import
WidgetRebase
from
'
~/vue_merge_request_widget/components/states/mr_widget_rebase.vue
'
;
import
WidgetRebase
from
'
~/vue_merge_request_widget/components/states/mr_widget_rebase.vue
'
;
import
eventHub
from
'
~/vue_merge_request_widget/event_hub
'
;
import
eventHub
from
'
~/vue_merge_request_widget/event_hub
'
;
import
ActionsButton
from
'
~/vue_shared/components/actions_button.vue
'
;
import
{
REBASE_BUTTON_KEY
,
REBASE_WITHOUT_CI_BUTTON_KEY
,
}
from
'
~/vue_merge_request_widget/constants
'
;
let
wrapper
;
let
wrapper
;
function
factory
(
propsData
,
mergeRequestWidgetGraphql
)
{
function
createWrapper
(
propsData
,
mergeRequestWidgetGraphql
)
{
wrapper
=
shallowMount
(
WidgetRebase
,
{
wrapper
=
shallowMount
(
WidgetRebase
,
{
propsData
,
propsData
,
data
()
{
data
()
{
...
@@ -31,8 +36,9 @@ function factory(propsData, mergeRequestWidgetGraphql) {
...
@@ -31,8 +36,9 @@ function factory(propsData, mergeRequestWidgetGraphql) {
}
}
describe
(
'
Merge request widget rebase component
'
,
()
=>
{
describe
(
'
Merge request widget rebase component
'
,
()
=>
{
const
findRebaseMessageEl
=
()
=>
wrapper
.
find
(
'
[data-testid="rebase-message"]
'
);
const
findRebaseMessage
=
()
=>
wrapper
.
find
(
'
[data-testid="rebase-message"]
'
);
const
findRebaseMessageElText
=
()
=>
findRebaseMessageEl
().
text
();
const
findRebaseMessageText
=
()
=>
findRebaseMessage
().
text
();
const
findRebaseButton
=
()
=>
wrapper
.
find
(
ActionsButton
);
afterEach
(()
=>
{
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
.
destroy
();
...
@@ -41,9 +47,9 @@ describe('Merge request widget rebase component', () => {
...
@@ -41,9 +47,9 @@ describe('Merge request widget rebase component', () => {
[
true
,
false
].
forEach
((
mergeRequestWidgetGraphql
)
=>
{
[
true
,
false
].
forEach
((
mergeRequestWidgetGraphql
)
=>
{
describe
(
`widget graphql is
${
mergeRequestWidgetGraphql
?
'
enabled
'
:
'
disabled
'
}
`
,
()
=>
{
describe
(
`widget graphql is
${
mergeRequestWidgetGraphql
?
'
enabled
'
:
'
disabled
'
}
`
,
()
=>
{
describe
(
'
W
hile rebasing
'
,
()
=>
{
describe
(
'
w
hile rebasing
'
,
()
=>
{
it
(
'
should show progress message
'
,
()
=>
{
it
(
'
should show progress message
'
,
()
=>
{
factory
(
createWrapper
(
{
{
mr
:
{
rebaseInProgress
:
true
},
mr
:
{
rebaseInProgress
:
true
},
service
:
{},
service
:
{},
...
@@ -51,24 +57,32 @@ describe('Merge request widget rebase component', () => {
...
@@ -51,24 +57,32 @@ describe('Merge request widget rebase component', () => {
mergeRequestWidgetGraphql
,
mergeRequestWidgetGraphql
,
);
);
expect
(
findRebaseMessage
El
Text
()).
toContain
(
'
Rebase in progress
'
);
expect
(
findRebaseMessageText
()).
toContain
(
'
Rebase in progress
'
);
});
});
});
});
describe
(
'
With permissions
'
,
()
=>
{
describe
(
'
with permissions
'
,
()
=>
{
it
(
'
it should render rebase button and warning message
'
,
()
=>
{
const
rebaseMock
=
jest
.
fn
().
mockResolvedValue
();
factory
(
const
pollMock
=
jest
.
fn
().
mockResolvedValue
({});
beforeEach
(()
=>
{
createWrapper
(
{
{
mr
:
{
mr
:
{
rebaseInProgress
:
false
,
rebaseInProgress
:
false
,
canPushToSourceBranch
:
true
,
canPushToSourceBranch
:
true
,
},
},
service
:
{},
service
:
{
rebase
:
rebaseMock
,
poll
:
pollMock
,
},
},
},
mergeRequestWidgetGraphql
,
mergeRequestWidgetGraphql
,
);
);
});
const
text
=
findRebaseMessageElText
();
it
(
'
renders the warning message
'
,
()
=>
{
const
text
=
findRebaseMessageText
();
expect
(
text
).
toContain
(
'
Merge blocked
'
);
expect
(
text
).
toContain
(
'
Merge blocked
'
);
expect
(
text
.
replace
(
/
\s\s
+/g
,
'
'
)).
toContain
(
expect
(
text
.
replace
(
/
\s\s
+/g
,
'
'
)).
toContain
(
...
@@ -76,42 +90,79 @@ describe('Merge request widget rebase component', () => {
...
@@ -76,42 +90,79 @@ describe('Merge request widget rebase component', () => {
);
);
});
});
it
(
'
it should render error message when it fails
'
,
async
()
=>
{
it
(
'
renders an error message when rebasing has failed
'
,
async
()
=>
{
factory
(
{
mr
:
{
rebaseInProgress
:
false
,
canPushToSourceBranch
:
true
,
},
service
:
{},
},
mergeRequestWidgetGraphql
,
);
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
// eslint-disable-next-line no-restricted-syntax
wrapper
.
setData
({
rebasingError
:
'
Something went wrong!
'
});
wrapper
.
setData
({
rebasingError
:
'
Something went wrong!
'
});
await
nextTick
();
await
nextTick
();
expect
(
findRebaseMessageElText
()).
toContain
(
'
Something went wrong!
'
);
expect
(
findRebaseMessageText
()).
toContain
(
'
Something went wrong!
'
);
});
describe
(
'
"Rebase" button
'
,
()
=>
{
it
(
'
is rendered
'
,
()
=>
{
expect
(
findRebaseButton
().
exists
()).
toBe
(
true
);
});
it
(
'
has rebase and rebase without CI actions
'
,
()
=>
{
const
actionNames
=
findRebaseButton
()
.
props
(
'
actions
'
)
.
map
((
action
)
=>
action
.
key
);
expect
(
actionNames
).
toStrictEqual
([
REBASE_BUTTON_KEY
,
REBASE_WITHOUT_CI_BUTTON_KEY
]);
});
});
it
(
'
defaults to rebase action
'
,
()
=>
{
expect
(
findRebaseButton
().
props
(
'
selectedKey
'
)).
toStrictEqual
(
REBASE_BUTTON_KEY
);
});
});
describe
(
'
Without permissions
'
,
()
=>
{
it
(
'
starts the rebase when clicking
'
,
async
()
=>
{
it
(
'
should render a message explaining user does not have permissions
'
,
()
=>
{
// ActionButtons use the actions props instead of emitting
factory
(
// a click event, therefore simulating the behavior here:
findRebaseButton
()
.
props
(
'
actions
'
)
.
find
((
x
)
=>
x
.
key
===
REBASE_BUTTON_KEY
)
.
handle
();
await
nextTick
();
expect
(
rebaseMock
).
toHaveBeenCalledWith
({
skipCi
:
false
});
});
it
(
'
starts the CI-skipping rebase when clicking on "Rebase without CI"
'
,
async
()
=>
{
// ActionButtons use the actions props instead of emitting
// a click event, therefore simulating the behavior here:
findRebaseButton
()
.
props
(
'
actions
'
)
.
find
((
x
)
=>
x
.
key
===
REBASE_WITHOUT_CI_BUTTON_KEY
)
.
handle
();
await
nextTick
();
expect
(
rebaseMock
).
toHaveBeenCalledWith
({
skipCi
:
true
});
});
});
});
describe
(
'
without permissions
'
,
()
=>
{
const
exampleTargetBranch
=
'
fake-branch-to-test-with
'
;
beforeEach
(()
=>
{
createWrapper
(
{
{
mr
:
{
mr
:
{
rebaseInProgress
:
false
,
rebaseInProgress
:
false
,
canPushToSourceBranch
:
false
,
canPushToSourceBranch
:
false
,
targetBranch
:
'
foo
'
,
targetBranch
:
exampleTargetBranch
,
},
},
service
:
{},
service
:
{},
},
},
mergeRequestWidgetGraphql
,
mergeRequestWidgetGraphql
,
);
);
});
const
text
=
findRebaseMessageElText
();
it
(
'
renders a message explaining user does not have permissions
'
,
()
=>
{
const
text
=
findRebaseMessageText
();
expect
(
text
).
toContain
(
expect
(
text
).
toContain
(
'
Merge blocked: the source branch must be rebased onto the target branch.
'
,
'
Merge blocked: the source branch must be rebased onto the target branch.
'
,
...
@@ -119,32 +170,23 @@ describe('Merge request widget rebase component', () => {
...
@@ -119,32 +170,23 @@ describe('Merge request widget rebase component', () => {
expect
(
text
).
toContain
(
'
the source branch must be rebased
'
);
expect
(
text
).
toContain
(
'
the source branch must be rebased
'
);
});
});
it
(
'
should render the correct target branch name
'
,
()
=>
{
it
(
'
renders the correct target branch name
'
,
()
=>
{
const
targetBranch
=
'
fake-branch-to-test-with
'
;
const
elem
=
findRebaseMessage
();
factory
(
{
mr
:
{
rebaseInProgress
:
false
,
canPushToSourceBranch
:
false
,
targetBranch
,
},
service
:
{},
},
mergeRequestWidgetGraphql
,
);
const
elem
=
findRebaseMessageEl
();
expect
(
elem
.
text
()).
toContain
(
expect
(
elem
.
text
()).
toContain
(
`Merge blocked: the source branch must be rebased onto the target branch.`
,
`Merge blocked: the source branch must be rebased onto the target branch.`
,
);
);
});
});
it
(
'
does not render the "Rebase" button
'
,
()
=>
{
expect
(
findRebaseButton
().
exists
()).
toBe
(
false
);
});
});
});
describe
(
'
methods
'
,
()
=>
{
describe
(
'
methods
'
,
()
=>
{
it
(
'
checkRebaseStatus
'
,
async
()
=>
{
it
(
'
checkRebaseStatus
'
,
async
()
=>
{
jest
.
spyOn
(
eventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
eventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{});
factory
(
createWrapper
(
{
{
mr
:
{},
mr
:
{},
service
:
{
service
:
{
...
...
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