-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [M3-7532] - Payment Method Row Storybook v7 Story (#9958)
* props and export cleanup * add tests, start story * starting story * stories for storybook * update comments * Added changeset: Payment Method Row V7 story migration * address feedback * update key * feedback
- Loading branch information
1 parent
d1e24e8
commit 5623a50
Showing
12 changed files
with
163 additions
and
158 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9958-tech-stories-1701721635562.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Payment Method Row V7 story migration ([#9958](https://github.com/linode/manager/pull/9958)) |
46 changes: 46 additions & 0 deletions
46
packages/manager/src/components/PaymentMethodRow/DeletePaymentMethodDialog.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { DeletePaymentMethodDialog } from './DeletePaymentMethodDialog'; | ||
|
||
const props = { | ||
error: 'some error', | ||
loading: false, | ||
onClose: vi.fn(), | ||
onDelete: vi.fn(), | ||
open: true, | ||
paymentMethod: undefined, | ||
}; | ||
|
||
describe('Delete Payment Method Dialog', () => { | ||
it('renders the delete payment method dialog', () => { | ||
const screen = renderWithTheme(<DeletePaymentMethodDialog {...props} />); | ||
|
||
const headerText = screen.getByText('Delete Payment Method'); | ||
expect(headerText).toBeVisible(); | ||
|
||
const deleteText = screen.getByText( | ||
'Are you sure you want to delete this payment method?' | ||
); | ||
expect(deleteText).toBeVisible(); | ||
|
||
const buttons = screen.getAllByRole('button'); | ||
expect(buttons?.length).toBe(3); | ||
}); | ||
|
||
it('calls the corresponding functions when buttons are clicked', () => { | ||
const screen = renderWithTheme(<DeletePaymentMethodDialog {...props} />); | ||
|
||
const deleteButton = screen.getByText('Delete'); | ||
expect(deleteButton).toBeVisible(); | ||
fireEvent.click(deleteButton); | ||
expect(props.onDelete).toHaveBeenCalled(); | ||
|
||
const cancelButton = screen.getByText('Cancel'); | ||
expect(cancelButton).toBeVisible(); | ||
fireEvent.click(cancelButton); | ||
expect(props.onClose).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 0 additions & 130 deletions
130
packages/manager/src/components/PaymentMethodRow/PaymentMethodRow.stories.mdx
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
packages/manager/src/components/PaymentMethodRow/PaymentMethodRow.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { CardType } from '@linode/api-v4'; | ||
import { action } from '@storybook/addon-actions'; | ||
import React from 'react'; | ||
|
||
import { paymentMethodFactory } from 'src/factories'; | ||
|
||
import { PaymentMethodRow } from './PaymentMethodRow'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
type Story = StoryObj<typeof PaymentMethodRow>; | ||
|
||
const onDelete = action('onDelete'); | ||
|
||
const supportedCreditCards: (CardType | undefined)[] = [ | ||
'Visa', | ||
'MasterCard', | ||
'American Express', | ||
'Discover', | ||
'JCB', | ||
undefined, | ||
]; | ||
|
||
const CreditCardExamples = () => { | ||
const paymentMethods = supportedCreditCards.map((creditCard) => ( | ||
<PaymentMethodRow | ||
paymentMethod={paymentMethodFactory.build({ | ||
data: { | ||
card_type: creditCard, | ||
}, | ||
type: 'credit_card', | ||
})} | ||
key={creditCard ?? 'undefined-credit-card'} | ||
onDelete={onDelete} | ||
/> | ||
)); | ||
|
||
return <>{paymentMethods}</>; | ||
}; | ||
|
||
export const CreditCards: Story = { | ||
render: () => <CreditCardExamples />, | ||
}; | ||
|
||
export const GooglePay: Story = { | ||
render: (args) => <PaymentMethodRow {...args} />, | ||
}; | ||
|
||
export const PayPal: Story = { | ||
render: (args) => ( | ||
<PaymentMethodRow | ||
{...args} | ||
paymentMethod={paymentMethodFactory.build({ | ||
data: { | ||
email: '[email protected]', | ||
paypal_id: 'ABCDEFG123', | ||
}, | ||
type: 'paypal', | ||
})} | ||
/> | ||
), | ||
}; | ||
|
||
const meta: Meta<typeof PaymentMethodRow> = { | ||
args: { | ||
onDelete, | ||
paymentMethod: paymentMethodFactory.build({ | ||
data: { | ||
card_type: 'Visa', | ||
}, | ||
type: 'google_pay', | ||
}), | ||
}, | ||
component: PaymentMethodRow, | ||
title: 'Components/Payment Method Row', | ||
}; | ||
|
||
export default meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.