Skip to content

Commit

Permalink
Merge branch 'main' into 2023_12_20-remove_resize_observer_mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 authored Jan 9, 2024
2 parents 2fb8aa8 + 8f9e11d commit 8370e88
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/cloud/build_and_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fi

echo "--- Create Deployment"
CLOUD_DEPLOYMENT_ID=$(ecctl deployment list --output json | jq -r '.deployments[] | select(.name == "'$CLOUD_DEPLOYMENT_NAME'") | .id')
if [ -z "${CLOUD_DEPLOYMENT_ID}" ]; then
if [ -z "${CLOUD_DEPLOYMENT_ID}" ] || [ "${CLOUD_DEPLOYMENT_ID}" = 'null' ]; then
jq '
.resources.kibana[0].plan.kibana.docker_image = "'$KIBANA_CLOUD_IMAGE'" |
.resources.elasticsearch[0].plan.elasticsearch.docker_image = "'$ELASTICSEARCH_CLOUD_IMAGE'" |
Expand Down
5 changes: 5 additions & 0 deletions .buildkite/scripts/steps/serverless/build_and_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ deploy() {
-XPOST -d "$PROJECT_CREATE_CONFIGURATION" &>> $DEPLOY_LOGS

PROJECT_ID=$(jq -r --slurp '.[1].id' $DEPLOY_LOGS)
if [ -z "${PROJECT_ID}" ] || [ "$PROJECT_ID" = 'null' ]; then
echo "Failed to create project. Deploy logs:"
cat $DEPLOY_LOGS
exit 1
fi

echo "Get credentials..."
curl -s -XPOST -H "Authorization: ApiKey $PROJECT_API_KEY" \
Expand Down
7 changes: 4 additions & 3 deletions src/cli_plugin/install/zip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import globby from 'globby';

import { analyzeArchive, extractArchive } from './zip';

const getMode = (path) => (fs.statSync(path).mode & parseInt('777', 8)).toString(8);
const getExecFlags = (path) =>
(fs.statSync(path).mode & parseInt('111', 8)).toString(8).padStart(3, '0');

describe('kibana cli', function () {
describe('zip', function () {
Expand Down Expand Up @@ -83,8 +84,8 @@ describe('kibana cli', function () {
]
`);

expect(getMode(path.resolve(tempPath, 'executable'))).toEqual('755');
expect(getMode(path.resolve(tempPath, 'not-executable'))).toEqual('644');
expect(getExecFlags(path.resolve(tempPath, 'executable'))).toEqual('111');
expect(getExecFlags(path.resolve(tempPath, 'not-executable'))).toEqual('000');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,79 @@ import userEvent from '@testing-library/user-event';
import type { AppMockRenderer } from '../../../common/mock';
import { createAppMockRenderer } from '../../../common/mock';
import { basicCase } from '../../../containers/mock';
import { waitForComponentToUpdate } from '../../../common/test_utils';
import { EditAssigneesFlyout } from './edit_assignees_flyout';
import { waitFor } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import { useBulkGetUserProfiles } from '../../../containers/user_profiles/use_bulk_get_user_profiles';
import { useSuggestUserProfiles } from '../../../containers/user_profiles/use_suggest_user_profiles';
import { userProfiles, userProfilesMap } from '../../../containers/user_profiles/api.mock';

jest.mock('../../../containers/user_profiles/api');
jest.mock('../../../containers/user_profiles/use_bulk_get_user_profiles');
jest.mock('../../../containers/user_profiles/use_suggest_user_profiles');

// Failing: See https://github.com/elastic/kibana/issues/174194
// Failing: See https://github.com/elastic/kibana/issues/174195
describe.skip('EditAssigneesFlyout', () => {
const useBulkGetUserProfilesMock = useBulkGetUserProfiles as jest.Mock;
const useSuggestUserProfilesMock = useSuggestUserProfiles as jest.Mock;

describe('EditAssigneesFlyout', () => {
let appMock: AppMockRenderer;

/**
* Case one has the following assignees: coke, pepsi, one
* Case two has the following assignees: one, three
* All available assignees are: one, two, three, coke, pepsi
*/
const props = {
selectedCases: [basicCase],
onClose: jest.fn(),
onSaveAssignees: jest.fn(),
};

beforeEach(() => {
appMock = createAppMockRenderer();
jest.clearAllMocks();
appMock = createAppMockRenderer();

useBulkGetUserProfilesMock.mockReturnValue({ data: userProfilesMap });
useSuggestUserProfilesMock.mockReturnValue({ data: userProfiles, isLoading: false });
});

it('renders correctly', async () => {
const result = appMock.render(<EditAssigneesFlyout {...props} />);
appMock.render(<EditAssigneesFlyout {...props} />);

expect(result.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument();
expect(result.getByTestId('cases-edit-assignees-flyout-title')).toBeInTheDocument();
expect(result.getByTestId('cases-edit-assignees-flyout-cancel')).toBeInTheDocument();
expect(result.getByTestId('cases-edit-assignees-flyout-submit')).toBeInTheDocument();

await waitForComponentToUpdate();
expect(await screen.findByTestId('cases-edit-assignees-flyout')).toBeInTheDocument();
expect(await screen.findByTestId('cases-edit-assignees-flyout-title')).toBeInTheDocument();
expect(await screen.findByTestId('cases-edit-assignees-flyout-cancel')).toBeInTheDocument();
expect(await screen.findByTestId('cases-edit-assignees-flyout-submit')).toBeInTheDocument();
});

it('calls onClose when pressing the cancel button', async () => {
const result = appMock.render(<EditAssigneesFlyout {...props} />);
appMock.render(<EditAssigneesFlyout {...props} />);

userEvent.click(result.getByTestId('cases-edit-assignees-flyout-cancel'));
expect(props.onClose).toHaveBeenCalled();
userEvent.click(await screen.findByTestId('cases-edit-assignees-flyout-cancel'));

await waitForComponentToUpdate();
await waitFor(() => {
expect(props.onClose).toHaveBeenCalled();
});
});

it('calls onSaveAssignees when pressing the save selection button', async () => {
const result = appMock.render(<EditAssigneesFlyout {...props} />);
appMock.render(<EditAssigneesFlyout {...props} />);

await waitForComponentToUpdate();
expect(await screen.findByText('Damaged Raccoon')).toBeInTheDocument();

await waitFor(() => {
expect(result.getByText('Damaged Raccoon')).toBeInTheDocument();
});

userEvent.click(result.getByText('Damaged Raccoon'));
userEvent.click(result.getByTestId('cases-edit-assignees-flyout-submit'));
userEvent.click(await screen.findByText('Damaged Raccoon'));
userEvent.click(await screen.findByTestId('cases-edit-assignees-flyout-submit'));

expect(props.onSaveAssignees).toHaveBeenCalledWith({
selectedItems: [],
unSelectedItems: ['u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0'],
await waitFor(() => {
expect(props.onSaveAssignees).toHaveBeenCalledWith({
selectedItems: [],
unSelectedItems: ['u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0'],
});
});
});

it('shows the case title when selecting one case', async () => {
const result = appMock.render(<EditAssigneesFlyout {...props} />);

expect(result.getByText(basicCase.title)).toBeInTheDocument();
appMock.render(<EditAssigneesFlyout {...props} />);

await waitForComponentToUpdate();
expect(await screen.findByText(basicCase.title)).toBeInTheDocument();
});

it('shows the number of total selected cases in the title when selecting multiple cases', async () => {
const result = appMock.render(
<EditAssigneesFlyout {...props} selectedCases={[basicCase, basicCase]} />
);

expect(result.getByText('Selected cases: 2')).toBeInTheDocument();
appMock.render(<EditAssigneesFlyout {...props} selectedCases={[basicCase, basicCase]} />);

await waitForComponentToUpdate();
expect(await screen.findByText('Selected cases: 2')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,57 @@
* 2.0.
*/

import { waitFor, within } from '@testing-library/react';
import { screen, within } from '@testing-library/react';
import React from 'react';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics';
import { useGetCasesStatus } from '../../containers/use_get_cases_status';
import { CasesMetrics } from './cases_metrics';

jest.mock('../../api');
jest.mock('pretty-ms', () => jest.fn().mockReturnValue('2ms'));
jest.mock('../../containers/use_get_cases_metrics');
jest.mock('../../containers/use_get_cases_status');

// Failing: See https://github.com/elastic/kibana/issues/174300
describe.skip('Cases metrics', () => {
const useGetCasesMetricsMock = useGetCasesMetrics as jest.Mock;
const useGetCasesStatusMock = useGetCasesStatus as jest.Mock;

describe('Cases metrics', () => {
let appMockRenderer: AppMockRenderer;

beforeEach(() => {
useGetCasesMetricsMock.mockReturnValue({ isLoading: false, data: { mttr: 2000 } });
useGetCasesStatusMock.mockReturnValue({
isLoading: false,
data: {
countOpenCases: 20,
countInProgressCases: 40,
countClosedCases: 130,
},
});

appMockRenderer = createAppMockRenderer();
});

it('renders the correct stats', async () => {
const result = appMockRenderer.render(<CasesMetrics />);

await waitFor(() => {
expect(result.getByTestId('cases-metrics-stats')).toBeTruthy();
expect(within(result.getByTestId('openStatsHeader')).getByText(20)).toBeTruthy();
expect(within(result.getByTestId('inProgressStatsHeader')).getByText(40)).toBeTruthy();
expect(within(result.getByTestId('closedStatsHeader')).getByText(130)).toBeTruthy();
expect(within(result.getByTestId('mttrStatsHeader')).getByText('12s')).toBeTruthy();
});
appMockRenderer.render(<CasesMetrics />);

expect(await screen.findByTestId('cases-metrics-stats')).toBeInTheDocument();

expect(
within(await screen.findByTestId('openStatsHeader')).getByText('20')
).toBeInTheDocument();

expect(
within(await screen.findByTestId('inProgressStatsHeader')).getByText('40')
).toBeInTheDocument();

expect(
within(await screen.findByTestId('closedStatsHeader')).getByText('130')
).toBeInTheDocument();

expect(
within(await screen.findByTestId('mttrStatsHeader')).getByText('2ms')
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const EditQueryDelay: FC<{
queryDelay: Datafeed['query_delay'];
isEnabled: boolean;
}> = ({ datafeedId, queryDelay, isEnabled }) => {
const [currentQueryDelay, setCurrentQueryDelay] = useState(queryDelay);
const [newQueryDelay, setNewQueryDelay] = useState<string | undefined>();
const [isEditing, setIsEditing] = useState<boolean>(false);
const { updateDatafeed } = useMlApiContext();
Expand All @@ -45,6 +46,7 @@ export const EditQueryDelay: FC<{
datafeedId,
datafeedConfig: { query_delay: newQueryDelay },
});
setCurrentQueryDelay(newQueryDelay);
displaySuccessToast(
i18n.translate(
'xpack.ml.jobsList.datafeedChart.editQueryDelay.changesSavedNotificationMessage',
Expand Down Expand Up @@ -120,7 +122,12 @@ export const EditQueryDelay: FC<{
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="none" direction="column">
<EuiFlexItem grow={false}>
<EuiButtonEmpty color="primary" size="xs" onClick={updateQueryDelay}>
<EuiButtonEmpty
disabled={newQueryDelay === currentQueryDelay}
color="primary"
size="xs"
onClick={updateQueryDelay}
>
<FormattedMessage
id="xpack.ml.jobsList.datafeedChart.applyQueryDelayLabel"
defaultMessage="Apply"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ journey(`TestRunDetailsPage`, async ({ page, params }) => {

step('Go to test run page', async () => {
await page.click(byTestId('superDatePickerToggleQuickMenuButton'));
await page.click('text=Last 1 year');
await page.getByTestId('superDatePickerQuickMenu').getByLabel('Time value').fill('10');
await page
.getByTestId('superDatePickerQuickMenu')
.getByLabel('Time unit')
.selectOption('Years');
await page.getByTestId('superDatePickerQuickMenu').getByText('Apply').click();
await page.mouse.wheel(0, 1000);
await page.click(byTestId('row-ab240846-8d22-11ed-8fac-52bb19a2321e'));

await page.waitForSelector('text=Test run details');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ProjectMonitor } from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
import { ProjectMonitorFormatter } from '../../synthetics_service/project_monitor/project_monitor_formatter';

const MAX_PAYLOAD_SIZE = 1048576 * 20; // 20MiB
const MAX_PAYLOAD_SIZE = 1048576 * 50; // 20MiB

export const addSyntheticsProjectMonitorRoute: SyntheticsRestApiRouteFactory = () => ({
method: 'PUT',
Expand Down

0 comments on commit 8370e88

Please sign in to comment.