Skip to content
Permalink
Browse files

wip: feat: scopes in data-test-ids

  • Loading branch information...
callogerasl committed Jan 26, 2018
1 parent 39fd3eb commit 7583e45b1d470ae764bebf4ad9dd7c3fb16b3305
Showing with 39 additions and 3 deletions.
  1. +5 −0 .prettierrc
  2. +34 −3 morph/react/make-block-test-id.js
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
@@ -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') {
@@ -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.
You can’t perform that action at this time.