Skip to content

Commit

Permalink
Resolved failing Jest test cases in Jest suite 3. Updated tests check…
Browse files Browse the repository at this point in the history
…ing for strict text equality to account for text coming from the EuiScreenReaderOnly component. Also updated tests to account for EuiIcon text that is now rendered when the icon is imported from .testenv (PR 5709 - elastic/eui#5709).
  • Loading branch information
breehall committed Mar 24, 2022
1 parent e3182bb commit 8398681
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('ExceptionEntries', () => {
expect(parentValue.text()).toEqual(getEmptyValue());

expect(nestedField.exists('.euiToolTipAnchor')).toBeTruthy();
expect(nestedField.text()).toEqual('host.name');
expect(nestedField.text()).toContain('host.name');
expect(nestedOperator.text()).toEqual('is');
expect(nestedValue.text()).toEqual('some name');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ describe('Modal Inspect', () => {

expect(
wrapper.find('.euiDescriptionList__title span[data-test-subj="index-pattern-title"]').text()
).toBe('Index pattern ');
).toContain('Index pattern ');
expect(
wrapper
.find('.euiDescriptionList__description span[data-test-subj="index-pattern-description"]')
.text()
).toBe('auditbeat-*, filebeat-*, packetbeat-*, winlogbeat-*');
expect(
wrapper.find('.euiDescriptionList__title span[data-test-subj="query-time-title"]').text()
).toBe('Query time ');
).toContain('Query time ');
expect(
wrapper
.find('.euiDescriptionList__description span[data-test-subj="query-time-description"]')
Expand All @@ -76,7 +76,7 @@ describe('Modal Inspect', () => {
wrapper
.find('.euiDescriptionList__title span[data-test-subj="request-timestamp-title"]')
.text()
).toBe('Request timestamp ');
).toContain('Request timestamp ');
});

test('Click on request Tab', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Custom Links', () => {
const wrapper = mountWithIntl(
<GoogleLink link={'http://example.com/'}>{'Example Link'}</GoogleLink>
);
expect(removeExternalLinkText(wrapper.text())).toEqual('Example Link');
expect(removeExternalLinkText(wrapper.text())).toContain('Example Link');
});

test('it renders props passed in as link', () => {
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('Custom Links', () => {
describe('WhoisLink', () => {
test('it renders ip passed in as domain', () => {
const wrapper = mountWithIntl(<WhoIsLink domain={'192.0.2.0'}>{'Example Link'}</WhoIsLink>);
expect(removeExternalLinkText(wrapper.text())).toEqual('Example Link');
expect(removeExternalLinkText(wrapper.text())).toContain('Example Link');
});

test('it renders correct href', () => {
Expand All @@ -488,7 +488,7 @@ describe('Custom Links', () => {
{'Example Link'}
</CertificateFingerprintLink>
);
expect(removeExternalLinkText(wrapper.text())).toEqual('Example Link');
expect(removeExternalLinkText(wrapper.text())).toContain('Example Link');
});

test('it renders correct href', () => {
Expand Down Expand Up @@ -519,7 +519,7 @@ describe('Custom Links', () => {
const wrapper = mountWithIntl(
<Ja3FingerprintLink ja3Fingerprint={'abcd'}>{'Example Link'}</Ja3FingerprintLink>
);
expect(removeExternalLinkText(wrapper.text())).toEqual('Example Link');
expect(removeExternalLinkText(wrapper.text())).toContain('Example Link');
});

test('it renders correct href', () => {
Expand Down Expand Up @@ -548,7 +548,7 @@ describe('Custom Links', () => {
const wrapper = mountWithIntl(
<PortOrServiceNameLink portOrServiceName={443}>{'Example Link'}</PortOrServiceNameLink>
);
expect(removeExternalLinkText(wrapper.text())).toEqual('Example Link');
expect(removeExternalLinkText(wrapper.text())).toContain('Example Link');
});

test('it renders correct href when port is a number', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Markdown', () => {

expect(
removeExternalLinkText(wrapper.find('[data-test-subj="markdown-link"]').first().text())
).toEqual('External Site');
).toContain('External Site');
});

test('it renders the expected href', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('CertificateFingerprint', () => {
removeExternalLinkText(
wrapper.find('[data-test-subj="certificate-fingerprint-link"]').first().text()
)
).toEqual('3f4c57934e089f02ae7511200aee2d7e7aabd272');
).toContain('3f4c57934e089f02ae7511200aee2d7e7aabd272');
});

test('it renders a hyperlink to an external site to compare the fingerprint against a known set of signatures', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Ja3Fingerprint', () => {

expect(
removeExternalLinkText(wrapper.find('[data-test-subj="ja3-fingerprint-link"]').first().text())
).toEqual('fff799d91b7c01ae3fe6787cfc895552');
).toContain('fff799d91b7c01ae3fe6787cfc895552');
});

test('it renders a hyperlink to an external site to compare the fingerprint against a known set of signatures', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('Netflow', () => {
removeExternalLinkText(
wrapper.find('[data-test-subj="destination-ip-and-port"]').first().text()
)
).toEqual('10.1.2.3:80');
).toContain('10.1.2.3:80');
});

test('it renders destination.packets', () => {
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('Netflow', () => {

expect(
removeExternalLinkText(wrapper.find('[data-test-subj="source-ip-and-port"]').first().text())
).toEqual('192.168.1.2:9987');
).toContain('192.168.1.2:9987');
});

test('it renders source.packets', () => {
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('Netflow', () => {
.first()
.text()
)
).toEqual('tls.client_certificate.fingerprint.sha1-value');
).toContain('tls.client_certificate.fingerprint.sha1-value');
});

test('it hyperlinks tls.fingerprints.ja3.hash site to compare the fingerprint against a known set of signatures', () => {
Expand All @@ -390,7 +390,7 @@ describe('Netflow', () => {

expect(
removeExternalLinkText(wrapper.find('[data-test-subj="ja3-fingerprint-link"]').first().text())
).toEqual('tls.fingerprints.ja3.hash-value');
).toContain('tls.fingerprints.ja3.hash-value');
});

test('it hyperlinks tls.server_certificate.fingerprint.sha1 site to compare the fingerprint against a known set of signatures', () => {
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('Netflow', () => {
.first()
.text()
)
).toEqual('tls.server_certificate.fingerprint.sha1-value');
).toContain('tls.server_certificate.fingerprint.sha1-value');
});

test('it renders network.transport', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { useMountAppended } from '../../../../../common/utils/use_mount_appended
import { defaultRowRenderers } from '.';
import { getRowRenderer } from './get_row_renderer';

// EuiIcons coming from .testenv render the icon's aria-label as a span
// extractEuiIcon removes the aria-label before checking for equality
const extractEuiIconText = (str: string) => {
return str.replaceAll('External link', '');
};

jest.mock('../../../../../common/lib/kibana');

jest.mock('@elastic/eui', () => {
Expand Down Expand Up @@ -90,7 +96,7 @@ describe('get_column_renderer', () => {
<span>{row}</span>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toContain(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'4ETEXPLOITNETGEARWNR2000v5 hidden_lang_avi Stack Overflow (CVE-2016-10174)Source192.168.0.3:53Destination192.168.0.3:6343'
);
});
Expand All @@ -109,7 +115,7 @@ describe('get_column_renderer', () => {
<span>{row}</span>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toContain(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'4ETEXPLOITNETGEARWNR2000v5 hidden_lang_avi Stack Overflow (CVE-2016-10174)Source192.168.0.3:53Destination192.168.0.3:6343'
);
});
Expand All @@ -128,7 +134,7 @@ describe('get_column_renderer', () => {
<span>{row}</span>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toContain(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'C8DRTq362Fios6hw16connectionREJSrConnection attempt rejectedtcpSource185.176.26.101:44059Destination207.154.238.205:11568'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ describe('SuricataDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
const removeEuiIconText = removeExternalLinkText(wrapper.text()).replaceAll(
'External link',
''
);
expect(removeEuiIconText).toEqual(
'4ETEXPLOITNETGEARWNR2000v5 hidden_lang_avi Stack Overflow (CVE-2016-10174)Source192.168.0.3:53Destination192.168.0.3:6343'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ describe('suricata_row_renderer', () => {
<span>{children}</span>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toContain(

const extractEuiIconText = removeExternalLinkText(wrapper.text()).replaceAll(
'External link',
''
);
expect(extractEuiIconText).toContain(
'4ETEXPLOITNETGEARWNR2000v5 hidden_lang_avi Stack Overflow (CVE-2016-10174)Source192.168.0.3:53Destination192.168.0.3:6343'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ import {
import * as i18n from './translations';
import { RowRenderer } from '../../../../../../../common/types';

// EuiIcons coming from .testenv render the icon's aria-label as a span
// extractEuiIcon removes the aria-label before checking for equality
const extractEuiIconText = (str: string) => {
return str.replaceAll('External link', '');
};

jest.mock('../../../../../../common/lib/kibana');

jest.mock('@elastic/eui', () => {
Expand Down Expand Up @@ -1130,7 +1136,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'NETWORK SERVICE\\NT AUTHORITY@windows-endpoint-1accepted a connection viasvchost.exe(328)with resultsuccessEndpoint network eventincomingtcpSource10.1.2.3:64557North AmericaUnited States🇺🇸USNorth CarolinaConcordDestination10.50.60.70:3389'
);
});
Expand Down Expand Up @@ -1214,7 +1220,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'NETWORK SERVICE\\NT AUTHORITY@win2019-endpoint-1made a http request viasvchost.exe(2232)Endpoint network eventoutgoinghttptcpSource10.1.2.3:51570Destination10.11.12.13:80North AmericaUnited States🇺🇸USArizonaPhoenix'
);
});
Expand Down Expand Up @@ -1243,7 +1249,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'SYSTEM\\NT AUTHORITY@HD-gqf-0af7b4feaccepted a connection viaAmSvc.exe(1084)tcp1:network-community_idSource127.0.0.1:49306Destination127.0.0.1:49305'
);
});
Expand Down Expand Up @@ -1272,7 +1278,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'SYSTEM\\NT AUTHORITY@HD-55b-3ec87f66accepted a connection via(4)tcp1:network-community_idSource::1:51324Destination::1:5357'
);
});
Expand All @@ -1298,7 +1304,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'NETWORK SERVICE\\NT AUTHORITY@windows-endpoint-1disconnected viasvchost.exe(328)Endpoint network eventincomingtcpSource10.20.30.40:64557North AmericaUnited States🇺🇸USNorth CarolinaConcord(42.47%)1.2KB(57.53%)1.6KBDestination10.11.12.13:3389'
);
});
Expand Down Expand Up @@ -1327,7 +1333,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'Arun\\Anvi-Acer@HD-obe-8bf77f54disconnected viachrome.exe(11620)8.1KBtcp1:LxYHJJv98b2O0fNccXu6HheXmwk=Source192.168.0.6:59356(25.78%)2.1KB(74.22%)6KBDestination10.156.162.53:443'
);
});
Expand Down Expand Up @@ -1356,7 +1362,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'SYSTEM\\NT AUTHORITY@HD-55b-3ec87f66disconnected via(4)7.9KBtcp1:ZylzQhsB1dcptA2t4DY8S6l9o8E=Source::1:51338(96.92%)7.7KB(3.08%)249BDestination::1:2869'
);
});
Expand Down Expand Up @@ -1385,7 +1391,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'root@foohostopened a socket withgoogle_accounts(2166)Outbound socket (10.4.20.1:59554 -> 10.1.2.3:80) Ooutboundtcp1:network-community_idSource10.4.20.1:59554Destination10.1.2.3:80'
);
});
Expand Down Expand Up @@ -1414,7 +1420,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'root@foohostclosed a socket withgoogle_accounts(2166)Outbound socket (10.4.20.1:59508 -> 10.1.2.3:80) Coutboundtcp1:network-community_idSource10.4.20.1:59508Destination10.1.2.3:80'
);
});
Expand Down Expand Up @@ -1722,7 +1728,7 @@ describe('GenericRowRenderer', () => {
</TestProviders>
);

expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toBe(
'iot.example.comasked forlookup.example.comwith question typeA, which resolved to10.1.2.3(response code:NOERROR)viaan unknown process6.937500msOct 8, 2019 @ 10:05:23.241Oct 8, 2019 @ 10:05:23.248outbounddns177Budp1:network-community_idSource10.9.9.9:58732(22.60%)40B(77.40%)137BDestination10.1.1.1:53OceaniaAustralia🇦🇺AU'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { mockTimelineData, TestProviders } from '../../../../../../common/mock';
import { useMountAppended } from '../../../../../../common/utils/use_mount_appended';
import { ZeekDetails } from './zeek_details';

// EuiIcons coming from .testenv render the icon's aria-label as a span
// extractEuiIcon removes the aria-label before checking for equality
const extractEuiIconText = (str: string) => {
return str.replaceAll('External link', '');
};

jest.mock('../../../../../../common/lib/kibana');

jest.mock('@elastic/eui', () => {
Expand Down Expand Up @@ -53,7 +59,7 @@ describe('ZeekDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toEqual(
'C8DRTq362Fios6hw16connectionREJSrConnection attempt rejectedtcpSource185.176.26.101:44059Destination207.154.238.205:11568'
);
});
Expand All @@ -68,7 +74,7 @@ describe('ZeekDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toEqual(
'CyIrMA1L1JtLqdIuoldnsudpSource206.189.35.240:57475Destination67.207.67.3:53'
);
});
Expand All @@ -83,7 +89,7 @@ describe('ZeekDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toEqual(
'CZLkpC22NquQJOpkwehttp302Source206.189.35.240:36220Destination192.241.164.26:80'
);
});
Expand All @@ -98,7 +104,7 @@ describe('ZeekDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toEqual(
'noticeDropped:falseScan::Port_Scan8.42.77.171 scanned at least 15 unique ports of host 207.154.238.205 in 0m0sSource8.42.77.171'
);
});
Expand All @@ -113,7 +119,7 @@ describe('ZeekDetails', () => {
/>
</TestProviders>
);
expect(removeExternalLinkText(wrapper.text())).toEqual(
expect(extractEuiIconText(removeExternalLinkText(wrapper.text()))).toEqual(
'CmTxzt2OVXZLkGDaResslTLSv12TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256Source188.166.66.184:34514Destination91.189.95.15:443'
);
});
Expand Down
Loading

0 comments on commit 8398681

Please sign in to comment.