Skip to content

Commit

Permalink
Feature: Mobile - Add "phone" article type
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 25, 2023
1 parent 4a547d1 commit 60409bd
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const { showImage } = useImageViewer(uploadFiles)
ref="fileInput"
data-test-id="fileInput"
type="file"
:name="context.id"
class="hidden"
aria-hidden="true"
:accept="props.context.accept"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/

import { defaultTicket } from '@mobile/pages/ticket/__tests__/mocks/detail-view'
import { setupView } from '@tests/support/mock-user'
import { createTestArticleTypes } from './utils'

describe('phone type', () => {
it('customer cannot use phone type', () => {
setupView('customer')
const { ticket } = defaultTicket()
const actions = createTestArticleTypes(ticket)
expect(actions.find((a) => a.value === 'phone')).toBeUndefined()
})

it('agents can use phone type', () => {
setupView('agent')
const { ticket } = defaultTicket()
ticket.policy.update = true
const actions = createTestArticleTypes(ticket)
expect(actions.find((a) => a.value === 'phone')).toBeDefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { defaultArticles } from '@mobile/pages/ticket/__tests__/mocks/detail-view'
import type { TicketArticle, TicketById } from '@shared/entities/ticket/types'
import type { AppName } from '@shared/types/app'
import { initializeStore } from '@tests/support/components/initializeStore'
import { createArticleActions, createArticleTypes } from '../index'
import type { TicketActionAddOptions } from '../types'
Expand All @@ -28,7 +29,10 @@ export const createTestArticleActions = (
return createArticleActions(ticket, article, 'mobile', options)
}

export const createTestArticleTypes = (ticket: TicketById) => {
export const createTestArticleTypes = (
ticket: TicketById,
app: AppName = 'mobile',
) => {
initializeStore()
return createArticleTypes(ticket, 'mobile')
return createArticleTypes(ticket, app)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/

import type { TicketArticleActionPlugin, TicketArticleType } from './types'

const actionPlugin: TicketArticleActionPlugin = {
order: 100,

addTypes() {
const type: TicketArticleType = {
apps: ['mobile'],
value: 'phone',
label: __('Phone'),
icon: {
mobile: 'mobile-phone',
},
view: {
agent: ['change'],
},
attributes: ['attachments'],
internal: false,
}
return [type]
},
}

export default actionPlugin
8 changes: 8 additions & 0 deletions app/frontend/tests/support/mock-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/

import { mockPermissions } from './mock-permissions'

// If we change handling, we can improve it here in one function
export const setupView = (view: 'agent' | 'customer') => {
mockPermissions([`ticket.${view}`])
}
1 change: 1 addition & 0 deletions i18n/zammad.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7958,6 +7958,7 @@ msgid "Personal overview order was reset."
msgstr ""

#: app/assets/javascripts/app/controllers/cti.coffee
#: app/frontend/shared/entities/ticket-article/action/plugins/phone.ts
#: db/seeds/object_manager_attributes.rb
msgid "Phone"
msgstr ""
Expand Down
Binary file added spec/fixtures/files/image/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 64 additions & 15 deletions spec/system/apps/mobile/tickets/ticket_create_article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ def wait_for_ticket_edit()
wait_for_gql('apps/mobile/pages/ticket/graphql/mutations/update.graphql')
end

def save_article()
find_button('Done').click
find_button('Save ticket').click

wait_for_ticket_edit
end

def open_article_dialog()
visit "/tickets/#{ticket.id}"
find_button('Add reply').click
end

context 'when creating a new article as an agent', authenticated_as: :agent do
it 'creates an internal note (default)' do
visit "/tickets/#{ticket.id}"
find_button('Add reply').click
open_article_dialog

expect(find_select('Article Type', visible: :all)).to have_selected_option('Note')
expect(find_select('Visibility', visible: :all)).to have_selected_option('Internal')
Expand All @@ -25,10 +36,7 @@ def wait_for_ticket_edit()
expect(text).to have_text_value('', exact: true)
text.type('This is a note')

find_button('Done').click
find_button('Save ticket').click

wait_for_ticket_edit
save_article

expect(Ticket::Article.last).to have_attributes(
type_id: Ticket::Article::Type.lookup(name: 'note').id,
Expand All @@ -39,19 +47,15 @@ def wait_for_ticket_edit()
end

it 'creates a public note' do
visit "/tickets/#{ticket.id}"
find_button('Add reply').click
open_article_dialog

find_select('Visibility', visible: :all).select_option('Public')

text = find_editor('Text')
expect(text).to have_text_value('', exact: true)
text.type('This is a note!')

find_button('Done').click
find_button('Save ticket').click

wait_for_ticket_edit
save_article

expect(Ticket::Article.last).to have_attributes(
type_id: Ticket::Article::Type.lookup(name: 'note').id,
Expand Down Expand Up @@ -113,9 +117,7 @@ def wait_for_ticket_edit()
end

it 'changes ticket data together with the article' do
visit "/tickets/#{ticket.id}"

find_button('Add reply').click
open_article_dialog

find_editor('Text').type('This is a note!')

Expand All @@ -137,6 +139,53 @@ def wait_for_ticket_edit()
)
end

context 'when creating a phone article' do
it 'creates a phone article' do
open_article_dialog

find_select('Article Type', visible: :all).select_option('Phone')

text = find_editor('Text')
expect(text).to have_text_value('', exact: true)
text.type('This is a note!')

save_article

expect(Ticket::Article.last).to have_attributes(
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
internal: false,
body: '<p>This is a note!</p>',
)
end

it 'creates a phone article with attachments' do
open_article_dialog

find_select('Article Type', visible: :all).select_option('Phone')

text = find_editor('Text')
expect(text).to have_text_value('', exact: true)
text.type('This is a note!')

find_field('attachments', visible: :all).attach_file('spec/fixtures/files/image/small.png')

# need to wait until the file is uploaded
expect(page).to have_text('small.png', wait: 60)

save_article

expect(Store.last.filename).to eq('small.png')
expect(Ticket::Article.last).to have_attributes(
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
internal: false,
body: '<p>This is a note!</p>',
attachments: [
Store.last
]
)
end
end

# TODO: test security settings
end
end

0 comments on commit 60409bd

Please sign in to comment.