|
const {defineInlineTest} = require('jscodeshift/dist/testUtils') |
|
const transform = require('./displayClassToHidden') |
|
const {SHOW, HIDE} = transform |
|
|
|
describe(`classList.add('d-*') => {hidden = ...}`, () => { |
|
defineInlineTest(transform, {}, |
|
`this.classList.add('d-none')`, |
|
`this.hidden = true`, |
|
`classList.add('d-none') => {hidden = true}`) |
|
|
|
defineInlineTest(transform, {}, |
|
`els.forEach(el => el.classList.add('d-none'))`, |
|
`els.forEach(el => el.hidden = true)`, |
|
`classList.add('d-none') => {hidden = true}`) |
|
|
|
defineInlineTest(transform, {}, |
|
`this.querySelector('g-emoji').classList.add('d-none')`, |
|
`this.querySelector('g-emoji').hidden = true`, |
|
`classList.add('d-none') => {hidden = true} (with complex expression)`) |
|
for (const klass of SHOW) { |
|
defineInlineTest(transform, {}, |
|
`this.classList.add('${klass}')`, |
|
`this.hidden = false`, |
|
`classList.add('${klass}') => {hidden = false}`) |
|
} |
|
|
|
// make sure that we don't transform unqualified classList identifiers |
|
defineInlineTest(transform, {}, |
|
`classList.add('d-none')`, |
|
`classList.add('d-none')`, |
|
`does not transform unqualified classList identifiers`) |
|
|
|
xdescribe('...with mixed display and non-display classes', () => { |
|
defineInlineTest(transform, {}, |
|
`this.classList.add('d-none', 'x-foo')`, |
|
`this.hidden = true;\nthis.classList.add('x-foo')`) |
|
}) |
|
}) |
|
|
|
describe(`classList.remove('d-*') => {hidden = ...}`, () => { |
|
defineInlineTest(transform, {}, |
|
`this.classList.remove('d-none')`, |
|
`this.hidden = false`, |
|
`classList.remove('d-none') => {hidden = false}`) |
|
|
|
for (const klass of SHOW) { |
|
defineInlineTest(transform, {}, |
|
`this.classList.remove('${klass}')`, |
|
`this.hidden = true`, |
|
`classList.add('${klass}') => {hidden = true}`) |
|
} |
|
|
|
xdescribe('...with mixed display and non-display classes', () => { |
|
defineInlineTest(transform, {}, |
|
`this.classList.remove('d-none', 'x-foo')`, |
|
`this.hidden = false;\nthis.classList.add('x-foo')`) |
|
}) |
|
}) |
|
|
|
describe(`classList.toggle('d-*') => {hidden = ...}`, () => { |
|
defineInlineTest(transform, {}, |
|
`this.classList.toggle('d-none', true)`, |
|
`this.hidden = true`, |
|
`classList.toggle('d-none', true) => {hidden = true}`) |
|
defineInlineTest(transform, {}, |
|
`this.classList.toggle('d-none', false)`, |
|
`this.hidden = false`, |
|
`classList.toggle('d-none', false) => {hidden = false}`) |
|
defineInlineTest(transform, {}, |
|
`this.classList.toggle('d-none', x !== 1)`, |
|
`this.hidden = x !== 1`, |
|
`classList.toggle('d-none', <expression>) => {hidden = <expression>}`) |
|
|
|
for (const klass of SHOW) { |
|
defineInlineTest(transform, {}, |
|
`this.classList.toggle('${klass}', x === 1)`, |
|
`this.hidden = !(x === 1)`, |
|
`classList.toggle('${klass}', <expr>) => {hidden = !<expr>}`) |
|
} |
|
}) |
|
|
|
describe(`classList.contains('d-none') => {hidden}`, () => { |
|
defineInlineTest(transform, {}, |
|
`if (this.classList.contains('d-none')) return`, |
|
`if (this.hidden) return`, |
|
`classList.contains('d-none') => {hidden} (in an if statement)`) |
|
defineInlineTest(transform, {}, |
|
`assert(el.classList.contains('d-none'))`, |
|
`assert(el.hidden)`, |
|
`classList.contains('d-none') => {hidden} (in a call expression)`) |
|
}) |