Skip to content

Commit

Permalink
Maintenance: Add tests for user profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed Apr 19, 2024
1 parent 379b0dc commit 6ed5c8a
Show file tree
Hide file tree
Showing 44 changed files with 91 additions and 173 deletions.
61 changes: 61 additions & 0 deletions spec/system/apps/desktop/account_spec.rb
@@ -0,0 +1,61 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe 'Desktop > Account', app: :desktop_view, authenticated_as: :agent, type: :system do
let(:agent) { create(:agent) }

before do
visit '/'
find("[aria-label=\"Avatar (#{agent.fullname})\"]").click
end

describe 'appearance selection' do
it 'user can switch appearance' do
# Switch starts on 'auto'
default_theme = page.execute_script("return matchMedia('(prefers-color-scheme: dark)').matches") ? 'dark' : 'light'
expect(page).to have_css("html[data-theme=#{default_theme}]")

# Switch to 'dark'
click_on 'Appearance'
wait_for_mutation('accountAppearance')
expect(page).to have_css('html[data-theme=dark]')

# Switch to 'light'
click_on 'Appearance'
wait_for_mutation('accountAppearance', number: 2)
expect(page).to have_css('html[data-theme=light]')

end
end

describe 'language selection' do
it 'user can change language' do
click_on 'Profile settings'
click_on 'Language'

find('label', text: 'Your language').click
find('span', text: 'Deutsch').click
expect(page).to have_text('Sprache')
end
end

describe 'avatar handling', authenticated_as: :agent do
let(:agent) { create(:agent, firstname: 'Jane', lastname: 'Doe') }

it 'user can upload avatar' do
click_on 'Profile settings'
click_on 'Avatar'

expect(page).to have_text('JD')
find('input[data-test-id="fileUploadInput"]', visible: :all).set(Rails.root.join('test/data/image/1000x1000.png'))
expect(page).to have_text('Avatar Preview')
click_on 'Save'

expect(page).to have_text('Your avatar has been uploaded')

avatar_element_style = find("#user-menu span[aria-label=\"Avatar (#{agent.fullname})\"]").style('background-image')
expect(avatar_element_style['background-image']).to include("/api/v1/users/image/#{Avatar.last.store_hash}")
end
end
end
139 changes: 0 additions & 139 deletions spec/system/apps/mobile/account/avatar_spec.rb

This file was deleted.

48 changes: 22 additions & 26 deletions spec/system/apps/mobile/account_spec.rb
Expand Up @@ -3,42 +3,38 @@
require 'rails_helper'

RSpec.describe 'Mobile > App Account Page', app: :mobile, type: :system do
context 'when on account page' do
let(:admin) { create(:admin) }
let(:agent) { create(:agent) }

describe 'language selection' do
before do
visit '/account'
end

context 'when updating locale', authenticated_as: :agent do
it 'check that user can see and change locale' do
locale = find_treeselect('Language')
it 'user can change language' do
locale = find_treeselect('Language')
locale.select_option('Deutsch')
expect(page).to have_text('Sprache')
end
end

# current locale is visible
expect(locale).to have_selected_option('English (United States)')
describe 'avatar handling', authenticated_as: :agent do
let(:agent) { create(:agent, firstname: 'Jane', lastname: 'Doe') }

locale.select_option('Dansk')
wait_for_gql('shared/entities/account/graphql/mutations/locale.graphql')
agent.reload
expect(agent.preferences[:locale]).to eq('da')
end
before do
visit '/account/avatar'
end

context 'when checking about information' do
context 'when permitted', authenticated_as: :admin do
it 'shows about information' do
wait_for_gql('shared/graphql/queries/about.graphql')
it 'user can upload avatar' do
expect(page).to have_text('JD')
find('input[data-test-id="fileGalleryInput"]', visible: :all).set(Rails.root.join('test/data/image/1000x1000.png'))

expect(page).to have_css('.vue-advanced-cropper')
click_on 'Save'

expect(page).to have_content(Version.get)
end
end
wait.until { Avatar.last.present? }
store = Store.find(Avatar.last.store_resize_id)
img_url = "data:#{store.preferences['Mime-Type']};base64,#{Base64.strict_encode64(store.content)}"

context 'when forbidden', authenticated_as: :agent do
it 'does not show about information' do
expect(page).to have_no_content(Version.get)
end
end
avatar_element_style = find('[data-test-id="common-avatar"]').style('background-image')
expect(avatar_element_style['background-image']).to eq("url(\"#{img_url}\")")
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

require 'system/apps/mobile/examples/core_workflow_examples'
require 'system/apps/mobile_old/examples/core_workflow_examples'

RSpec.describe 'Mobile > Organization > Can edit organization', app: :mobile, type: :system do
let(:organization) { create(:organization, domain: 'domain.com', note: '') }
Expand Down
@@ -1,8 +1,8 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/create_article_examples'
require 'system/apps/mobile/examples/article_security_examples'
require 'system/apps/mobile_old/examples/create_article_examples'
require 'system/apps/mobile_old/examples/article_security_examples'

RSpec.describe 'Mobile > Ticket > Article > Create', app: :mobile, authenticated_as: :agent, type: :system do
let(:group) { Group.find_by(name: 'Users') }
Expand Down
@@ -1,7 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/reply_article_examples'
require 'system/apps/mobile_old/examples/reply_article_examples'

RSpec.describe 'Mobile > Ticket > Article actions', app: :mobile, authenticated_as: :agent, type: :system do
let(:group) { Group.find_by(name: 'Users') }
Expand Down
@@ -1,7 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/article_security_examples'
require 'system/apps/mobile_old/examples/article_security_examples'

RSpec.describe 'Mobile > Ticket > Create with security options', app: :mobile, authenticated_as: :authenticate, type: :system do
def prepare_phone_article
Expand Down
@@ -1,7 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/core_workflow_examples'
require 'system/apps/mobile_old/examples/core_workflow_examples'

RSpec.describe 'Mobile > Ticket > Create', app: :mobile, authenticated_as: :user, type: :system do
let(:group) { Group.find_by(name: 'Users') }
Expand Down
@@ -1,7 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/core_workflow_examples'
require 'system/apps/mobile_old/examples/core_workflow_examples'

RSpec.describe 'Mobile > Ticket > Update', app: :mobile, authenticated_as: :agent, type: :system do
let(:group) { Group.find_by(name: 'Users') }
Expand Down
@@ -1,7 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/apps/mobile/examples/core_workflow_examples'
require 'system/apps/mobile_old/examples/core_workflow_examples'

RSpec.describe 'Mobile > Search > User > Edit', app: :mobile, authenticated_as: :authenticate, type: :system do
let(:user) { create(:customer, :with_org, address: 'Berlin') }
Expand Down

0 comments on commit 6ed5c8a

Please sign in to comment.