Skip to content

Commit cf942f2

Browse files
committed
Revert "[Cases] Fix cases flaky tests (#176863)"
This reverts commit 0dd21e5.
1 parent 250c427 commit cf942f2

36 files changed

+398
-578
lines changed

x-pack/plugins/cases/public/common/apm/use_cases_transactions.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ describe('cases transactions', () => {
8080
);
8181
expect(mockAddLabels).toHaveBeenCalledWith({ alert_count: 3 });
8282
});
83-
84-
it('should not start any transactions if the app ID is not defined', () => {
85-
const { result } = renderUseCreateCaseWithAttachmentsTransaction();
86-
87-
result.current.startTransaction();
88-
89-
expect(mockStartTransaction).not.toHaveBeenCalled();
90-
expect(mockAddLabels).not.toHaveBeenCalled();
91-
});
9283
});
9384

9485
describe('useAddAttachmentToExistingCaseTransaction', () => {
@@ -113,14 +104,5 @@ describe('cases transactions', () => {
113104
);
114105
expect(mockAddLabels).toHaveBeenCalledWith({ alert_count: 3 });
115106
});
116-
117-
it('should not start any transactions if the app ID is not defined', () => {
118-
const { result } = renderUseAddAttachmentToExistingCaseTransaction();
119-
120-
result.current.startTransaction({ attachments: bulkAttachments });
121-
122-
expect(mockStartTransaction).not.toHaveBeenCalled();
123-
expect(mockAddLabels).not.toHaveBeenCalled();
124-
});
125107
});
126108
});

x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const BULK_ADD_ATTACHMENT_TO_NEW_CASE = 'bulkAddAttachmentsToNewCase' as const;
1717
const ADD_ATTACHMENT_TO_EXISTING_CASE = 'addAttachmentToExistingCase' as const;
1818
const BULK_ADD_ATTACHMENT_TO_EXISTING_CASE = 'bulkAddAttachmentsToExistingCase' as const;
1919

