Maintenance: Stabilize KB granular permissions tests.

This commit is contained in:
Mantas Masalskis 2022-03-08 20:19:45 +01:00 committed by Martin Gruner
parent eb9882f39f
commit 381713e5db
2 changed files with 10 additions and 32 deletions

View file

@ -14,8 +14,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
it 'shows roles with has KB permissions only' do it 'shows roles with has KB permissions only' do
open_page category open_page category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_text(%r{Admin}i) .to have_text(%r{Admin}i)
@ -28,8 +26,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
it 'shows existing permissions when category has no permissions' do it 'shows existing permissions when category has no permissions' do
open_page category open_page category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_editor.id}'][value='editor'][checked]:not([disabled])", visible: :all) .to have_css("input[name='#{role_editor.id}'][value='editor'][checked]:not([disabled])", visible: :all)
@ -43,8 +39,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page category open_page category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_reader.id}'][value='reader']:not([disabled])", visible: :all) .to have_css("input[name='#{role_reader.id}'][value='reader']:not([disabled])", visible: :all)
@ -57,8 +51,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page child_category open_page child_category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_reader.id}'][value='reader']:not([disabled])", visible: :all) .to have_css("input[name='#{role_reader.id}'][value='reader']:not([disabled])", visible: :all)
@ -71,8 +63,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page child_category open_page child_category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_another_editor.id}'][value='none']:not([disabled])", visible: :all) .to have_css("input[name='#{role_another_editor.id}'][value='none']:not([disabled])", visible: :all)
@ -86,8 +76,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page child_category open_page child_category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_another_editor.id}'][value='none'][checked]:not([disabled])", visible: :all) .to have_css("input[name='#{role_another_editor.id}'][value='none'][checked]:not([disabled])", visible: :all)
@ -101,8 +89,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page child_category open_page child_category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_reader.id}'][value='none'][checked]:not([disabled])", visible: :all) .to have_css("input[name='#{role_reader.id}'][value='none'][checked]:not([disabled])", visible: :all)
@ -115,8 +101,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
it 'saves permissions' do it 'saves permissions' do
open_page category open_page category
find('[data-action=permissions]').click
in_modal do in_modal do
find("input[name='#{role_reader.id}'][value='none']", visible: :all) find("input[name='#{role_reader.id}'][value='none']", visible: :all)
.ancestor('label') .ancestor('label')
@ -137,8 +121,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
open_page category open_page category
find('[data-action=permissions]').click
in_modal do in_modal do
find("input[name='#{role_reader.id}'][value='reader']", visible: :all) find("input[name='#{role_reader.id}'][value='reader']", visible: :all)
.ancestor('label') .ancestor('label')
@ -157,8 +139,6 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
it 'does not allow to lock user himself' do it 'does not allow to lock user himself' do
open_page category open_page category
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
find("input[name='#{role_editor.id}'][value='reader']", visible: :all) find("input[name='#{role_editor.id}'][value='reader']", visible: :all)
.ancestor('label') .ancestor('label')
@ -173,5 +153,9 @@ RSpec.describe 'Knowledge Base Locale Category Permissions', type: :system do
def open_page(category) def open_page(category)
visit "knowledge_base/#{knowledge_base.id}/locale/#{Locale.first.locale}/category/#{category.id}/edit" visit "knowledge_base/#{knowledge_base.id}/locale/#{Locale.first.locale}/category/#{category.id}/edit"
find('[data-action=permissions]').click
travel_to 1.hour.from_now
end end
end end

View file

@ -12,8 +12,6 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
it 'shows roles with has KB permissions only' do it 'shows roles with has KB permissions only' do
open_page open_page
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_text(%r{Admin}i) .to have_text(%r{Admin}i)
@ -26,8 +24,6 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
it 'shows existing permissions when KB has no permissions' do it 'shows existing permissions when KB has no permissions' do
open_page open_page
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_editor.id}'][value='editor'][checked]", visible: :all) .to have_css("input[name='#{role_editor.id}'][value='editor'][checked]", visible: :all)
@ -40,8 +36,6 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
open_page open_page
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
expect(page) expect(page)
.to have_css("input[name='#{role_another_editor.id}'][value='reader'][checked]", visible: :all) .to have_css("input[name='#{role_another_editor.id}'][value='reader'][checked]", visible: :all)
@ -53,9 +47,8 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
describe 'saving changes' do describe 'saving changes' do
it 'saves permissions' do it 'saves permissions' do
role_another_editor role_another_editor
open_page
find('[data-action=permissions]').click open_page
in_modal do in_modal do
find("input[name='#{role_another_editor.id}'][value='reader']", visible: :all) find("input[name='#{role_another_editor.id}'][value='reader']", visible: :all)
@ -75,9 +68,8 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
it 'allows to modify existing permissions' do it 'allows to modify existing permissions' do
KnowledgeBase::PermissionsUpdate.new(knowledge_base).update! role_another_editor => 'reader' KnowledgeBase::PermissionsUpdate.new(knowledge_base).update! role_another_editor => 'reader'
open_page
find('[data-action=permissions]').click open_page
in_modal do in_modal do
find("input[name='#{role_another_editor.id}'][value='editor']", visible: :all) find("input[name='#{role_another_editor.id}'][value='editor']", visible: :all)
@ -98,8 +90,6 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
it 'does not allow to lock user himself' do it 'does not allow to lock user himself' do
open_page open_page
find('[data-action=permissions]').click
in_modal disappears: false do in_modal disappears: false do
find("input[name='#{role_editor.id}'][value='reader']", visible: :all) find("input[name='#{role_editor.id}'][value='reader']", visible: :all)
.ancestor('label') .ancestor('label')
@ -114,5 +104,9 @@ RSpec.describe 'Knowledge Base Locale Knowledge Base Permissions', type: :system
def open_page def open_page
visit "knowledge_base/#{knowledge_base.id}/locale/#{Locale.first.locale}/edit" visit "knowledge_base/#{knowledge_base.id}/locale/#{Locale.first.locale}/edit"
find('[data-action=permissions]').click
travel_to 1.hour.from_now
end end
end end