Commit 74f2f9b3 authored by Annabel Dunstone Gray's avatar Annabel Dunstone Gray

Merge branch '16988-use-toggle-for-subscribed-unsubscribed-to-notifications' into 'master'

Resolve "Use toggle for subscribed/unsubscribed to notifications"

Closes #16988

See merge request gitlab-org/gitlab-ce!16408
parents 6b5b93ab 0815236f
<script> <script>
/* eslint-disable vue/require-default-prop */ import { __ } from '~/locale';
import { __ } from '../../../locale'; import icon from '~/vue_shared/components/icon.vue';
import toggleButton from '~/vue_shared/components/toggle_button.vue';
import tooltip from '~/vue_shared/directives/tooltip';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
import loadingButton from '../../../vue_shared/components/loading_button.vue';
const ICON_ON = 'notifications';
const ICON_OFF = 'notifications-off';
const LABEL_ON = __('Notifications on');
const LABEL_OFF = __('Notifications off');
export default { export default {
directives: {
tooltip,
},
components: { components: {
loadingButton, icon,
toggleButton,
}, },
props: { props: {
loading: { loading: {
...@@ -17,22 +27,23 @@ ...@@ -17,22 +27,23 @@
subscribed: { subscribed: {
type: Boolean, type: Boolean,
required: false, required: false,
default: null,
}, },
id: { id: {
type: Number, type: Number,
required: false, required: false,
default: null,
}, },
}, },
computed: { computed: {
buttonLabel() { showLoadingState() {
let label; return this.subscribed === null;
if (this.subscribed === false) { },
label = __('Subscribe'); notificationIcon() {
} else if (this.subscribed === true) { return this.subscribed ? ICON_ON : ICON_OFF;
label = __('Unsubscribe'); },
} notificationTooltip() {
return this.subscribed ? LABEL_ON : LABEL_OFF;
return label;
}, },
}, },
methods: { methods: {
...@@ -46,21 +57,29 @@ ...@@ -46,21 +57,29 @@
<template> <template>
<div> <div>
<div class="sidebar-collapsed-icon"> <div class="sidebar-collapsed-icon">
<i <span
class="fa fa-rss" v-tooltip
aria-hidden="true" :title="notificationTooltip"
data-container="body"
data-placement="left"
> >
</i> <icon
:name="notificationIcon"
:size="16"
aria-hidden="true"
class="sidebar-item-icon is-active"
/>
</span>
</div> </div>
<span class="issuable-header-text hide-collapsed pull-left"> <span class="issuable-header-text hide-collapsed pull-left">
{{ __('Notifications') }} {{ __('Notifications') }}
</span> </span>
<loading-button <toggle-button
ref="loadingButton" ref="toggleButton"
class="btn btn-default pull-right hide-collapsed js-issuable-subscribe-button" class="pull-right hide-collapsed js-issuable-subscribe-button"
:loading="loading" :is-loading="showLoadingState"
:label="buttonLabel" :value="subscribed"
@click="toggleSubscription" @change="toggleSubscription"
/> />
</div> </div>
</template> </template>
...@@ -23,11 +23,12 @@ ...@@ -23,11 +23,12 @@
name: { name: {
type: String, type: String,
required: false, required: false,
default: '', default: null,
}, },
value: { value: {
type: Boolean, type: Boolean,
required: true, required: false,
default: null,
}, },
disabledInput: { disabledInput: {
type: Boolean, type: Boolean,
...@@ -61,6 +62,7 @@ ...@@ -61,6 +62,7 @@
<template> <template>
<label class="toggle-wrapper"> <label class="toggle-wrapper">
<input <input
v-if="name"
type="hidden" type="hidden"
:name="name" :name="name"
:value="value" :value="value"
......
...@@ -162,10 +162,6 @@ ...@@ -162,10 +162,6 @@
border: 0; border: 0;
} }
span {
display: inline-block;
}
.select2-container span { .select2-container span {
margin-top: 0; margin-top: 0;
} }
......
...@@ -164,7 +164,7 @@ Feature: Project Issues ...@@ -164,7 +164,7 @@ Feature: Project Issues
Given project "Shop" have "Release 0.4" open issue Given project "Shop" have "Release 0.4" open issue
When I visit issue page "Release 0.4" When I visit issue page "Release 0.4"
Then I should see that I am subscribed Then I should see that I am subscribed
When I click button "Unsubscribe" When I click the subscription toggle
Then I should see that I am unsubscribed Then I should see that I am unsubscribed
@javascript @javascript
......
...@@ -21,20 +21,20 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps ...@@ -21,20 +21,20 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps
step 'I should see that I am subscribed' do step 'I should see that I am subscribed' do
wait_for_requests wait_for_requests
expect(find('.js-issuable-subscribe-button span')).to have_content 'Unsubscribe' expect(find('.js-issuable-subscribe-button')).to have_css 'button.is-checked'
end end
step 'I should see that I am unsubscribed' do step 'I should see that I am unsubscribed' do
wait_for_requests wait_for_requests
expect(find('.js-issuable-subscribe-button span')).to have_content 'Subscribe' expect(find('.js-issuable-subscribe-button')).to have_css 'button:not(.is-checked)'
end end
step 'I click link "Closed"' do step 'I click link "Closed"' do
find('.issues-state-filters [data-state="closed"] span', text: 'Closed').click find('.issues-state-filters [data-state="closed"] span', text: 'Closed').click
end end
step 'I click button "Unsubscribe"' do step 'I click the subscription toggle' do
click_on "Unsubscribe" find('.js-issuable-subscribe-button button').click
end end
step 'I should see "Release 0.3" in issues' do step 'I should see "Release 0.3" in issues' do
......
...@@ -334,14 +334,14 @@ describe 'Issue Boards', :js do ...@@ -334,14 +334,14 @@ describe 'Issue Boards', :js do
wait_for_requests wait_for_requests
page.within('.subscriptions') do page.within('.subscriptions') do
click_button 'Subscribe' find('.js-issuable-subscribe-button button:not(.is-checked)').click
wait_for_requests wait_for_requests
expect(page).to have_content('Unsubscribe') expect(page).to have_css('.js-issuable-subscribe-button button.is-checked')
end end
end end
it 'has "Unsubscribe" button when already subscribed' do it 'has checked subscription toggle when already subscribed' do
create(:subscription, user: user, project: project, subscribable: issue2, subscribed: true) create(:subscription, user: user, project: project, subscribable: issue2, subscribed: true)
visit project_board_path(project, board) visit project_board_path(project, board)
wait_for_requests wait_for_requests
...@@ -350,10 +350,10 @@ describe 'Issue Boards', :js do ...@@ -350,10 +350,10 @@ describe 'Issue Boards', :js do
wait_for_requests wait_for_requests
page.within('.subscriptions') do page.within('.subscriptions') do
click_button 'Unsubscribe' find('.js-issuable-subscribe-button button.is-checked').click
wait_for_requests wait_for_requests
expect(page).to have_content('Subscribe') expect(page).to have_css('.js-issuable-subscribe-button button:not(.is-checked)')
end end
end end
end end
......
...@@ -13,20 +13,18 @@ describe 'User manages subscription', :js do ...@@ -13,20 +13,18 @@ describe 'User manages subscription', :js do
end end
it 'toggles subscription' do it 'toggles subscription' do
subscribe_button = find('.js-issuable-subscribe-button') page.within('.js-issuable-subscribe-button') do
expect(page).to have_css 'button:not(.is-checked)'
find('button:not(.is-checked)').click
expect(subscribe_button).to have_content('Subscribe') wait_for_requests
click_on('Subscribe') expect(page).to have_css 'button.is-checked'
find('button.is-checked').click
wait_for_requests wait_for_requests
expect(subscribe_button).to have_content('Unsubscribe') expect(page).to have_css 'button:not(.is-checked)'
end
click_on('Unsubscribe')
wait_for_requests
expect(subscribe_button).to have_content('Subscribe')
end end
end end
...@@ -20,23 +20,23 @@ describe('Subscriptions', function () { ...@@ -20,23 +20,23 @@ describe('Subscriptions', function () {
subscribed: undefined, subscribed: undefined,
}); });
expect(vm.$refs.loadingButton.loading).toBe(true); expect(vm.$refs.toggleButton.isLoading).toBe(true);
expect(vm.$refs.loadingButton.label).toBeUndefined(); expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass('is-loading');
}); });
it('has "Subscribe" text when currently not subscribed', () => { it('is toggled "off" when currently not subscribed', () => {
vm = mountComponent(Subscriptions, { vm = mountComponent(Subscriptions, {
subscribed: false, subscribed: false,
}); });
expect(vm.$refs.loadingButton.label).toBe('Subscribe'); expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).not.toHaveClass('is-checked');
}); });
it('has "Unsubscribe" text when currently not subscribed', () => { it('is toggled "on" when currently subscribed', () => {
vm = mountComponent(Subscriptions, { vm = mountComponent(Subscriptions, {
subscribed: true, subscribed: true,
}); });
expect(vm.$refs.loadingButton.label).toBe('Unsubscribe'); expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass('is-checked');
}); });
}); });
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