Skip to content

Commit 7b3e37b

Browse files
committed
fixed test cases
1 parent a79e099 commit 7b3e37b

File tree

11 files changed

+70
-35
lines changed

11 files changed

+70
-35
lines changed

src/components/floweditor/FlowEditor.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ import * as Notification from 'common/notification';
2929

3030
window.location = { assign: vi.fn() } as any;
3131

32+
beforeEach(() => {
33+
Object.defineProperty(window, 'location', {
34+
writable: true,
35+
value: { reload: vi.fn() },
36+
});
37+
});
38+
3239
vi.mock('react-router', async () => {
3340
return {
3441
...(await vi.importActual<any>('react-router')),
@@ -263,7 +270,7 @@ test('reset flow counts', async () => {
263270
fireEvent.click(getByTestId('ok-button'));
264271

265272
await waitFor(() => {
266-
// need to have an assertion after the query ran
273+
expect(window.location.reload).toHaveBeenCalled();
267274
});
268275
});
269276

src/containers/Organization/Onboarding/Form.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ test('it should submit the form', async () => {
234234
await waitFor(() => {
235235
expect(getByText('Success!')).toBeInTheDocument();
236236
});
237-
});
237+
}, 1500);
238238

239239
test('it should disgree and send an email', async () => {
240240
const { getByTestId, getAllByRole, getAllByTestId } = render(renderForm);

src/containers/SettingList/Billing/Billing.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ const mockStripe = () => ({
5555
};
5656
}),
5757
confirmCardPayment: vi.fn(),
58-
confirmCardSetup: vi.fn(),
58+
confirmCardSetup: vi.fn((props) => {
59+
return Promise.resolve({
60+
error: null,
61+
setupIntent: { status: 'succeeded' },
62+
});
63+
}),
5964
paymentRequest: vi.fn(),
6065
_registerWrapper: vi.fn(),
6166
});

src/containers/SettingList/Providers/Providers.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ describe('update credentials', () => {
182182
expect(screen.getByText('Token')).toBeInTheDocument();
183183
});
184184

185+
await waitFor(() => {
186+
expect(screen.getByText('Product ID')).toBeInTheDocument();
187+
});
188+
185189
const inputs = screen.getAllByRole('textbox');
186190

187191
fireEvent.change(inputs[0], { target: { value: 'token2' } });
@@ -225,6 +229,10 @@ describe('update credentials', () => {
225229
expect(screen.getByText('Token')).toBeInTheDocument();
226230
});
227231

232+
await waitFor(() => {
233+
expect(screen.getByText('Product ID')).toBeInTheDocument();
234+
});
235+
228236
const inputs = screen.getAllByRole('textbox');
229237

230238
fireEvent.change(inputs[0], { target: { value: 'token2' } });

src/containers/SpeedSend/SpeedSend.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('test creating a speed send', () => {
182182
await waitFor(() => {
183183
expect(screen.getByTestId('translation')).toBeInTheDocument();
184184
});
185-
});
185+
}, 1500);
186186

187187
test('it should display warning message', async () => {
188188
render(addSpeedSendContainer);

src/containers/WaGroups/WaPolls/WaPollsList/WaPollsList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('it navigates to create a copy', async () => {
7676
fireEvent.click(screen.getAllByTestId('duplicate-icon')[0]);
7777

7878
await waitFor(() => {
79-
expect(screen.getByText('Copy Poll')).toBeInTheDocument();
79+
expect(mockedUsedNavigate).toHaveBeenCalled();
8080
});
8181
});
8282

src/mocks/Organization.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,14 @@ export const createMaytapiCredentialsMock = (error: boolean = false) => ({
965965
keys: '{}',
966966
secrets: '{"token":"token","product_id":"product_id"}',
967967
},
968-
errors: error ? new Error('Something went wrong') : null,
968+
errors: error
969+
? [
970+
{
971+
message: 'Something went wrong',
972+
key: 0,
973+
},
974+
]
975+
: null,
969976
},
970977
},
971978
},
@@ -1043,7 +1050,14 @@ export const updateMaytapiCredentials = (error: boolean = false) => ({
10431050
keys: '{}',
10441051
secrets: '{"token":"token2","product_id":"product_id2"}',
10451052
},
1046-
errors: error ? new Error('Something went wrong') : null,
1053+
errors: error
1054+
? [
1055+
{
1056+
message: 'Something went wrong',
1057+
key: 0,
1058+
},
1059+
]
1060+
: null,
10471061
},
10481062
},
10491063
},

src/routes/AuthenticatedRoute/AuthenticatedRoute.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { vi } from 'vitest';
66

77
import { getOrganizationBSP, walletBalanceQuery, walletBalanceSubscription } from 'mocks/Organization';
88
import { setUserSession } from 'services/AuthService';
9-
import { CONVERSATION_MOCKS } from 'mocks/Chat';
9+
import { CONVERSATION_MOCKS, markAsReadMock } from 'mocks/Chat';
1010
import { Loading } from 'components/UI/Layout/Loading/Loading';
1111
import AuthenticatedRoute from './AuthenticatedRoute';
1212
import { getNotificationCountQuery } from 'mocks/Notifications';
@@ -19,6 +19,7 @@ const mocks = [
1919
...CONVERSATION_MOCKS,
2020
getOrganizationBSP,
2121
getNotificationCountQuery,
22+
markAsReadMock('2'),
2223
];
2324
window.HTMLElement.prototype.scrollIntoView = function () {};
2425
describe('<AuthenticatedRoute />', () => {

src/routes/AuthenticatedRoute/AuthenticatedRoute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const AuthenticatedRoute = () => {
200200
);
201201

202202
let userRole: any[] = [];
203-
let route = routeStaff;
203+
let route;
204204

205205
if (getUserRole()) {
206206
userRole = getUserRole();

src/setupTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TextEncoder, TextDecoder } from 'util';
44
import '@testing-library/jest-dom/vitest';
55

66
import { cleanup } from '@testing-library/react';
7-
import { afterEach } from 'node:test';
7+
import { afterEach } from 'vitest';
88

99
// runs a cleanup after each test case (e.g. clearing jsdom)
1010
afterEach(() => {

0 commit comments

Comments
 (0)