Skip to content

Commit

Permalink
test(plugin-transition): improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzio committed Jul 7, 2021
1 parent 9aee928 commit e9cf826
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
44 changes: 43 additions & 1 deletion packages/fower-plugin-transition/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Parser } from '@fower/parser'
import { Atom } from '@fower/atom'
import plugin from '.'

const { isMatch, handleAtom } = plugin()
const { isMatch, handleAtom, afterAtomStyleCreate } = plugin()
const parser = new Parser({ transitionCommon: true })

test('isMatch', () => {
Expand Down Expand Up @@ -113,3 +113,45 @@ test('easeLinear', () => {
)
expect(atom.style.transitionTimingFunction).toEqual('linear')
})

describe('afterAtomStyleCreate', () => {
test('atom.length = 0', () => {
parser.atoms = []
afterAtomStyleCreate?.(parser)
})

test('no transition prop', () => {
parser.atoms = [
new Atom({
propKey: 'p-10',
propValue: true,
}),
]
afterAtomStyleCreate?.(parser)
expect(parser.atoms.length).toEqual(1)
})

test('no transition prop', () => {
parser.atoms = [
new Atom({
propKey: 'easeIn',
propValue: true,
}),
]
afterAtomStyleCreate?.(parser)
expect(parser.atoms.length).toEqual(1)
})

test('set default duration and timing', () => {
parser.atoms = [
new Atom({
propKey: 'transitionAll',
propValue: true,
}),
]
afterAtomStyleCreate?.(parser)
expect(parser.atoms.length).toEqual(3)
expect(parser.atoms[1].id).toEqual('transition-duration-200')
expect(parser.atoms[2].id).toEqual('easeInOut')
})
})
3 changes: 1 addition & 2 deletions packages/fower-plugin-transition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export function toStyle(atom: Atom, parser: Parser): any {
if (timingReg.test(key)) {
return { [`${prefix}TimingFunction`]: easeMaps[key.toLowerCase()] }
}

return { transition: value }
}

export default (): FowerPlugin => {
Expand All @@ -63,6 +61,7 @@ export default (): FowerPlugin => {
if (!matched) return

const hasTransition = parser.atoms.find((i) => transitionReg.test(i.key))

if (!hasTransition) return

/** set default Duration */
Expand Down

0 comments on commit e9cf826

Please sign in to comment.