Skip to content

Commit 58d7065

Browse files
fix tests
1 parent 006fb97 commit 58d7065

File tree

5 files changed

+81
-56
lines changed

5 files changed

+81
-56
lines changed

packages/manager/src/components/PaymentMethodRow/PaymentMethodRow.test.tsx

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,14 @@ describe('Payment Method Row', () => {
258258
).not.toEqual('true');
259259
});
260260

261-
it('Opens "Make a Payment" drawer with the payment method preselected if "Make a Payment" action is clicked', async () => {
261+
it.only('Opens "Make a Payment" drawer with the payment method preselected if "Make a Payment" action is clicked', async () => {
262+
queryMocks.userPermissions.mockReturnValue({
263+
data: {
264+
make_billing_payment: true,
265+
set_default_payment_method: false,
266+
delete_payment_method: false,
267+
},
268+
});
262269
const paymentMethods = [
263270
paymentMethodFactory.build({
264271
type: 'paypal',
@@ -274,23 +281,22 @@ describe('Payment Method Row', () => {
274281
* The <BillingSummary /> component is responsible for rendering the "Make a Payment" drawer,
275282
* and is required for this test. We may want to consider decoupling these components in the future.
276283
*/
277-
const { getByLabelText, getByTestId, getByText, getAllByTestId } =
278-
renderWithTheme(
279-
<PayPalScriptProvider options={{ clientId: PAYPAL_CLIENT_ID }}>
280-
<BillingSummary
281-
balance={0}
282-
balanceUninvoiced={0}
283-
paymentMethods={paymentMethods}
284-
/>
285-
<PaymentMethodRow
286-
onDelete={vi.fn()}
287-
paymentMethod={paymentMethods[1]}
288-
/>
289-
</PayPalScriptProvider>,
290-
{
291-
initialRoute: '/account/billing',
292-
}
293-
);
284+
const { getByLabelText, getByText, router } = renderWithTheme(
285+
<PayPalScriptProvider options={{ clientId: PAYPAL_CLIENT_ID }}>
286+
<BillingSummary
287+
balance={0}
288+
balanceUninvoiced={0}
289+
paymentMethods={paymentMethods}
290+
/>
291+
<PaymentMethodRow
292+
onDelete={vi.fn()}
293+
paymentMethod={paymentMethods[1]}
294+
/>
295+
</PayPalScriptProvider>,
296+
{
297+
initialRoute: '/billing',
298+
}
299+
);
294300

295301
const actionMenu = getByLabelText('Action menu for card ending in 1881');
296302
await userEvent.click(actionMenu);
@@ -300,21 +306,10 @@ describe('Payment Method Row', () => {
300306
await userEvent.click(makePaymentButton);
301307

302308
await waitFor(() => {
303-
expect(getByTestId('drawer')).toBeVisible();
309+
expect(router.state.location.pathname).toBe('/billing');
310+
expect(router.state.location.searchStr).toBe(
311+
'?action=make-payment&paymentMethodId=2'
312+
);
304313
});
305-
306-
expect(getByTestId('drawer-title')).toHaveTextContent('Make a Payment');
307-
308-
const expectedSelectionCard = getAllByTestId('selection-card')[1];
309-
310-
expect(expectedSelectionCard).toBeVisible();
311-
expect(expectedSelectionCard).toHaveTextContent('1881');
312-
expect(expectedSelectionCard).toHaveAttribute(
313-
'data-qa-selection-card-checked',
314-
'true'
315-
);
316-
317-
// In the future, if we have access to the router's state,
318-
// we can assert the search params.
319314
});
320315
});

packages/manager/src/components/TypeToConfirm/TypeToConfirm.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('TypeToConfirm Component', () => {
7272
expect(
7373
queryByTestId('instructions-to-enable-or-disable')
7474
).toBeInTheDocument();
75-
expect(getByRole('link')).toHaveAttribute('href', '/profile/settings');
75+
expect(getByRole('link')).toHaveAttribute('href', '/profile/preferences');
7676
});
7777

7878
it('Should not display instructions when toggled to hidden', () => {

packages/manager/src/features/Billing/BillingDetail.test.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
import * as React from 'react';
22

3+
import { accountFactory } from 'src/factories';
34
import { renderWithTheme } from 'src/utilities/testHelpers';
45

56
import { BillingDetail } from './BillingDetail';
67

7-
describe('Account Landing', () => {
8+
const queryMocks = vi.hoisted(() => ({
9+
userPermissions: vi.fn(() => ({
10+
data: {
11+
list_billing_payments: true,
12+
},
13+
})),
14+
useAccount: vi.fn().mockReturnValue({}),
15+
}));
16+
17+
vi.mock('@linode/queries', async () => {
18+
const actual = await vi.importActual('@linode/queries');
19+
return {
20+
...actual,
21+
useAccount: queryMocks.useAccount,
22+
};
23+
});
24+
25+
vi.mock('src/features/IAM/hooks/usePermissions', () => ({
26+
usePermissions: queryMocks.userPermissions,
27+
}));
28+
29+
describe('Billing Detail', () => {
830
it('should render', async () => {
31+
const account = accountFactory.build({});
32+
33+
queryMocks.useAccount.mockReturnValue({
34+
data: account,
35+
isLoading: false,
36+
error: null,
37+
});
38+
939
const { findByTestId, findByText } = renderWithTheme(<BillingDetail />, {
10-
initialRoute: '/account/billing',
40+
initialRoute: '/billing',
1141
});
1242
await findByTestId('billing-detail');
1343
await findByText('Account Balance');

packages/manager/src/features/Billing/BillingPanels/BillingSummary/BillingSummary.test.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('BillingSummary', () => {
3939
<BillingSummary balance={0} balanceUninvoiced={5} paymentMethods={[]} />
4040
</PayPalScriptProvider>,
4141
{
42-
initialRoute: '/account/billing',
42+
initialRoute: '/billing',
4343
}
4444
);
4545
within(screen.getByTestId(accountBalanceText)).getByText(/no balance/i);
@@ -56,7 +56,7 @@ describe('BillingSummary', () => {
5656
/>
5757
</PayPalScriptProvider>,
5858
{
59-
initialRoute: '/account/billing',
59+
initialRoute: '/billing',
6060
}
6161
);
6262
within(screen.getByTestId(accountBalanceText)).getByText(/credit/i);
@@ -73,7 +73,7 @@ describe('BillingSummary', () => {
7373
/>
7474
</PayPalScriptProvider>,
7575
{
76-
initialRoute: '/account/billing',
76+
initialRoute: '/billing',
7777
}
7878
);
7979
within(screen.getByTestId(accountBalanceText)).getByText(/Balance/i);
@@ -86,7 +86,7 @@ describe('BillingSummary', () => {
8686
<BillingSummary balance={0} balanceUninvoiced={5} paymentMethods={[]} />
8787
</PayPalScriptProvider>,
8888
{
89-
initialRoute: '/account/billing',
89+
initialRoute: '/billing',
9090
}
9191
);
9292
expect(screen.queryByText('Promotions')).not.toBeInTheDocument();
@@ -119,7 +119,7 @@ describe('BillingSummary', () => {
119119
/>
120120
</PayPalScriptProvider>,
121121
{
122-
initialRoute: '/account/billing',
122+
initialRoute: '/billing',
123123
}
124124
);
125125
const getByTextWithMarkup = withMarkup(screen.getByText);
@@ -142,7 +142,7 @@ describe('BillingSummary', () => {
142142
promotions={promotions}
143143
/>,
144144
{
145-
initialRoute: '/account/billing',
145+
initialRoute: '/billing',
146146
}
147147
);
148148
expect(screen.queryByText('Applies to: All')).not.toBeInTheDocument();
@@ -155,27 +155,27 @@ describe('BillingSummary', () => {
155155
<BillingSummary balance={0} balanceUninvoiced={5} paymentMethods={[]} />
156156
</PayPalScriptProvider>,
157157
{
158-
initialRoute: '/account/billing',
158+
initialRoute: '/billing',
159159
}
160160
);
161161
within(screen.getByTestId('accrued-charges-value')).getByText('$5.00');
162162
});
163163

164164
it('opens "Make a Payment" drawer when "Make a payment." is clicked', async () => {
165-
const { getByTestId, getByText } = renderWithTheme(
165+
const { getByText, router } = renderWithTheme(
166166
<PayPalScriptProvider options={{ clientId: PAYPAL_CLIENT_ID }}>
167167
<BillingSummary balance={5} balanceUninvoiced={5} paymentMethods={[]} />
168168
</PayPalScriptProvider>,
169169
{
170-
initialRoute: '/account/billing',
170+
initialRoute: '/billing',
171171
}
172172
);
173173

174174
const paymentButton = getByText('Make a payment', { exact: false });
175175
await userEvent.click(paymentButton);
176176

177-
expect(getByTestId('drawer')).toBeVisible();
178-
expect(getByTestId('drawer-title').textContent).toEqual('Make a Payment');
177+
expect(router.state.location.pathname).toBe('/billing');
178+
expect(router.state.location.searchStr).toBe('?action=make-payment');
179179
});
180180

181181
it('does not display the "Add a promo code" button if user does not have create_promo_code permission', async () => {
@@ -184,7 +184,7 @@ describe('BillingSummary', () => {
184184
<BillingSummary balance={5} balanceUninvoiced={5} paymentMethods={[]} />
185185
</PayPalScriptProvider>,
186186
{
187-
initialRoute: '/account/billing',
187+
initialRoute: '/billing',
188188
}
189189
);
190190
expect(queryByText('Add a promo code')).not.toBeInTheDocument();
@@ -206,7 +206,7 @@ describe('BillingSummary', () => {
206206
/>
207207
</PayPalScriptProvider>,
208208
{
209-
initialRoute: '/account/billing',
209+
initialRoute: '/billing',
210210
}
211211
);
212212
expect(queryByText('Add a promo code')).toBeInTheDocument();

packages/manager/src/features/Billing/BillingPanels/PaymentInfoPanel/PaymentInformation.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Payment Info Panel', () => {
6868
<PaymentInformation {...props} loading={true} />
6969
</PayPalScriptProvider>,
7070
{
71-
initialRoute: '/account/billing',
71+
initialRoute: '/billing',
7272
}
7373
);
7474

@@ -81,7 +81,7 @@ describe('Payment Info Panel', () => {
8181
<PaymentInformation {...props} loading={false} />
8282
</PayPalScriptProvider>,
8383
{
84-
initialRoute: '/account/billing',
84+
initialRoute: '/billing',
8585
}
8686
);
8787

@@ -105,7 +105,7 @@ describe('Payment Info Panel', () => {
105105
<PaymentInformation {...props} />
106106
</PayPalScriptProvider>,
107107
{
108-
initialRoute: '/account/billing',
108+
initialRoute: '/billing',
109109
}
110110
);
111111

@@ -122,7 +122,7 @@ describe('Payment Info Panel', () => {
122122
<PaymentInformation {...props} />
123123
</PayPalScriptProvider>,
124124
{
125-
initialRoute: '/account/billing',
125+
initialRoute: '/billing',
126126
}
127127
);
128128

@@ -139,7 +139,7 @@ describe('Payment Info Panel', () => {
139139
<PaymentInformation {...props} isAkamaiCustomer={true} />
140140
</PayPalScriptProvider>,
141141
{
142-
initialRoute: '/account/billing',
142+
initialRoute: '/billing',
143143
}
144144
);
145145

@@ -168,7 +168,7 @@ describe('Payment Info Panel', () => {
168168
/>
169169
</PayPalScriptProvider>,
170170
{
171-
initialRoute: '/account/billing',
171+
initialRoute: '/billing',
172172
}
173173
);
174174

@@ -195,7 +195,7 @@ describe('Payment Info Panel', () => {
195195
<PaymentInformation {...props} />
196196
</PayPalScriptProvider>,
197197
{
198-
initialRoute: '/account/billing',
198+
initialRoute: '/billing',
199199
}
200200
);
201201

0 commit comments

Comments
 (0)