Skip to content

Instantly share code, notes, and snippets.

@jf423
Created May 5, 2021 11:01
Show Gist options
  • Save jf423/989b58eabbd0d2401235ef48ee2ac390 to your computer and use it in GitHub Desktop.
Save jf423/989b58eabbd0d2401235ef48ee2ac390 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const LevelItemMachine = Machine({
id: 'LevelItem',
initial: 'default',
states: {
default: {
on: {
RERENDER_EMPTY: 'empty',
RERENDER_SUCCESS: 'success',
},
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_CAROUSEL_ITEM.ID)).toBeInTheDocument()
},
},
},
empty: {
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_CAROUSEL_ITEM.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_CAROUSEL_ITEM_ICON.ID)).toBeInTheDocument()
},
},
},
success: {
initial: 'complete',
states: {
complete: {
meta: {
test: ({ getByTestId }) => {
const LevelItemIndex = 0
const {
data: { level },
} = GET_USER_LEVEL
const { satisfy_img: complete } = level[LevelItemIndex]
expect(getByTestId(LEVEL_CAROUSEL_ITEM_ICON.ID)).toHaveAttribute('src', complete)
},
},
},
incomplete: {
meta: {
test: ({ getByTestId }) => {
const LevelItemIndex = 0
const {
data: { level },
} = GET_USER_LEVEL
const { not_satisfy_img: incomplete } = level[LevelItemIndex]
expect(getByTestId(LEVEL_CAROUSEL_ITEM_ICON.ID)).toHaveAttribute('src', incomplete)
},
},
},
},
on: {
RERENDER_SUCCESS_WITH_COMPLETE: 'success.complete',
RERENDER_SUCCESS_WITH_INCOMPLETE: 'success.incomplete',
},
meta: {
test: ({ getByTestId }) => {
const LevelItemIndex = 0
const {
data: { level: totalLevel },
} = GET_USER_LEVEL
const { badge_name: name, title } = totalLevel[LevelItemIndex]
expect(getByTestId(LEVEL_CAROUSEL_ITEM_RANK.ID)).toHaveTextContent(title)
expect(getByTestId(LEVEL_CAROUSEL_ITEM_NAME.ID)).toHaveTextContent(name)
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment