Commit 8f1dd45a authored by Lukas Eipert's avatar Lukas Eipert Committed by Clement Ho

Resolve "Merge request spinner spins forever after loading the diff"

parent 4c74936f
...@@ -362,7 +362,7 @@ export default class MergeRequestTabs { ...@@ -362,7 +362,7 @@ export default class MergeRequestTabs {
// //
// status - Boolean, true to show, false to hide // status - Boolean, true to show, false to hide
toggleLoading(status) { toggleLoading(status) {
$('.mr-loading-status .loading').toggleClass('hidden', status); $('.mr-loading-status .loading').toggleClass('hidden', !status);
} }
diffViewType() { diffViewType() {
......
...@@ -77,8 +77,7 @@ export default class UserTabs { ...@@ -77,8 +77,7 @@ export default class UserTabs {
this.action = action || this.defaultAction; this.action = action || this.defaultAction;
this.$parentEl = $(parentEl) || $(document); this.$parentEl = $(parentEl) || $(document);
this.windowLocation = window.location; this.windowLocation = window.location;
this.$parentEl.find('.nav-links a') this.$parentEl.find('.nav-links a').each((i, navLink) => {
.each((i, navLink) => {
this.loaded[$(navLink).attr('data-action')] = false; this.loaded[$(navLink).attr('data-action')] = false;
}); });
this.actions = Object.keys(this.loaded); this.actions = Object.keys(this.loaded);
...@@ -116,8 +115,7 @@ export default class UserTabs { ...@@ -116,8 +115,7 @@ export default class UserTabs {
} }
activateTab(action) { activateTab(action) {
return this.$parentEl.find(`.nav-links .js-${action}-tab a`) return this.$parentEl.find(`.nav-links .js-${action}-tab a`).tab('show');
.tab('show');
} }
setTab(action, endpoint) { setTab(action, endpoint) {
...@@ -137,7 +135,8 @@ export default class UserTabs { ...@@ -137,7 +135,8 @@ export default class UserTabs {
loadTab(action, endpoint) { loadTab(action, endpoint) {
this.toggleLoading(true); this.toggleLoading(true);
return axios.get(endpoint) return axios
.get(endpoint)
.then(({ data }) => { .then(({ data }) => {
const tabSelector = `div#${action}`; const tabSelector = `div#${action}`;
this.$parentEl.find(tabSelector).html(data.html); this.$parentEl.find(tabSelector).html(data.html);
...@@ -161,10 +160,11 @@ export default class UserTabs { ...@@ -161,10 +160,11 @@ export default class UserTabs {
const utcOffset = $calendarWrap.data('utcOffset'); const utcOffset = $calendarWrap.data('utcOffset');
let utcFormatted = 'UTC'; let utcFormatted = 'UTC';
if (utcOffset !== 0) { if (utcOffset !== 0) {
utcFormatted = `UTC${utcOffset > 0 ? '+' : ''}${(utcOffset / 3600)}`; utcFormatted = `UTC${utcOffset > 0 ? '+' : ''}${utcOffset / 3600}`;
} }
axios.get(calendarPath) axios
.get(calendarPath)
.then(({ data }) => { .then(({ data }) => {
$calendarWrap.html(CALENDAR_TEMPLATE); $calendarWrap.html(CALENDAR_TEMPLATE);
$calendarWrap.find('.calendar-hint').append(`(Timezone: ${utcFormatted})`); $calendarWrap.find('.calendar-hint').append(`(Timezone: ${utcFormatted})`);
...@@ -180,17 +180,20 @@ export default class UserTabs { ...@@ -180,17 +180,20 @@ export default class UserTabs {
} }
toggleLoading(status) { toggleLoading(status) {
return this.$parentEl.find('.loading-status .loading') return this.$parentEl.find('.loading-status .loading').toggleClass('hidden', !status);
.toggleClass('hidden', status);
} }
setCurrentAction(source) { setCurrentAction(source) {
let newState = source; let newState = source;
newState = newState.replace(/\/+$/, ''); newState = newState.replace(/\/+$/, '');
newState += this.windowLocation.search + this.windowLocation.hash; newState += this.windowLocation.search + this.windowLocation.hash;
history.replaceState({ history.replaceState(
{
url: newState, url: newState,
}, document.title, newState); },
document.title,
newState,
);
return newState; return newState;
} }
......
...@@ -26,6 +26,10 @@ describe 'User views diffs', :js do ...@@ -26,6 +26,10 @@ describe 'User views diffs', :js do
expect(page).to have_css('#inline-diff-btn', count: 1) expect(page).to have_css('#inline-diff-btn', count: 1)
end end
it 'hides loading spinner after load' do
expect(page).not_to have_selector('.mr-loading-status .loading', visible: true)
end
context 'when in the inline view' do context 'when in the inline view' do
include_examples 'unfold diffs' include_examples 'unfold diffs'
end end
......
...@@ -26,18 +26,23 @@ describe 'Users > User browses projects on user page', :js do ...@@ -26,18 +26,23 @@ describe 'Users > User browses projects on user page', :js do
end end
end end
it 'hides loading spinner after load', :js do
visit user_path(user)
click_nav_link('Personal projects')
wait_for_requests
expect(page).not_to have_selector('.loading-status .loading', visible: true)
end
it 'paginates projects', :js do it 'paginates projects', :js do
project = create(:project, namespace: user.namespace, updated_at: 2.minutes.since) project = create(:project, namespace: user.namespace, updated_at: 2.minutes.since)
project2 = create(:project, namespace: user.namespace, updated_at: 1.minute.since) project2 = create(:project, namespace: user.namespace, updated_at: 1.minute.since)
allow(Project).to receive(:default_per_page).and_return(1) allow(Project).to receive(:default_per_page).and_return(1)
sign_in(user) sign_in(user)
visit user_path(user) visit user_path(user)
click_nav_link('Personal projects')
page.within('.user-profile-nav') do
click_link('Personal projects')
end
wait_for_requests wait_for_requests
...@@ -92,7 +97,6 @@ describe 'Users > User browses projects on user page', :js do ...@@ -92,7 +97,6 @@ describe 'Users > User browses projects on user page', :js do
click_nav_link('Personal projects') click_nav_link('Personal projects')
expect(title).to start_with(user.name) expect(title).to start_with(user.name)
expect(page).to have_content(private_project.name) expect(page).to have_content(private_project.name)
expect(page).to have_content(public_project.name) expect(page).to have_content(public_project.name)
expect(page).to have_content(internal_project.name) expect(page).to have_content(internal_project.name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment