OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/features/work_packages/tabs/watcher_tab_spec.rb

140 lines
4.8 KiB

require 'spec_helper'
describe 'Watcher tab', js: true, selenium: true do
include ::Components::NgSelectAutocompleteHelpers
let(:project) { FactoryBot.create(:project) }
let(:work_package) { FactoryBot.create(:work_package, project: project) }
let(:tabs) { ::Components::WorkPackages::Tabs.new(work_package) }
let(:user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }
let(:role) { FactoryBot.create(:role, permissions: permissions) }
let(:permissions) {
%i(view_work_packages
view_work_package_watchers
delete_work_package_watchers
add_work_package_watchers)
}
let(:watch_button) { find '#watch-button' }
let(:watchers_tab) { find('.tabrow li.selected', text: 'WATCHERS') }
def expect_button_is_watching
title = I18n.t('js.label_unwatch_work_package')
Extract all access of APIv3 calls into APIv3Service (#8521) * Move apiv3 path helper into apiv3 service * Refactor application to use apiv3 service * Allow caching responses within apiv3 endpoints through state cache * Fix reference to root service * Continue refactoring of DM services * Refactor version DM service * Refactor order service into v3 paths * Replace time entry dm and cache service * Replace QueryFormDmService with nested form resource * Replace QueryDmService with api paths * Replace ProjectDM and ProjectCacheService * Move PayloadDmService into static helper class * Replace NewsDmService with api paths * Replace MembershipDmService with api paths * Replace HelpTextDmService with api paths * Replace ConfigurationDmService with apiv3 path * Replace GridDmService with paths * Remove DmListParameters This is now Apiv3ListParameters type * Replace virtual BoardDmService with a virtual path Boards are not actually their own API resource, but a shallow wrapper over a grid resource. To reuse the same API service pattern, we can allow other resources other than HalResource and make the boards path just reference the grids paths. This allows to nicely use the `apiV3Service.boards.id(..).cache` patterns. * Refactor cacheState into single method * Make HalEditingService a v3 cache without loading ability * Replace usages of WorkPackageCacheService with api-integrated cache * Fix accessing grid subpath * Correctly use schema ensureLoaded before inserting into caches * Fix query not having an ID when updating * Fix npm tests after removal of wp cache * Readd missing path helper for APIv3 used from ckeditor * Correctly save query in widget * Fix watcher tab * Fix search path * Use a promise for the updateImmediately link of time entry * Make apiv3 independent cache services depend on the base cache service We had two cache services now, one base service for the apiv3, and the previous one. Both shared a lot of code, so we can unify them * Don't use multiState getter in schemaCache * Correct loading of schema * Correctly fill state with relations * Don't render comment until workPackage ready * Merge the initial loading observable to get error handling If we only return state.values$(), we never get the initial http observable and thus no error handling * Ensure we reload the default query from the current project if any * Use get() instead of stream * Load types correctly * Fix paths in enterprise token urls * Ensure take(1) in requireAndStream toPromise usage * Avoid duplicate StateCacheService definition * Only use project based query when there is no query.id yet There is no endpoint for /api/v3/projects/:projectIdentifier/queries/:id * Add isAvailable to filter out filters incorrectly added The search component always adds a subproject filter when in project scope. This filter however is only valid/existent in schemas if there is a subproject. This ensures we only try to access filters that are available * Refactor embedded table to reuse the loadQueryFromExisting method We had a few duplicate methods on how to look for a query with params basing on an existing (saved or unsaved) query. * Ensure filter schemas are inserted and checked before use * Better matcher for search spec * Ensure correct initialization of query states * Load attribute help text correctly
4 years ago
expect(page).to have_selector("#unwatch-button[title='#{title}']", wait: 10)
expect(page).to have_selector('#unwatch-button .button--icon.icon-watched', wait: 10)
end
def expect_button_is_not_watching
title = I18n.t('js.label_watch_work_package')
expect(page).to have_selector("#watch-button[title='#{title}']")
expect(page).to have_selector('#watch-button .button--icon.icon-unwatched')
end
shared_examples 'watch and unwatch with button' do
it 'watching the WP modifies the watcher list' do
# Expect WP watch button is in not-watched state
expect_button_is_not_watching
expect(page).to have_no_selector('.work-package--watcher-name')
watch_button.click
# Expect WP watch button causes watcher list to add user
expect_button_is_watching
expect(page).to have_selector('.work-package--watcher-name', count: 1, text: user.name)
# Expect WP unwatch button causes watcher list to remove user
watch_button.click
expect_button_is_not_watching
expect(page).to have_no_selector('.work-package--watcher-name')
end
end
shared_examples 'watchers tab' do
before do
login_as(user)
wp_page.visit_tab! :watchers
expect_angular_frontend_initialized
expect(page).to have_selector('.tabrow li.selected', text: 'WATCHERS')
end
it 'modifying the watcher list modifies the watch button' do
# Add user as watcher
autocomplete = find('.wp-watcher--autocomplete')
[27828] Feature: Query menu in sidenav (#6429) * in main menu add gantt as extra work package child item * Satisfy spec and code climate * Add gantt chart icon behin default gantt query name. * WIP Query menu in left sidebar * Shift query dropdown in left sidenav * Reload menu or load query on click from every project location * WIP set correct label for default queries * Query menu listens on all changes of queries (delete, create, rename, toggle starred) and updates immediatly * WIP: Inline edit, field validation * Inline Edit validation and comfirm * Inline edit: validation of duplicate name * Set default columns and sorting for static queries * Codeclimate issues fixed * WIP Inline edit validation not working perfectly in all error states * Inline edit working * Autocompleter hover disabled and hovering over categories fixed * Category hover and toggle fixed; tested in Chrome, Firefox and Opera * Placeholder cut off fixed and text wrap added * English and german wording adjusted * Styles of inline edit and menu adjusted; matching wiki page styles * prevent menus to be displayed to often * application menu only displayed on work package * specify using no_menu layout more often * adapt tests to altered production implementation * Hamburger icon only in project; on global wp page: default queries shown correctly and summary removed * searching for undefined leads to error * Accessible click fixed (listen on escape) * Gantt in top menu deleted (gantt chart is part of default queries on wp page) * load menu on wp summary page * reduce times queries are loaded * lowercase on second word * remove menu from search and home * Styles fixed (category toggle and correct highlighting) * reflect static query in url * fix autocomplete handling in specs * Open all global menus on default and hide hamburger icon on global pages; Rebuild changes that have been ovrwritten after merge" * Correct highlighting of default queries after reload * Replace summary cuke with spec * WIP * Clear up selectors * Avoid actively setting promises and instead use $state.go to load links [ci skip] * Make editable title component a little simpler We can reuse the component I built for the wiki, that wasn't present in the frontend beforehand. * Fix moving through the menu and selecting items [ci skip] * Add save button to query title when query changed * Improve static names lookup by comparing query_props * Adapt and fix specs * Allow inner scrolling of wp query results Also, style the webkit scrollbar to make it pretty where supported * Allow renaming the query through setting menu, but simply focus on field [ci skip]
6 years ago
select_autocomplete autocomplete,
query: user.firstname,
select_text: user.name
# Expect the addition of the user to toggle WP watch button
expect(page).to have_selector('.work-package--watcher-name', count: 1, text: user.name)
expect_button_is_watching
# Expect watchers counter to increase
tabs.expect_counter(watchers_tab, 1)
# Remove watcher from list
page.find('wp-watcher-entry', text: user.name).hover
page.find('.form--selected-value--remover').click
# Watchers counter should not be displayed
tabs.expect_no_counter(watchers_tab)
# Expect the removal of the user to toggle WP watch button
expect(page).to have_no_selector('.work-package--watcher-name')
expect_button_is_not_watching
end
context 'with a user with arbitrary characters' do
let!(:html_user) {
FactoryBot.create :user,
firstname: '<em>foo</em>',
member_in_project: project,
member_through_role: role
}
it 'escapes the user name' do
autocomplete = find('.wp-watcher--autocomplete')
[27828] Feature: Query menu in sidenav (#6429) * in main menu add gantt as extra work package child item * Satisfy spec and code climate * Add gantt chart icon behin default gantt query name. * WIP Query menu in left sidebar * Shift query dropdown in left sidenav * Reload menu or load query on click from every project location * WIP set correct label for default queries * Query menu listens on all changes of queries (delete, create, rename, toggle starred) and updates immediatly * WIP: Inline edit, field validation * Inline Edit validation and comfirm * Inline edit: validation of duplicate name * Set default columns and sorting for static queries * Codeclimate issues fixed * WIP Inline edit validation not working perfectly in all error states * Inline edit working * Autocompleter hover disabled and hovering over categories fixed * Category hover and toggle fixed; tested in Chrome, Firefox and Opera * Placeholder cut off fixed and text wrap added * English and german wording adjusted * Styles of inline edit and menu adjusted; matching wiki page styles * prevent menus to be displayed to often * application menu only displayed on work package * specify using no_menu layout more often * adapt tests to altered production implementation * Hamburger icon only in project; on global wp page: default queries shown correctly and summary removed * searching for undefined leads to error * Accessible click fixed (listen on escape) * Gantt in top menu deleted (gantt chart is part of default queries on wp page) * load menu on wp summary page * reduce times queries are loaded * lowercase on second word * remove menu from search and home * Styles fixed (category toggle and correct highlighting) * reflect static query in url * fix autocomplete handling in specs * Open all global menus on default and hide hamburger icon on global pages; Rebuild changes that have been ovrwritten after merge" * Correct highlighting of default queries after reload * Replace summary cuke with spec * WIP * Clear up selectors * Avoid actively setting promises and instead use $state.go to load links [ci skip] * Make editable title component a little simpler We can reuse the component I built for the wiki, that wasn't present in the frontend beforehand. * Fix moving through the menu and selecting items [ci skip] * Add save button to query title when query changed * Improve static names lookup by comparing query_props * Adapt and fix specs * Allow inner scrolling of wp query results Also, style the webkit scrollbar to make it pretty where supported * Allow renaming the query through setting menu, but simply focus on field [ci skip]
6 years ago
target_dropdown = search_autocomplete autocomplete,
query: 'foo'
expect(target_dropdown).to have_selector(".ng-option", text: html_user.firstname)
expect(target_dropdown).to have_no_selector(".ng-option em")
end
end
context 'with all permissions' do
it_behaves_like 'watch and unwatch with button'
end
context 'without watchers permission' do
let(:permissions) { %i(view_work_packages view_work_package_watchers) }
it_behaves_like 'watch and unwatch with button'
end
end
context 'split screen' do
let(:wp_page) { Pages::SplitWorkPackage.new(work_package) }
it_behaves_like 'watchers tab'
end
context 'full screen' do
let(:wp_page) { Pages::FullWorkPackage.new(work_package) }
it_behaves_like 'watchers tab'
end
context 'when the work package has a watcher' do
let(:watchers) { FactoryBot.create(:watcher, watchable: work_package, user: user) }
let(:wp_table) { Pages::WorkPackagesTable.new(project) }
before do
watchers
login_as(user)
wp_table.visit!
wp_table.expect_work_package_listed work_package
end
it 'should show the number of watchers [#33685]' do
wp_table.open_full_screen_by_doubleclick(work_package)
expect(page).to have_selector('.wp-tabs-count', text: 1)
end
end
end