Skip to content

Commit

Permalink
remove non-current user test
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-tvu committed Feb 14, 2024
1 parent 196766c commit 02f6659
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 144 deletions.
218 changes: 75 additions & 143 deletions web/src/app/users/UserContactMethodListDest.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,130 +5,6 @@ import { expect, within, userEvent, screen } from '@storybook/test'
import { handleDefaultConfig, handleExpFlags } from '../storybook/graphql'
import { HttpResponse, graphql } from 'msw'

interface UserCMResponse {
user: {
id: string
contactMethods: {
id: string
name: string
dest: {
type: string
values: {
fieldID: string
value: string
label: string
}[]
}
disabled: boolean
pending: boolean
}[]
}
}

function getUserCMData(userID: string): UserCMResponse | undefined {
if (userID === '00000000-0000-0000-0000-000000000000') {
return {
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,
},
],
},
}
}
if (userID === '00000000-0000-0000-0000-000000000001') {
return {
user: {
id: '00000000-0000-0000-0000-000000000001',
contactMethods: [
{
id: '12345',
name: 'non_current_user',
dest: {
type: 'single-field',
values: [
{
fieldID: 'phone-number',
value: '+15555555555',
label: '+1 555-555-5555',
},
],
},
disabled: false,
pending: false,
},
],
},
}
}
if (userID === '00000000-0000-0000-0000-000000000002') {
return {
user: {
id: '00000000-0000-0000-0000-000000000002',
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: 'my_webhook',
dest: {
type: 'webhook-field',
values: [
{
fieldID: 'webhook-url',
value: 'https://target.com',
label: 'https://target.com',
},
],
},
disabled: false,
pending: false,
},
],
},
}
}
}

const meta = {
title: 'users/UserContactMethodListDest',
component: UserContactMethodListDest,
Expand All @@ -140,7 +16,80 @@ const meta = {
handleExpFlags('dest-types'),
graphql.query('cmList', ({ variables: vars }) => {
return HttpResponse.json({
data: getUserCMData(vars.id),
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: 'my_webhook',
dest: {
type: 'webhook-field',
values: [
{
fieldID: 'webhook-url',
value: 'https://target.com',
label: 'https://target.com',
},
],
},
disabled: false,
pending: false,
},
],
},
},
})
}),
],
Expand Down Expand Up @@ -190,7 +139,7 @@ export const SingleContactMethod: Story = {

export const MultiContactMethods: Story = {
args: {
userID: '00000000-0000-0000-0000-000000000002',
userID: '00000000-0000-0000-0000-000000000001',
readOnly: false,
},
play: async ({ canvasElement }) => {
Expand Down Expand Up @@ -236,20 +185,3 @@ export const SingleReadOnlyContactMethods: Story = {
).not.toBeInTheDocument()
},
}

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

// ensure non-current user cannot send test to user CM
await userEvent.click(await canvas.findByTestId('MoreHorizIcon'))
await expect(await screen.findByText('Send Test')).toHaveAttribute(
'aria-disabled',
'true',
)
},
}
2 changes: 1 addition & 1 deletion web/src/app/users/UserContactMethodListDest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { GenericError, ObjectNotFound } from '../error-pages'
import SendTestDialog from './SendTestDialog'
import AppLink from '../util/AppLink'
import { styles as globalStyles } from '../styles/materialStyles'
import { FieldValuePair, UserContactMethod } from '../../schema'
import { UserContactMethod } from '../../schema'
import UserContactMethodCreateDialog from './UserContactMethodCreateDialog'
import { useSessionInfo } from '../util/RequireConfig'

Expand Down

0 comments on commit 02f6659

Please sign in to comment.