Last active
November 12, 2019 16:33
-
-
Save dominikkaegi/e7eb5e56d90558cb836df66f09f0f945 to your computer and use it in GitHub Desktop.
Logs all data test ids with console.group. Within a group the reference to the element is available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function logIds() { | |
| function getDataTestIdElements() { | |
| return document.querySelectorAll('[data-test-id]') | |
| } | |
| function toArray(elementList) { | |
| return Array.from(elementList) | |
| } | |
| function toTagTestIdPair(item) { | |
| return { | |
| ref: item, | |
| id: item.getAttribute('data-test-id') | |
| } | |
| } | |
| function map(array, f) { | |
| return array.map(f) | |
| } | |
| function logElements(items) { | |
| for (const item of items) { | |
| const tagTitle = rightSpacing(item.ref.tagName, 6) | |
| console.groupCollapsed(`${tagTitle}: ${item.id}`) | |
| console.log(item.ref) | |
| console.groupEnd() | |
| } | |
| } | |
| /** | |
| * Adds spaces to the right of a text if it the text | |
| * does not exceed the amount of letters in the text | |
| * than the provided length | |
| * @param text | |
| * @param length | |
| */ | |
| function rightSpacing(text, length) { | |
| const diff = length - text.length; | |
| let result = text; | |
| for (let i = 0; i < diff; i++) { | |
| result = result + ' '; | |
| } | |
| return result | |
| } | |
| logElements( | |
| map( | |
| toArray(getDataTestIdElements()), | |
| toTagTestIdPair | |
| ) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment