Skip to content

Commit

Permalink
users: use generic destinations for user contact method list component (
Browse files Browse the repository at this point in the history
#3684)

* add user CM list dest component

* [WIP] add component tests for user CM list dest

* add component tests for user CM list

* remove console log

* unify into one function

* remove non-current user test

* remove hard coded dest usage

* fix issue where hint url not displaying for mult field dests

* combine test assertions

* remove repeated assertions

* update comment to trigger github action

* remove lines to meet pr size limit

* remove function

* fix CM title label

* rename variable

* use destType.name

* update story text

---------

Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com>
  • Loading branch information
tony-tvu and mastercactapus authored Feb 20, 2024
1 parent 9bd24f4 commit e7035d9
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 4 deletions.
2 changes: 1 addition & 1 deletion graphql2/graphqlapp/contactmethod.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (a *ContactMethod) Dest(ctx context.Context, obj *contactmethod.ContactMeth
return &graphql2.Destination{
Type: destSlackDM,
Values: []graphql2.FieldValuePair{
{FieldID: fieldSlackUserID, Value: obj.Value, Label: a.FormatDestFunc(ctx, notification.DestTypeSlackChannel, obj.Value)},
{FieldID: fieldSlackUserID, Value: obj.Value, Label: a.FormatDestFunc(ctx, notification.ScannableDestType{CM: obj.Type}.DestType(), obj.Value)},
},
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/storybook/defaultDestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export const destTypes: DestinationTypeInfo[] = [
fieldID: 'third-field',
labelSingular: 'Third Item',
labelPlural: 'Third Items',
hint: '',
hintURL: '',
hint: 'docs',
hintURL: '/docs',
placeholderText: 'slack user ID',
prefix: '',
inputType: 'string',
Expand Down
182 changes: 182 additions & 0 deletions web/src/app/users/UserContactMethodListDest.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import React from 'react'
import type { Meta, StoryObj } from '@storybook/react'
import UserContactMethodListDest from './UserContactMethodListDest'
import { expect, within, userEvent, screen } from '@storybook/test'
import { handleDefaultConfig, handleExpFlags } from '../storybook/graphql'
import { HttpResponse, graphql } from 'msw'

const meta = {
title: 'users/UserContactMethodListDest',
component: UserContactMethodListDest,
tags: ['autodocs'],
parameters: {
msw: {
handlers: [
handleDefaultConfig,
handleExpFlags('dest-types'),
graphql.query('cmList', ({ variables: vars }) => {
return HttpResponse.json({
data:
vars.id === '00000000-0000-0000-0000-000000000000'
? {
user: {
id: '00000000-0000-0000-0000-000000000000',
contactMethods: [
{
id: '12345',
name: 'Josiah',
dest: {
type: 'single-field',
values: [
{
fieldID: 'phone-number',
value: '+15555555555',
label: '+1 555-555-5555',
},
],
},
disabled: false,
pending: false,
},
],
},
}
: {
user: {
id: '00000000-0000-0000-0000-000000000001',
contactMethods: [
{
id: '67890',
name: 'triple contact method',
dest: {
type: 'triple-field',
values: [
{
fieldID: 'first-field',
value: '+15555555555',
label: '+1 555-555-5555',
},
{
fieldID: 'second-field',
value: 'test_user@target.com',
label: 'test_user@target.com',
},
{
fieldID: 'third-field',
value: 'U03SM0U8TPE',
label: '@TestUser',
},
],
},
disabled: false,
pending: false,
},
{
id: '1111',
name: 'single field CM',
dest: {
type: 'single-field',
values: [
{
fieldID: 'phone-number',
value: '+15555555556',
label: '+1 555-555-5556',
},
],
},
disabled: false,
pending: false,
},
],
},
},
})
}),
],
},
},
render: function Component(args) {
return <UserContactMethodListDest {...args} />
},
} satisfies Meta<typeof UserContactMethodListDest>

export default meta
type Story = StoryObj<typeof meta>

export const SingleContactMethod: Story = {
args: {
userID: '00000000-0000-0000-0000-000000000000',
readOnly: false,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)

// ensure correct info is displayed for single-field CM
await expect(
await canvas.findByText('Josiah (Single Field Destination Type)'),
).toBeVisible()
await expect(await canvas.findByText('+1 555-555-5555')).toBeVisible()
// ensure CM is editable
await expect(
await canvas.queryByTestId('MoreHorizIcon'),
).toBeInTheDocument()
// ensure all edit options are available
await userEvent.click(await canvas.findByTestId('MoreHorizIcon'))
await expect(await screen.findByText('Edit')).toHaveAttribute(
'role',
'menuitem',
)
await expect(await screen.findByText('Delete')).toHaveAttribute(
'role',
'menuitem',
)
await expect(await screen.findByText('Send Test')).toHaveAttribute(
'role',
'menuitem',
)
},
}

export const MultiContactMethods: Story = {
args: {
userID: '00000000-0000-0000-0000-000000000001',
readOnly: false,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)

// ensure correct info is displayed for single field CM
await expect(
await canvas.findByText(
'single field CM (Single Field Destination Type)',
),
).toBeVisible()
// ensure correct info is displayed for triple-field CM
await expect(
await canvas.findByText(
'triple contact method (Multi Field Destination Type)',
),
).toBeVisible()
await expect(await canvas.findByText('+1 555-555-5556')).toBeVisible()
await expect(await canvas.findByText('test_user@target.com')).toBeVisible()
// ensure has link when hint url exists
await expect(canvas.getByText('docs')).toHaveAttribute('href', '/docs')
// ensure all edit icons exists
await expect(await canvas.findAllByTestId('MoreHorizIcon')).toHaveLength(2)
},
}

export const SingleReadOnlyContactMethods: Story = {
args: {
userID: '00000000-0000-0000-0000-000000000000',
readOnly: true,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)

// ensure no edit icons exist for read-only CM
await expect(
await canvas.queryByTestId('MoreHorizIcon'),
).not.toBeInTheDocument()
},
}
Loading

0 comments on commit e7035d9

Please sign in to comment.