Chore: convert LogRowContextProvider tests to RTL (#55031)

* convert LogRowContextProvider tests to RTL

* remove act
This commit is contained in:
Ashley Harrison 2022-09-12 15:00:09 +01:00 committed by GitHub
parent 49bc70c812
commit b90260b3ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View File

@ -8,9 +8,6 @@ exports[`no enzyme tests`] = {
"packages/grafana-ui/src/components/Graph/Graph.test.tsx:1664091255": [
[0, 17, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.tsx:3786619094": [
[0, 17, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/QueryField/QueryField.test.tsx:2976628669": [
[0, 26, 13, "RegExp match", "2409514259"]
],

View File

@ -1,6 +1,5 @@
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { FieldType, LogRowModel, MutableDataFrame, DataQueryResponse } from '@grafana/data';
@ -152,7 +151,7 @@ describe('LogRowContextProvider', () => {
expect(errors).toEqual({ before: undefined, after: undefined });
expect(hasMoreContextRows).toEqual({ before: true, after: true });
expect(limit).toBe(10);
return <></>;
return <div data-testid="mockChild" />;
}
if (!updateLimitCalled && result.before.length > 0) {
expect(result).toEqual({ before: ['10', '9', '8', '7', '6', '5'], after: ['14', '13', '12'] });
@ -161,20 +160,19 @@ describe('LogRowContextProvider', () => {
expect(limit).toBe(10);
updateLimit();
updateLimitCalled = true;
return <></>;
return <div data-testid="mockChild" />;
}
if (updateLimitCalled && result.before.length > 0 && limit > 10) {
expect(limit).toBe(20);
}
return <></>;
});
await act(async () => {
await mount(
<LogRowContextProvider row={row} getRowContext={getRowContextMock}>
{mockedChildren}
</LogRowContextProvider>
);
return <div data-testid="mockChild" />;
});
render(
<LogRowContextProvider row={row} getRowContext={getRowContextMock}>
{mockedChildren}
</LogRowContextProvider>
);
await screen.findByTestId('mockChild');
});
});
});