Skip to content

Commit

Permalink
[META] - Converted makeId to TS + tests (#1759)
Browse files Browse the repository at this point in the history
* [Pagination] - Updated Changelog

* Code Review - Moved Changelog entry to current master

* [META] - Converted  to TS + tests

* Updated Changelog

* Added Non-null assertion operator before graphicColors

* [META] - Converted  to TS + tests

* Updated Changelog

* Code review fixes
  • Loading branch information
theodesp authored and chandlerprall committed Mar 25, 2019
1 parent 4bdad39 commit 9595574
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
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;

0 comments on commit 9595574

Please sign in to comment.