[9.0] [Unzyme] Migrates status_table of enzyme completely (#218361) (#218491)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Unzyme] Migrates status_table of enzyme completely
(#218361)](https://github.com/elastic/kibana/pull/218361)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Christiane (Tina)
Heiligers","email":"christiane.heiligers@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T20:23:28Z","message":"[Unzyme]
Migrates status_table of enzyme completely (#218361)\n\n## Summary\nfix
https://github.com/elastic/kibana/issues/217589 again\nThe
implementation in https://github.com/elastic/kibana/pull/217599 for\nthe
status table still relied on enzyme indirectly by
using\n`mountWithI18n`.\n\nThis PR refactors the test from implementing
the enzyme-reliant helper\nto using `renderReactTestingLibraryWithI18n`
that doesn't.\n\n## Note to reviewers:\nIf
`renderReactTestingLibraryWithI18n` becomes the standard, renaming
it\nto something shorter (e.g. `renderWithI18n`) would be nicer. ATM,
the\nhelper's only used in 13 files and it would be better to do so now
that\nwhen adoption becomes wide-spread.\n\nThe package is owned by
`shared-ux` and renaming the function would\nrequire code-reviews from
too many teams to justify doing so in this PR.\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c45f791ddb3917fb13d978fc53a3a440bf9505b5","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","v9.1.0"],"title":"[Unzyme]
Migrates status_table of enzyme
completely","number":218361,"url":"https://github.com/elastic/kibana/pull/218361","mergeCommit":{"message":"[Unzyme]
Migrates status_table of enzyme completely (#218361)\n\n## Summary\nfix
https://github.com/elastic/kibana/issues/217589 again\nThe
implementation in https://github.com/elastic/kibana/pull/217599 for\nthe
status table still relied on enzyme indirectly by
using\n`mountWithI18n`.\n\nThis PR refactors the test from implementing
the enzyme-reliant helper\nto using `renderReactTestingLibraryWithI18n`
that doesn't.\n\n## Note to reviewers:\nIf
`renderReactTestingLibraryWithI18n` becomes the standard, renaming
it\nto something shorter (e.g. `renderWithI18n`) would be nicer. ATM,
the\nhelper's only used in 13 files and it would be better to do so now
that\nwhen adoption becomes wide-spread.\n\nThe package is owned by
`shared-ux` and renaming the function would\nrequire code-reviews from
too many teams to justify doing so in this PR.\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c45f791ddb3917fb13d978fc53a3a440bf9505b5"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218361","number":218361,"mergeCommit":{"message":"[Unzyme]
Migrates status_table of enzyme completely (#218361)\n\n## Summary\nfix
https://github.com/elastic/kibana/issues/217589 again\nThe
implementation in https://github.com/elastic/kibana/pull/217599 for\nthe
status table still relied on enzyme indirectly by
using\n`mountWithI18n`.\n\nThis PR refactors the test from implementing
the enzyme-reliant helper\nto using `renderReactTestingLibraryWithI18n`
that doesn't.\n\n## Note to reviewers:\nIf
`renderReactTestingLibraryWithI18n` becomes the standard, renaming
it\nto something shorter (e.g. `renderWithI18n`) would be nicer. ATM,
the\nhelper's only used in 13 files and it would be better to do so now
that\nwhen adoption becomes wide-spread.\n\nThe package is owned by
`shared-ux` and renaming the function would\nrequire code-reviews from
too many teams to justify doing so in this PR.\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c45f791ddb3917fb13d978fc53a3a440bf9505b5"}}]}]
BACKPORT-->

Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
This commit is contained in:
Kibana Machine 2025-04-17 19:10:37 +02:00 committed by GitHub
parent 0afff0c441
commit cb022879a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,8 +8,7 @@
*/
import React from 'react';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { render } from '@testing-library/react';
import { renderReactTestingLibraryWithI18n } from '@kbn/test-jest-helpers';
import '@testing-library/jest-dom';
import type { StatusInfoServiceStatus as ServiceStatus } from '@kbn/core-status-common';
import { StatusTable } from './status_table';
@ -20,6 +19,12 @@ const state = {
message: 'Ready',
title: 'green',
};
const state2 = {
id: 'degraded' as const,
uiColor: 'warning',
message: 'Not ready',
title: 'yellow',
};
const createServiceStatus = (parts: Partial<ServiceStatus> = {}): ServiceStatus => ({
level: 'available',
@ -29,63 +34,55 @@ const createServiceStatus = (parts: Partial<ServiceStatus> = {}): ServiceStatus
describe('StatusTable', () => {
it('renders when statuses is provided', () => {
const component = mountWithIntl(
<StatusTable statuses={[{ id: 'plugin:1', state, original: createServiceStatus() }]} />
const { getByTestId, getByText } = renderReactTestingLibraryWithI18n(
<StatusTable
statuses={[
{ id: 'plugin:1', state, original: createServiceStatus() },
{
id: 'plugin:2',
state: state2,
original: createServiceStatus({ level: 'degraded', summary: 'Not ready' }),
},
]}
/>
);
const table = component.find('EuiInMemoryTable');
expect(table.prop('columns')).toEqual([
{
align: 'center',
field: 'state',
name: 'Status',
render: expect.any(Function),
sortable: expect.any(Function),
width: '100px',
},
{
field: 'id',
name: 'ID',
sortable: true,
},
{
field: 'state',
name: 'Status summary',
render: expect.any(Function),
},
{
align: 'right',
isExpander: true,
name: expect.any(Object), // Matches the <EuiScreenReaderOnly> component
render: expect.any(Function),
width: '40px',
},
]);
expect(table.prop('items')).toEqual([
{
id: 'plugin:1',
original: {
level: 'available',
summary: 'Ready',
},
state: {
id: 'available',
message: 'Ready',
title: 'green',
uiColor: 'success',
},
},
]);
expect(table.prop('sorting')).toEqual({
sort: {
direction: 'asc',
field: 'state',
},
});
expect(table.prop('data-test-subj')).toBe('statusBreakdown');
const table = getByTestId('statusBreakdown');
// Verify table exists
expect(table).toBeInTheDocument();
// Verify columns
expect(getByText('Status')).toBeInTheDocument();
expect(getByText('ID')).toBeInTheDocument();
expect(getByText('Status summary')).toBeInTheDocument();
// Verify items
expect(getByText('plugin:1')).toBeInTheDocument();
expect(getByText('Ready')).toBeInTheDocument();
// Verify header row contents
const headerRow = table.querySelector('thead tr');
expect(headerRow).toBeInTheDocument();
expect(headerRow).toHaveTextContent('Status');
expect(headerRow).toHaveTextContent('ID');
expect(headerRow).toHaveTextContent('Status summary');
expect(headerRow).toHaveTextContent('Expand row');
// Verify sorting by checking row order
const rows = table.querySelectorAll('tr');
expect(rows).toHaveLength(3); // 1 header row + 2 data rows
expect(rows[1]).toHaveTextContent('plugin:2');
expect(rows[1]).toHaveTextContent('Not ready');
expect(rows[1].className).toContain('status-table-row-warning');
expect(rows[2]).toHaveTextContent('plugin:1');
expect(rows[2]).toHaveTextContent('Ready');
expect(rows[2].className).toContain('status-table-row-success');
});
it('renders empty when statuses is not provided', () => {
const { container } = render(<StatusTable />);
const { container } = renderReactTestingLibraryWithI18n(<StatusTable />);
expect(container.firstChild).toBeNull();
});
});