Skip to content
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

Remove undocumented Random service #7329

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src-docs/src/views/search_bar/controlled_search_bar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, Fragment } from 'react';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import { faker } from '@faker-js/faker';
import {
EuiHealth,
EuiCallOut,
Expand All @@ -13,8 +12,6 @@ import {
EuiButton,
} from '../../../../src/components';

const random = new Random();

const tags = [
{ name: 'marketing', color: 'danger' },
{ name: 'finance', color: 'success' },
Expand All @@ -27,20 +24,20 @@ const types = ['dashboard', 'visualization', 'watch'];

const users = ['dewey', 'wanda', 'carrie', 'jmack', 'gabic'];

const items = times(10, (id) => {
const items = [...Array(10).keys()].map((id) => {
return {
id,
status: random.oneOf(['open', 'closed']),
type: random.oneOf(types),
tag: random.setOf(
status: faker.helpers.arrayElement(['open', 'closed']),
type: faker.helpers.arrayElement(types),
tag: faker.helpers.arrayElements(
tags.map((tag) => tag.name),
{ min: 0, max: 3 }
),
active: random.boolean(),
owner: random.oneOf(users),
followers: random.integer({ min: 0, max: 20 }),
comments: random.integer({ min: 0, max: 10 }),
stars: random.integer({ min: 0, max: 5 }),
active: faker.datatype.boolean(),
owner: faker.helpers.arrayElement(users),
followers: faker.number.int({ min: 0, max: 20 }),
comments: faker.number.int({ min: 0, max: 10 }),
stars: faker.number.int({ min: 0, max: 5 }),
};
});

Expand Down
23 changes: 10 additions & 13 deletions src-docs/src/views/search_bar/search_bar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, Fragment } from 'react';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import { faker } from '@faker-js/faker';
import {
EuiHealth,
EuiCallOut,
Expand All @@ -14,8 +13,6 @@ import {
EuiSearchBar,
} from '../../../../src/components';

const random = new Random();

const tags = [
{ name: 'marketing', color: 'danger' },
{ name: 'finance', color: 'success' },
Expand All @@ -28,20 +25,20 @@ const types = ['dashboard', 'visualization', 'watch'];

const users = ['dewey', 'wanda', 'carrie', 'jmack', 'gabic'];

const items = times(10, (id) => {
const items = [...Array(10).keys()].map((id) => {
return {
id,
status: random.oneOf(['open', 'closed']),
type: random.oneOf(types),
tag: random.setOf(
status: faker.helpers.arrayElement(['open', 'closed']),
type: faker.helpers.arrayElement(types),
tag: faker.helpers.arrayElements(
tags.map((tag) => tag.name),
{ min: 0, max: 3 }
),
active: random.boolean(),
owner: random.oneOf(users),
followers: random.integer({ min: 0, max: 20 }),
comments: random.integer({ min: 0, max: 10 }),
stars: random.integer({ min: 0, max: 5 }),
active: faker.datatype.boolean(),
owner: faker.helpers.arrayElement(users),
followers: faker.number.int({ min: 0, max: 20 }),
comments: faker.number.int({ min: 0, max: 10 }),
stars: faker.number.int({ min: 0, max: 5 }),
};
});

Expand Down
23 changes: 10 additions & 13 deletions src-docs/src/views/search_bar/search_bar_filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, Fragment } from 'react';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import { faker } from '@faker-js/faker';
import {
EuiHealth,
EuiCallOut,
Expand All @@ -17,8 +16,6 @@ import {
EuiPanel,
} from '../../../../src/components';

const random = new Random();

const tags = [
{ name: 'marketing', color: 'danger' },
{ name: 'finance', color: 'success' },
Expand Down Expand Up @@ -47,20 +44,20 @@ const types = ['dashboard', 'visualization', 'watch'];

const users = ['dewey', 'wanda', 'carrie', 'jmack', 'gabic'];

const items = times(10, (id) => {
const items = [...Array(10).keys()].map((id) => {
return {
id,
status: random.oneOf(['open', 'closed']),
type: random.oneOf(types),
tag: random.setOf(
status: faker.helpers.arrayElement(['open', 'closed']),
type: faker.helpers.arrayElement(types),
tag: faker.helpers.arrayElements(
tags.map((tag) => tag.name),
{ min: 0, max: 3 }
),
active: random.boolean(),
owner: random.oneOf(users),
followers: random.integer({ min: 0, max: 20 }),
comments: random.integer({ min: 0, max: 10 }),
stars: random.integer({ min: 0, max: 5 }),
active: faker.datatype.boolean(),
owner: faker.helpers.arrayElement(users),
followers: faker.number.int({ min: 0, max: 20 }),
comments: faker.number.int({ min: 0, max: 10 }),
stars: faker.number.int({ min: 0, max: 5 }),
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, ReactNode } from 'react';
import { faker } from '@faker-js/faker';
import { Random } from '../../../../../src/services';

import {
EuiInMemoryTable,
Expand Down Expand Up @@ -90,8 +89,6 @@ const columns: Array<EuiBasicTableColumn<User>> = [
},
];

const random = new Random();

const noItemsFoundMsg = 'No users match search criteria';

export default () => {
Expand Down Expand Up @@ -129,7 +126,7 @@ export default () => {
setMessage(noItemsFoundMsg);
setError(undefined);
setUsers(userData);
}, random.number({ min: 0, max: 3000 }));
}, faker.number.int({ min: 0, max: 3000 }));
};

const onlineUsers = users.filter((user) => user.online);
Expand All @@ -144,7 +141,7 @@ export default () => {
setMessage(noItemsFoundMsg);
setError('ouch!... again... ');
setUsers([]);
}, random.number({ min: 0, max: 3000 }));
}, faker.number.int({ min: 0, max: 3000 }));
};

const renderToolsLeft = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, ReactNode } from 'react';
import { faker } from '@faker-js/faker';
import { Random } from '../../../../../src/services';

import {
EuiInMemoryTable,
Expand Down Expand Up @@ -91,8 +90,6 @@ const columns: Array<EuiBasicTableColumn<User>> = [
},
];

const random = new Random();

const noItemsFoundMsg = 'No users match search criteria';

export default () => {
Expand Down Expand Up @@ -130,7 +127,7 @@ export default () => {
setMessage(noItemsFoundMsg);
setError(undefined);
setUsers(userData);
}, random.number({ min: 0, max: 3000 }));
}, faker.number.int({ min: 0, max: 3000 }));
};

const loadUsersWithError = () => {
Expand All @@ -143,7 +140,7 @@ export default () => {
setMessage(noItemsFoundMsg);
setError('ouch!... again... ');
setUsers([]);
}, random.number({ min: 0, max: 3000 }));
}, faker.number.int({ min: 0, max: 3000 }));
};

const renderToolsLeft = () => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/search_bar/query/date_format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* Side Public License, v 1.
*/

import { dateFormat, dateGranularity, Granularity } from './date_format';
import { Random } from '../../../services';
import moment from 'moment';
import { faker } from '@faker-js/faker';

import { dateFormat, dateGranularity, Granularity } from './date_format';

const random = new Random();
const originalMomentNow = moment.now;

const now = random.moment().utc();
const now = moment(faker.date.anytime()).utc();

beforeEach(() => {
moment.now = () => +now;
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('date format', () => {
});

test('parse - week granularity', () => {
const weekNumber = random.integer({ min: 0, max: 50 });
const weekNumber = faker.number.int({ min: 0, max: 50 });
const week = moment(now).week(weekNumber).startOf('week');
let parsed = dateFormat.parse(`Week ${weekNumber}`);
expect(parsed.utcOffset()).toBe(0);
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('date format', () => {
});

test('parse - year granularity', () => {
const year = random.integer({ min: 1970, max: new Date().getFullYear() });
const year = faker.number.int({ min: 1970, max: new Date().getFullYear() });
[
year.toString(),
year % 100 < 10 ? `0${year % 100}` : (year % 100).toString(), // YY format (padding with 0s)
Expand Down
8 changes: 4 additions & 4 deletions src/components/search_bar/query/date_value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* Side Public License, v 1.
*/

import { dateValueParser, isDateValue } from './date_value';
import { Random } from '../../../services';
import moment from 'moment';
import { faker } from '@faker-js/faker';

const random = new Random();
import { dateValueParser, isDateValue } from './date_value';

describe('date value', () => {
test('dateValueParser', () => {
const date = random.moment().utc();
const date = moment(faker.date.anytime()).utc();
const parse = jest.fn();
parse.mockReturnValue(date);
const format = { parse, print: jest.fn() };
Expand Down
22 changes: 8 additions & 14 deletions src/components/search_bar/query/default_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { defaultSyntax } from './default_syntax';
import { AST, Clause, FieldClause } from './ast';
import { Granularity } from './date_format';
import { DateValue, isDateValue } from './date_value';
import { Random } from '../../../services';

const random = new Random();

describe('defaultSyntax', () => {
test('empty query', () => {
Expand Down Expand Up @@ -1020,17 +1017,14 @@ describe('defaultSyntax', () => {

test('strict schema - flags - listed as non-boolean field', () => {
const query = 'is:active';
const schema = {
strict: true,
fields: {
active: {
type: random.oneOf(['number', 'string', 'date']),
},
},
};
expect(() => {
defaultSyntax.parse(query, { schema });
}).toThrow('Unknown flag `active`');
const getSchema = (type: string) => ({
schema: { strict: true, fields: { active: { type } } },
});
['number', 'string', 'date'].forEach((type) => {
expect(() => {
defaultSyntax.parse(query, getSchema(type));
}).toThrow('Unknown flag `active`');
});
});

test('strict schema - flags - not listed', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/search_bar/query/execute_ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

import { AST } from './ast';
import { executeAst } from './execute_ast';
import { Random } from '../../../services';

const random = new Random();

describe('execute ast', () => {
test('single matching field clause', () => {
Expand Down Expand Up @@ -122,9 +119,12 @@ describe('execute ast', () => {
{ name: 'john', description: 'doe', age: 5 },
{ name: 'joe' },
];
const value = random.oneOf(['john', 'doe']);
const result = executeAst(AST.create([AST.Term.must(value)]), items);
expect(result).toHaveLength(1);

const result1 = executeAst(AST.create([AST.Term.must('john')]), items);
expect(result1).toHaveLength(1);

const result2 = executeAst(AST.create([AST.Term.must('doe')]), items);
expect(result2).toHaveLength(1);
});

// when no default fields specified, we automatically select all/only
Expand Down
Loading