-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cases] Fix flaky tests in the CaseViewPage
component
#172940
Changes from 1 commit
29f9c5f
e0c1198
5cf170c
02b437b
d484379
a53cc81
b0840d2
d49e5de
da0d8ad
35745f8
e6a3735
46e537d
3ce63b4
327d09d
fb92d1f
20369ab
fa64d23
44a611d
48537b8
63f5870
f47d60f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
*/ | ||
|
||
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; | ||
import React, { useCallback, useEffect, useMemo, useRef } from 'react'; | ||
import React, { useCallback, useEffect, useRef } from 'react'; | ||
import { CASE_VIEW_PAGE_TABS } from '../../../common/types'; | ||
import { useUrlParams } from '../../common/navigation'; | ||
import { useCasesContext } from '../cases_context/use_cases_context'; | ||
|
@@ -23,6 +23,14 @@ import type { CaseViewPageProps } from './types'; | |
import { useRefreshCaseViewPage } from './use_on_refresh_case_view_page'; | ||
import { useOnUpdateField } from './use_on_update_field'; | ||
|
||
const getActiveTabId = (tabId?: string) => { | ||
if (tabId && Object.values(CASE_VIEW_PAGE_TABS).includes(tabId as CASE_VIEW_PAGE_TABS)) { | ||
return tabId; | ||
} | ||
|
||
return CASE_VIEW_PAGE_TABS.ACTIVITY; | ||
}; | ||
|
||
export const CaseViewPage = React.memo<CaseViewPageProps>( | ||
({ | ||
caseData, | ||
|
@@ -39,12 +47,7 @@ export const CaseViewPage = React.memo<CaseViewPageProps>( | |
|
||
useCasesTitleBreadcrumbs(caseData.title); | ||
|
||
const activeTabId = useMemo(() => { | ||
if (urlParams.tabId && Object.values(CASE_VIEW_PAGE_TABS).includes(urlParams.tabId)) { | ||
return urlParams.tabId; | ||
} | ||
return CASE_VIEW_PAGE_TABS.ACTIVITY; | ||
}, [urlParams.tabId]); | ||
const activeTabId = getActiveTabId(urlParams?.tabId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I removed some tests the other tests started failing. There was an issue with mocking and memorization that affected the tests. I removed the |
||
|
||
const init = useRef(true); | ||
const timelineUi = useTimelineContext()?.ui; | ||
|
@@ -113,15 +116,12 @@ export const CaseViewPage = React.memo<CaseViewPageProps>( | |
onUpdateField={onUpdateField} | ||
/> | ||
</HeaderPage> | ||
|
||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<CaseViewMetrics data-test-subj="case-view-metrics" caseId={caseData.id} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
||
<EuiSpacer size="l" /> | ||
|
||
<EuiFlexGroup data-test-subj={`case-view-tab-content-${activeTabId}`} alignItems="baseline"> | ||
{activeTabId === CASE_VIEW_PAGE_TABS.ACTIVITY && ( | ||
<CaseViewActivity | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1013,11 +1013,22 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { | |
describe('Tabs', () => { | ||
createOneCaseBeforeDeleteAllAfter(getPageObject, getService); | ||
|
||
it('renders tabs correctly', async () => { | ||
await testSubjects.existOrFail('case-view-tab-title-activity'); | ||
await testSubjects.existOrFail('case-view-tab-title-files'); | ||
// there are no alerts in stack management yet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this PR #172217 is merged we can test the alerts table in the stack. |
||
}); | ||
|
||
it('shows the "activity" tab by default', async () => { | ||
await testSubjects.existOrFail('case-view-tab-title-activity'); | ||
await testSubjects.existOrFail('case-view-tab-content-activity'); | ||
}); | ||
|
||
it("shows the 'activity' tab when clicked", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test make sense here following the previous one? We are already in the activity tab, I don't know how relevant it is to check that nothing changes when we click it. Maybe we could go to files and back instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Much better. |
||
await testSubjects.click('case-view-tab-title-activity'); | ||
await testSubjects.existOrFail('case-view-tab-content-activity'); | ||
}); | ||
|
||
// there are no alerts in stack management yet | ||
it.skip("shows the 'alerts' tab when clicked", async () => { | ||
await testSubjects.click('case-view-tab-title-alerts'); | ||
|
@@ -1028,6 +1039,37 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { | |
await testSubjects.click('case-view-tab-title-files'); | ||
await testSubjects.existOrFail('case-view-tab-content-files'); | ||
}); | ||
|
||
describe('Query params', () => { | ||
it('renders the activity tab when the query parameter tabId=activity', async () => { | ||
const theCase = await createAndNavigateToCase(getPageObject, getService); | ||
|
||
await cases.navigation.navigateToSingleCase('cases', theCase.id, 'activity'); | ||
await testSubjects.existOrFail('case-view-tab-title-activity'); | ||
}); | ||
|
||
// there are no alerts in stack management yet | ||
it.skip('renders the activity tab when the query parameter tabId=alerts', async () => { | ||
const theCase = await createAndNavigateToCase(getPageObject, getService); | ||
|
||
await cases.navigation.navigateToSingleCase('cases', theCase.id, 'alerts'); | ||
await testSubjects.existOrFail('case-view-tab-title-activity'); | ||
}); | ||
|
||
it('renders the activity tab when the query parameter tabId=files', async () => { | ||
const theCase = await createAndNavigateToCase(getPageObject, getService); | ||
|
||
await cases.navigation.navigateToSingleCase('cases', theCase.id, 'files'); | ||
await testSubjects.existOrFail('case-view-tab-content-files'); | ||
}); | ||
|
||
it('renders the activity tab when the query parameter tabId has an unknown value', async () => { | ||
const theCase = await createAndNavigateToCase(getPageObject, getService); | ||
|
||
await cases.navigation.navigateToSingleCase('cases', theCase.id, 'fake'); | ||
await testSubjects.existOrFail('case-view-tab-title-activity'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Files', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved outside the
Tabs
block.