20-
export type StartCreateCaseWithAttachmentsTransaction = (param?: {
21-
appId?: string;
20+
export type StartCreateCaseWithAttachmentsTransaction = (param: {
21+
appId: string;
2222
attachments?: CaseAttachmentsWithoutOwner;
2323
}) => Transaction | undefined;
2424

@@ -28,17 +28,11 @@ export const useCreateCaseWithAttachmentsTransaction = () => {
2828

2929
const startCreateCaseWithAttachmentsTransaction =
3030
useCallback<StartCreateCaseWithAttachmentsTransaction>(
31-
({ appId, attachments } = {}) => {
32-
if (!appId) {
33-
return;
34-
}
35-
31+
({ appId, attachments }) => {
3632
if (!attachments) {
3733
return startTransaction(`Cases [${appId}] ${CREATE_CASE}`);
3834
}
39-
4035
const alertCount = getAlertCount(attachments);
41-
4236
if (alertCount <= 1) {
4337
return startTransaction(`Cases [${appId}] ${ADD_ATTACHMENT_TO_NEW_CASE}`);
4438
}
@@ -54,7 +48,7 @@ export const useCreateCaseWithAttachmentsTransaction = () => {
5448
};
5549

5650
export type StartAddAttachmentToExistingCaseTransaction = (param: {
57-
appId?: string;
51+
appId: string;
5852
attachments: CaseAttachmentsWithoutOwner;
5953
}) => Transaction | undefined;
6054

@@ -65,20 +59,13 @@ export const useAddAttachmentToExistingCaseTransaction = () => {
6559
const startAddAttachmentToExistingCaseTransaction =
6660
useCallback<StartAddAttachmentToExistingCaseTransaction>(
6761
({ appId, attachments }) => {
68-
if (!appId) {
69-
return;
70-
}
71-
7262
const alertCount = getAlertCount(attachments);
73-
7463
if (alertCount <= 1) {
7564
return startTransaction(`Cases [${appId}] ${ADD_ATTACHMENT_TO_EXISTING_CASE}`);
7665
}
77-
7866
const transaction = startTransaction(
7967
`Cases [${appId}] ${BULK_ADD_ATTACHMENT_TO_EXISTING_CASE}`
8068
);
81-
8269
transaction?.addLabels({ alert_count: alertCount });
8370
return transaction;
8471
},

x-pack/plugins/cases/public/common/lib/kibana/__mocks__/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const useKibana = jest.fn().mockReturnValue({
2525
export const useHttp = jest.fn().mockReturnValue(createStartServicesMock().http);
2626
export const useTimeZone = jest.fn();
2727
export const useDateFormat = jest.fn();
28+
export const useBasePath = jest.fn(() => '/test/base/path');
2829
export const useToasts = jest
2930
.fn()
3031
.mockReturnValue(notificationServiceMock.createStartContract().toasts);

x-pack/plugins/cases/public/common/lib/kibana/hooks.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const useTimeZone = (): string => {
3030
return timeZone === 'Browser' ? moment.tz.guess() : timeZone;
3131
};
3232

33+
export const useBasePath = (): string => useKibana().services.http.basePath.get();
34+
3335
export const useToasts = (): StartServices['notifications']['toasts'] =>
3436
useKibana().services.notifications.toasts;
3537

@@ -114,12 +116,12 @@ export const useCurrentUser = (): AuthenticatedElasticUser | null => {
114116
* Returns a full URL to the provided page path by using
115117
* kibana's `getUrlForApp()`
116118
*/
117-
export const useAppUrl = (appId?: string) => {
119+
export const useAppUrl = (appId: string) => {
118120
const { getUrlForApp } = useKibana().services.application;
119121

120122
const getAppUrl = useCallback(
121123
(options?: { deepLinkId?: string; path?: string; absolute?: boolean }) =>
122-
getUrlForApp(appId ?? '', options),
124+
getUrlForApp(appId, options),
123125
[appId, getUrlForApp]
124126
);
125127
return { getAppUrl };
@@ -129,7 +131,7 @@ export const useAppUrl = (appId?: string) => {
129131
* Navigate to any app using kibana's `navigateToApp()`
130132
* or by url using `navigateToUrl()`
131133
*/
132-
export const useNavigateTo = (appId?: string) => {
134+
export const useNavigateTo = (appId: string) => {
133135
const { navigateToApp, navigateToUrl } = useKibana().services.application;
134136

135137
const navigateTo = useCallback(
@@ -142,7 +144,7 @@ export const useNavigateTo = (appId?: string) => {
142144
if (url) {
143145
navigateToUrl(url);
144146
} else {
145-
navigateToApp(appId ?? '', options);
147+
navigateToApp(appId, options);
146148
}
147149
},
148150
[appId, navigateToApp, navigateToUrl]
@@ -154,7 +156,7 @@ export const useNavigateTo = (appId?: string) => {
154156
* Returns navigateTo and getAppUrl navigation hooks
155157
*
156158
*/
157-
export const useNavigation = (appId?: string) => {
159+
export const useNavigation = (appId: string) => {
158160
const { navigateTo } = useNavigateTo(appId);
159161
const { getAppUrl } = useAppUrl(appId);
160162
return { navigateTo, getAppUrl };

x-pack/plugins/cases/public/common/lib/kibana/kibana_react.mock.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import React from 'react';
99
import { BehaviorSubject } from 'rxjs';
1010

1111
import type { PublicAppInfo } from '@kbn/core/public';
12-
import { AppStatus } from '@kbn/core/public';
1312
import type { RecursivePartial } from '@elastic/eui/src/components/common';
1413
import { coreMock } from '@kbn/core/public/mocks';
1514
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
@@ -53,21 +52,7 @@ export const createStartServicesMock = ({ license }: StartServiceArgs = {}): Sta
5352

5453
services.application.currentAppId$ = new BehaviorSubject<string>('testAppId');
5554
services.application.applications$ = new BehaviorSubject<Map<string, PublicAppInfo>>(
56-
new Map([
57-
[
58-
'testAppId',
59-
{
60-
id: 'testAppId',
61-
title: 'test-title',
62-
category: { id: 'test-label-id', label: 'Test' },
63-
status: AppStatus.accessible,
64-
visibleIn: ['globalSearch'],
65-
appRoute: `/app/some-id`,
66-
keywords: [],
67-
deepLinks: [],
68-
},
69-
],
70-
])
55+
new Map([['testAppId', { category: { label: 'Test' } } as unknown as PublicAppInfo]])
7156
);
7257

7358
services.triggersActionsUi.actionTypeRegistry.get = jest.fn().mockReturnValue({

x-pack/plugins/cases/public/common/mock/test_providers.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { ScopedFilesClient } from '@kbn/files-plugin/public';
1919
import { euiDarkVars } from '@kbn/ui-theme';
2020
import { I18nProvider } from '@kbn/i18n-react';
2121
import { createMockFilesClient } from '@kbn/shared-ux-file-mocks';
22-
import { QueryClient } from '@tanstack/react-query';
22+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2323

2424
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
2525
import { FilesContext } from '@kbn/shared-ux-file-context';
@@ -108,9 +108,10 @@ const TestProvidersComponent: React.FC<TestProviderProps> = ({
108108
permissions,
109109
getFilesClient,
110110
}}
111-
queryClient={queryClient}
112111
>
113-
<FilesContext client={createMockFilesClient()}>{children}</FilesContext>
112+
<QueryClientProvider client={queryClient}>
113+
<FilesContext client={createMockFilesClient()}>{children}</FilesContext>
114+
</QueryClientProvider>
114115
</CasesProvider>
115116
</MemoryRouter>
116117
</ThemeProvider>
@@ -190,9 +191,8 @@ export const createAppMockRenderer = ({
190191
releasePhase,
191192
getFilesClient,
192193
}}
193-
queryClient={queryClient}
194194
>
195-
{children}
195+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
196196
</CasesProvider>
197197
</MemoryRouter>
198198
</ThemeProvider>

x-pack/plugins/cases/public/common/use_cases_toast.test.tsx

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ import { alertComment, basicComment, mockCase } from '../containers/mock';
1414
import React from 'react';
1515
import userEvent from '@testing-library/user-event';
1616
import type { SupportedCaseAttachment } from '../types';
17-
import { getByTestId, queryByTestId, screen } from '@testing-library/react';
17+
import { getByTestId } from '@testing-library/react';
1818
import { OWNER_INFO } from '../../common/constants';
19-
import { useCasesContext } from '../components/cases_context/use_cases_context';
2019

2120
jest.mock('./lib/kibana');
22-
jest.mock('../components/cases_context/use_cases_context');
2321

2422
const useToastsMock = useToasts as jest.Mock;
2523
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
26-
const useCasesContextMock = useCasesContext as jest.Mock;
2724

2825
describe('Use cases toast hook', () => {
2926
const successMock = jest.fn();
@@ -69,8 +66,6 @@ describe('Use cases toast hook', () => {
6966
getUrlForApp,
7067
navigateToUrl,
7168
};
72-
73-
useCasesContextMock.mockReturnValue({ appId: 'testAppId' });
7469
});
7570

7671
describe('showSuccessAttach', () => {
@@ -152,7 +147,6 @@ describe('Use cases toast hook', () => {
152147
describe('Toast content', () => {
153148
let appMockRender: AppMockRenderer;
154149
const onViewCaseClick = jest.fn();
155-
156150
beforeEach(() => {
157151
appMockRender = createAppMockRenderer();
158152
onViewCaseClick.mockReset();
@@ -219,16 +213,9 @@ describe('Use cases toast hook', () => {
219213
const result = appMockRender.render(
220214
<CaseToastSuccessContent onViewCaseClick={onViewCaseClick} />
221215
);
222-
223216
userEvent.click(result.getByTestId('toaster-content-case-view-link'));
224217
expect(onViewCaseClick).toHaveBeenCalled();
225218
});
226-
227-
it('hides the view case link when onViewCaseClick is not defined', () => {
228-
appMockRender.render(<CaseToastSuccessContent />);
229-
230-
expect(screen.queryByTestId('toaster-content-case-view-link')).not.toBeInTheDocument();
231-
});
232219
});
233220

234221
describe('Toast navigation', () => {
@@ -280,31 +267,6 @@ describe('Use cases toast hook', () => {
280267
path: '/mock-id',
281268
});
282269
});
283-
284-
it('does not navigates to a case if the appId is not defined', () => {
285-
useCasesContextMock.mockReturnValue({ appId: undefined });
286-
287-
const { result } = renderHook(
288-
() => {
289-
return useCasesToast();
290-
},
291-
{ wrapper: TestProviders }
292-
);
293-
294-
result.current.showSuccessAttach({
295-
theCase: { ...mockCase, owner: 'in-valid' },
296-
title: 'Custom title',
297-
});
298-
299-
const mockParams = successMock.mock.calls[0][0];
300-
const el = document.createElement('div');
301-
mockParams.text(el);
302-
const button = queryByTestId(el, 'toaster-content-case-view-link');
303-
304-
expect(button).toBeNull();
305-
expect(getUrlForApp).not.toHaveBeenCalled();
306-
expect(navigateToUrl).not.toHaveBeenCalled();
307-
});
308270
});
309271
});
310272

x-pack/plugins/cases/public/common/use_cases_toast.tsx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,13 @@ export const useCasesToast = () => {
140140
? OWNER_INFO[theCase.owner].appId
141141
: appId;
142142

143-
const url =
144-
appIdToNavigateTo != null
145-
? getUrlForApp(appIdToNavigateTo, {
146-
deepLinkId: 'cases',
147-
path: generateCaseViewPath({ detailName: theCase.id }),
148-
})
149-
: null;
143+
const url = getUrlForApp(appIdToNavigateTo, {
144+
deepLinkId: 'cases',
145+
path: generateCaseViewPath({ detailName: theCase.id }),
146+
});
150147

151148
const onViewCaseClick = () => {
152-
if (url) {
153-
navigateToUrl(url);
154-
}
149+
navigateToUrl(url);
155150
};
156151

157152
const renderTitle = getToastTitle({ theCase, title, attachments });
@@ -162,10 +157,7 @@ export const useCasesToast = () => {
162157
iconType: 'check',
163158
title: toMountPoint(<Title>{renderTitle}</Title>),
164159
text: toMountPoint(
165-
<CaseToastSuccessContent
166-
content={renderContent}
167-
onViewCaseClick={url != null ? onViewCaseClick : undefined}
168-
/>
160+
<CaseToastSuccessContent content={renderContent} onViewCaseClick={onViewCaseClick} />
169161
),
170162
});
171163
},
@@ -194,7 +186,7 @@ export const CaseToastSuccessContent = ({
194186
onViewCaseClick,
195187
content,
196188
}: {
197-
onViewCaseClick?: () => void;
189+
onViewCaseClick: () => void;
198190
content?: string;
199191
}) => {
200192
return (
@@ -204,16 +196,14 @@ export const CaseToastSuccessContent = ({
204196
{content}
205197
</EuiTextStyled>
206198
) : null}
207-
{onViewCaseClick !== undefined ? (
208-
<EuiButtonEmpty
209-
size="xs"
210-
flush="left"
211-
onClick={onViewCaseClick}
212-
data-test-subj="toaster-content-case-view-link"
213-
>
214-
{VIEW_CASE}
215-
</EuiButtonEmpty>
216-
) : null}
199+
<EuiButtonEmpty
200+
size="xs"
201+
flush="left"
202+
onClick={onViewCaseClick}
203+
data-test-subj="toaster-content-case-view-link"
204+
>
205+
{VIEW_CASE}
206+
</EuiButtonEmpty>
217207
</>
218208
);
219209
};

x-pack/plugins/cases/public/components/add_comment/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const AddComment = React.memo(
7575
const [focusOnContext, setFocusOnContext] = useState(false);
7676
const { permissions, owner, appId } = useCasesContext();
7777
const { isLoading, mutate: createAttachments } = useCreateAttachments();
78-
const draftStorageKey = getMarkdownEditorStorageKey({ appId, caseId, commentId: id });
78+
const draftStorageKey = getMarkdownEditorStorageKey(appId, caseId, id);
7979

8080
const { form } = useForm<AddCommentFormSchema>({
8181
defaultValue: initialCommentValue,

x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_filter_config.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { LOCAL_STORAGE_KEYS } from '../../../../common/constants';
1414
import type { FilterConfig, FilterConfigState } from './types';
1515
import { useCustomFieldsFilterConfig } from './use_custom_fields_filter_config';
1616
import { useCasesContext } from '../../cases_context/use_cases_context';
17-
import { deflattenCustomFieldKey, getLocalStorageKey, isFlattenCustomField } from '../utils';
17+
import { deflattenCustomFieldKey, isFlattenCustomField } from '../utils';
1818

1919
const mergeSystemAndCustomFieldConfigs = ({
2020
systemFilterConfig,
@@ -52,7 +52,7 @@ const shouldBeActive = ({
5252
const useActiveByFilterKeyState = ({ filterOptions }: { filterOptions: FilterOptions }) => {
5353
const { appId } = useCasesContext();
5454
const [activeByFilterKey, setActiveByFilterKey] = useLocalStorage<FilterConfigState[]>(
55-
getLocalStorageKey(LOCAL_STORAGE_KEYS.casesTableFiltersConfig, appId),
55+
`${appId}.${LOCAL_STORAGE_KEYS.casesTableFiltersConfig}`,
5656
[]
5757
);
5858

0 commit comments

Comments
 (0)