Skip to content

Commit

Permalink
wip: feat: scopes in data-test-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
callogerasl committed Jan 26, 2018
1 parent 39fd3eb commit 7583e45
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
37 changes: 34 additions & 3 deletions morph/react/make-block-test-id.js
@@ -1,6 +1,17 @@
import toCamelCase from 'to-camel-case'
import toSlugCase from 'to-slug-case'

export const enter = key => (node, parent, state) => {
if (node.name === 'Proxy') return

const scopes = node.scopes
.filter(scope => !scope.isSystem)
.map(scope => {
return scope.value
})
.filter(Boolean)
.reverse()

let blockName = node.is || node.name

if (typeof state.testIds[blockName] === 'number') {
Expand All @@ -10,9 +21,29 @@ export const enter = key => (node, parent, state) => {
state.testIds[blockName] = 0
}

if (parent) {
state.render.push(` ${key}="${state.name}.${blockName}"`)
let conditional = `''`
scopes.forEach(scope => {
let s = toSlugCase(scope.replace('!', 'not-'))
s = s.replace(/props./g, '')
s = toCamelCase(s)
conditional = `${scope} ? '${s}' : ` + conditional
})

if (node.isBasic) {
if (parent) {
state.render.push(
` ${key}={"${state.name}.${blockName}|" + (${conditional})}`
)
} else {
state.render.push(
` ${key}={(props["${key}"] || "${blockName}") + '|' + (${conditional})}`
)
}
} else {
state.render.push(` ${key}={props["${key}"] || "${blockName}"}`)
if (parent) {
state.render.push(` ${key}="${state.name}.${blockName}"`)
} else {
state.render.push(` ${key}={props["${key}"] || "${blockName}"}`)
}
}
}

0 comments on commit 7583e45

Please sign in to comment.