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

[META] - Converted makeId to TS + tests #1759

Merged
merged 10 commits into from
Mar 25, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `makeId` to TS ([#1759](https://github.com/elastic/eui/pull/1759))
- Converted `EuiCardGraphic` to TS ([#1751](https://github.com/elastic/eui/pull/1751))
- Enhanced the build process to emit TypeScript types for the variables extracted from the themes ([#1750](https://github.com/elastic/eui/pull/1750))

Expand Down
1 change: 0 additions & 1 deletion src/components/form/form_row/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ declare module '@elastic/eui' {
/**
* @see './form_row.js'
*/

export type EuiFormRowCommonProps = CommonProps & {
error?: ReactNode | ReactNode[];
fullWidth?: boolean;
Expand Down
21 changes: 21 additions & 0 deletions src/components/form/form_row/make_id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import makeId from './make_id';

describe('makeId', () => {
let ids: Map<string, boolean>;
beforeEach(() => {
ids = new Map<string, boolean>();
});

test('returns a string of length 8', () => {
expect(makeId()).toHaveLength(8);
});

// Could be slow so adding a [SLOW] tag for use with --testNamePattern=<regex>
test('returns a random string - [SLOW]', () => {
for (let i = 0; i < 60000; i += 1) {
const id: string = makeId();
expect(ids.has(id)).toBeFalsy();
ids.set(id, true);
}
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Generate statistically almost-certainly-unique `id`s for associating form
// inputs with their labels and other descriptive text elements.
export default function makeId() {
return Math.random().toString(36).slice(-8);
function makeId(): string {
return Math.random()
.toString(36)
.slice(-8);
}

export default makeId;