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
b1beb2e5
Commit
b1beb2e5
authored
Mar 12, 2021
by
Vitaly Slobodin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate mr_widget_failed_to_merge to VTU
parent
56a6b2b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
84 deletions
+82
-84
spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js
...idget/components/states/mr_widget_failed_to_merge_spec.js
+82
-84
No files found.
spec/frontend/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js
View file @
b1beb2e5
import
Vue
from
'
vue
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
mountComponent
from
'
helpers/vue_mount_component_helper
'
;
import
{
nextTick
}
from
'
vue
'
;
import
failedToMergeComponent
from
'
~/vue_merge_request_widget/components/states/mr_widget_failed_to_merge.vue
'
;
import
StatusIcon
from
'
~/vue_merge_request_widget/components/mr_widget_status_icon.vue
'
;
import
MrWidgetFailedToMerge
from
'
~/vue_merge_request_widget/components/states/mr_widget_failed_to_merge.vue
'
;
import
eventHub
from
'
~/vue_merge_request_widget/event_hub
'
;
import
eventHub
from
'
~/vue_merge_request_widget/event_hub
'
;
describe
(
'
MRWidgetFailedToMerge
'
,
()
=>
{
describe
(
'
MRWidgetFailedToMerge
'
,
()
=>
{
const
dummyIntervalId
=
1337
;
const
dummyIntervalId
=
1337
;
let
Component
;
let
wrapper
;
let
mr
;
let
vm
;
const
createComponent
=
(
props
=
{},
data
=
{})
=>
{
wrapper
=
shallowMount
(
MrWidgetFailedToMerge
,
{
propsData
:
{
mr
:
{
mergeError
:
'
Merge error happened
'
,
},
...
props
,
},
data
()
{
return
data
;
},
});
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
Component
=
Vue
.
extend
(
failedToMergeComponent
);
jest
.
spyOn
(
eventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
eventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
window
,
'
setInterval
'
).
mockReturnValue
(
dummyIntervalId
);
jest
.
spyOn
(
window
,
'
setInterval
'
).
mockReturnValue
(
dummyIntervalId
);
jest
.
spyOn
(
window
,
'
clearInterval
'
).
mockImplementation
();
jest
.
spyOn
(
window
,
'
clearInterval
'
).
mockImplementation
();
mr
=
{
mergeError
:
'
Merge error happened
'
,
};
vm
=
mountComponent
(
Component
,
{
mr
,
});
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
vm
.
$destroy
();
wrapper
.
destroy
();
});
it
(
'
sets interval to refresh
'
,
()
=>
{
expect
(
window
.
setInterval
).
toHaveBeenCalledWith
(
vm
.
updateTimer
,
1000
);
expect
(
vm
.
intervalId
).
toBe
(
dummyIntervalId
);
});
});
it
(
'
clears interval when destroying
'
,
()
=>
{
describe
(
'
interval
'
,
()
=>
{
vm
.
$destroy
();
it
(
'
sets interval to refresh
'
,
()
=>
{
createComponent
();
expect
(
window
.
clearInterval
).
toHaveBeenCalledWith
(
dummyIntervalId
);
expect
(
window
.
setInterval
).
toHaveBeenCalledWith
(
wrapper
.
vm
.
updateTimer
,
1000
);
});
expect
(
wrapper
.
vm
.
intervalId
).
toBe
(
dummyIntervalId
);
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
timerText
'
,
()
=>
{
it
(
'
should return correct timer text
'
,
()
=>
{
expect
(
vm
.
timerText
).
toEqual
(
'
Refreshing in 10 seconds to show the updated status...
'
);
vm
.
timer
=
1
;
it
(
'
clears interval when destroying
'
,
()
=>
{
createComponent
();
wrapper
.
destroy
();
expect
(
vm
.
timerText
).
toEqual
(
'
Refreshing in a second to show the updated status...
'
);
expect
(
window
.
clearInterval
).
toHaveBeenCalledWith
(
dummyIntervalId
);
});
});
});
});
describe
(
'
mergeError
'
,
()
=>
{
describe
(
'
mergeError
'
,
()
=>
{
it
(
'
removes forced line breaks
'
,
(
done
)
=>
{
it
(
'
removes forced line breaks
'
,
async
(
)
=>
{
mr
.
mergeError
=
'
contains<br />line breaks<br />
'
;
createComponent
({
mr
:
{
mergeError
:
'
contains<br />line breaks<br />
'
}
})
;
Vue
.
nextTick
()
await
nextTick
();
.
then
(()
=>
{
expect
(
vm
.
mergeError
).
toBe
(
'
contains line breaks.
'
);
expect
(
wrapper
.
vm
.
mergeError
).
toBe
(
'
contains line breaks.
'
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
});
});
describe
(
'
created
'
,
()
=>
{
describe
(
'
created
'
,
()
=>
{
it
(
'
should disable polling
'
,
()
=>
{
it
(
'
should disable polling
'
,
()
=>
{
createComponent
();
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
DisablePolling
'
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
DisablePolling
'
);
});
});
});
});
...
@@ -71,11 +69,13 @@ describe('MRWidgetFailedToMerge', () => {
...
@@ -71,11 +69,13 @@ describe('MRWidgetFailedToMerge', () => {
describe
(
'
methods
'
,
()
=>
{
describe
(
'
methods
'
,
()
=>
{
describe
(
'
refresh
'
,
()
=>
{
describe
(
'
refresh
'
,
()
=>
{
it
(
'
should emit event to request component refresh
'
,
()
=>
{
it
(
'
should emit event to request component refresh
'
,
()
=>
{
expect
(
vm
.
isRefreshing
).
toEqual
(
false
);
createComponent
();
expect
(
wrapper
.
vm
.
isRefreshing
).
toBe
(
false
);
vm
.
refresh
();
wrapper
.
vm
.
refresh
();
expect
(
vm
.
isRefreshing
).
toEqual
(
true
);
expect
(
wrapper
.
vm
.
isRefreshing
).
toBe
(
true
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
MRWidgetUpdateRequested
'
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
MRWidgetUpdateRequested
'
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
EnablePolling
'
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
EnablePolling
'
);
});
});
...
@@ -83,78 +83,76 @@ describe('MRWidgetFailedToMerge', () => {
...
@@ -83,78 +83,76 @@ describe('MRWidgetFailedToMerge', () => {
describe
(
'
updateTimer
'
,
()
=>
{
describe
(
'
updateTimer
'
,
()
=>
{
it
(
'
should update timer and emit event when timer end
'
,
()
=>
{
it
(
'
should update timer and emit event when timer end
'
,
()
=>
{
jest
.
spyOn
(
vm
,
'
refresh
'
).
mockImplementation
(()
=>
{});
createComponent
();
jest
.
spyOn
(
wrapper
.
vm
,
'
refresh
'
).
mockImplementation
(()
=>
{});
expect
(
vm
.
timer
).
toEqual
(
10
);
expect
(
wrapper
.
vm
.
timer
).
toEqual
(
10
);
for
(
let
i
=
0
;
i
<
10
;
i
+=
1
)
{
for
(
let
i
=
0
;
i
<
10
;
i
+=
1
)
{
expect
(
vm
.
timer
).
toEqual
(
10
-
i
);
expect
(
wrapper
.
vm
.
timer
).
toEqual
(
10
-
i
);
vm
.
updateTimer
();
wrapper
.
vm
.
updateTimer
();
}
}
expect
(
vm
.
refresh
).
toHaveBeenCalled
();
expect
(
wrapper
.
vm
.
refresh
).
toHaveBeenCalled
();
});
});
});
});
});
});
describe
(
'
while it is refreshing
'
,
()
=>
{
describe
(
'
while it is refreshing
'
,
()
=>
{
it
(
'
renders Refresing now
'
,
(
done
)
=>
{
it
(
'
renders Refresing now
'
,
async
()
=>
{
vm
.
isRefreshing
=
true
;
createComponent
({},
{
isRefreshing
:
true
});
Vue
.
nextTick
(()
=>
{
await
nextTick
();
expect
(
vm
.
$el
.
querySelector
(
'
.js-refresh-label
'
).
textContent
.
trim
()).
toEqual
(
'
Refreshing now
'
,
expect
(
wrapper
.
find
(
'
.js-refresh-label
'
).
text
().
trim
()).
toBe
(
'
Refreshing now
'
);
);
done
();
});
});
});
});
});
describe
(
'
while it is not regresing
'
,
()
=>
{
describe
(
'
while it is not regresing
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
();
});
it
(
'
renders warning icon and disabled merge button
'
,
()
=>
{
it
(
'
renders warning icon and disabled merge button
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.js-ci-status-icon-warning
'
)).
not
.
toBeNull
();
expect
(
wrapper
.
find
(
'
.js-ci-status-icon-warning
'
)).
not
.
toBeNull
();
expect
(
expect
(
wrapper
.
find
(
StatusIcon
).
props
(
'
showDisabledButton
'
)).
toBe
(
true
);
vm
.
$el
.
querySelector
(
'
[data-testid="disabled-merge-button"]
'
).
getAttribute
(
'
disabled
'
),
).
toEqual
(
'
disabled
'
);
});
});
it
(
'
renders given error
'
,
()
=>
{
it
(
'
renders given error
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.has-error-message
'
).
textContent
.
trim
()).
toEqual
(
expect
(
wrapper
.
find
(
'
.has-error-message
'
).
text
().
trim
()).
toBe
(
'
Merge error happened.
'
);
'
Merge error happened.
'
,
);
});
});
it
(
'
renders refresh button
'
,
()
=>
{
it
(
'
renders refresh button
'
,
()
=>
{
expect
(
expect
(
vm
.
$el
wrapper
.
find
(
'
[data-testid="merge-request-failed-refresh-button"]
'
).
text
().
trim
(),
.
querySelector
(
'
[data-testid="merge-request-failed-refresh-button"]
'
)
).
toBe
(
'
Refresh now
'
);
.
textContent
.
trim
(),
).
toEqual
(
'
Refresh now
'
);
});
});
it
(
'
renders remaining time
'
,
()
=>
{
it
(
'
renders remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.has-custom-error
'
).
textContent
.
trim
()).
toEqual
(
expect
(
wrapper
.
find
(
'
.has-custom-error
'
).
text
().
trim
()).
toBe
(
'
Refreshing in 10 seconds to show the updated status...
'
,
'
Refreshing in 10 seconds to show the updated status...
'
,
);
);
});
});
});
});
it
(
'
should just generic merge failed message if merge_error is not available
'
,
(
done
)
=>
{
it
(
'
should just generic merge failed message if merge_error is not available
'
,
async
(
)
=>
{
vm
.
mr
.
mergeError
=
null
;
createComponent
({
mr
:
{
mergeError
:
null
}
})
;
Vue
.
nextTick
(()
=>
{
await
nextTick
();
expect
(
vm
.
$el
.
innerText
).
toContain
(
'
Merge failed.
'
);
expect
(
vm
.
$el
.
innerText
).
not
.
toContain
(
'
Merge error happened.
'
);
expect
(
wrapper
.
text
().
trim
()).
toContain
(
'
Merge failed.
'
);
done
();
expect
(
wrapper
.
text
().
trim
()).
not
.
toContain
(
'
Merge error happened.
'
);
});
});
});
it
(
'
should show refresh label when refresh requested
'
,
(
done
)
=>
{
it
(
'
should show refresh label when refresh requested
'
,
async
()
=>
{
vm
.
refresh
();
createComponent
();
Vue
.
nextTick
(()
=>
{
expect
(
vm
.
$el
.
innerText
).
not
.
toContain
(
'
Merge failed. Refreshing
'
);
wrapper
.
vm
.
refresh
();
expect
(
vm
.
$el
.
innerText
).
toContain
(
'
Refreshing now
'
);
done
();
await
nextTick
();
});
expect
(
wrapper
.
text
().
trim
()).
not
.
toContain
(
'
Merge failed. Refreshing
'
);
expect
(
wrapper
.
text
().
trim
()).
toContain
(
'
Refreshing now
'
);
});
});
});
});
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