FEATURE: Introducing new UI for changing User's notification levels (#7248)

* FEATURE: Introducing new UI for tracking User's ignored or muted states
This commit is contained in:
Tarek Khalil
2019-03-27 09:41:50 +00:00
committed by GitHub
parent 675d950eab
commit ef2362a30f
16 changed files with 251 additions and 92 deletions

View File

@ -2022,7 +2022,7 @@ describe UsersController do
describe '#ignore' do
it 'raises an error when not logged in' do
put "/u/#{user.username}/ignore.json", params: { ignored_user_id: "" }
put "/u/#{user.username}/notification_level.json", params: { notification_level: "" }
expect(response.status).to eq(403)
end
@ -2033,58 +2033,43 @@ describe UsersController do
sign_in(user)
end
describe 'when SiteSetting.ignore_user_enabled is false' do
it 'raises an error' do
SiteSetting.ignore_user_enabled = false
put "/u/#{user.username}/ignore.json"
context 'when ignore_user_enable is OFF' do
it 'raises an error when not logged in' do
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "" }
expect(response.status).to eq(404)
end
end
describe 'when SiteSetting.ignore_user_enabled is true' do
it 'creates IgnoredUser record' do
SiteSetting.ignore_user_enabled = true
put "/u/#{user.username}/ignore.json", params: { ignored_user_id: another_user.id }
expect(response.status).to eq(200)
expect(IgnoredUser.find_by(user_id: user.id,
ignored_user_id: another_user.id)).to be_present
end
end
end
end
describe '#watch' do
it 'raises an error when not logged in' do
delete "/u/#{user.username}/ignore.json"
expect(response.status).to eq(403)
end
context 'while logged in' do
let(:user) { Fabricate(:user) }
let(:another_user) { Fabricate(:user) }
before do
sign_in(user)
end
describe 'when SiteSetting.ignore_user_enabled is false' do
it 'raises an error' do
SiteSetting.ignore_user_enabled = false
delete "/u/#{user.username}/ignore.json", params: { ignored_user_id: another_user.id }
expect(response.status).to eq(404)
end
end
describe 'when SiteSetting.ignore_user_enabled is true' do
context 'when ignore_user_enable is ON' do
before do
Fabricate(:ignored_user, user_id: user.id, ignored_user_id: another_user.id)
SiteSetting.ignore_user_enabled = true
end
it 'destroys IgnoredUser record' do
SiteSetting.ignore_user_enabled = true
delete "/u/#{user.username}/ignore.json", params: { ignored_user_id: another_user.id }
expect(response.status).to eq(200)
expect(IgnoredUser.find_by(user_id: user.id,
ignored_user_id: another_user.id)).to be_blank
let!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }
let!(:muted_user) { Fabricate(:muted_user, user: user, muted_user: another_user) }
context 'when changing notification level to normal' do
it 'changes notification level to normal' do
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }
expect(IgnoredUser.count).to eq(0)
expect(MutedUser.count).to eq(0)
end
end
context 'when changing notification level to mute' do
it 'changes notification level to mute' do
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "mute" }
expect(IgnoredUser.count).to eq(0)
expect(MutedUser.find_by(user_id: user.id, muted_user_id: another_user.id)).to be_present
end
end
context 'when changing notification level to ignore' do
it 'changes notification level to mute' do
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "ignore" }
expect(MutedUser.count).to eq(0)
expect(IgnoredUser.find_by(user_id: user.id, ignored_user_id: another_user.id)).to be_present
end
end
end
end