Skip to content

Instantly share code, notes, and snippets.

@jf423
Last active May 5, 2021 09:12
Show Gist options
  • Save jf423/4a59454e7bf38b8cf6bbc8abed34ea2e to your computer and use it in GitHub Desktop.
Save jf423/4a59454e7bf38b8cf6bbc8abed34ea2e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const LevelMachine = Machine({
id: 'Level',
initial: 'default',
states: {
default: {
initial: 'initial',
states: {
initial: {
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_HEADER_CONTENT.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_HEADER_AVATAR.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_CAROUSEL_CONTENT.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_MISSION_CONTENT.ID)).toBeInTheDocument()
},
},
},
},
on: {
RERENDER_LOADING: 'loading',
RERENDER_EMPTY: 'empty',
RERENDER_SUCCESS: 'success',
},
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_CONTAINER.ID)).toBeInTheDocument()
},
},
},
loading: {
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_CAROUSEL_LOADING.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_MISSION_LOADING.ID)).toBeInTheDocument()
},
},
},
empty: {
meta: {
test: ({ getByTestId, queryByTestId }) => {
expect(getByTestId(LEVEL_CAROUSEL_CONTENT.ID)).toBeInTheDocument()
expect(getByTestId(LEVEL_MISSION_CONTENT.ID)).toBeInTheDocument()
expect(queryByTestId(LEVEL_CAROUSEL_LOADING.ID)).not.toBeInTheDocument()
expect(queryByTestId(LEVEL_MISSION_LOADING.ID)).not.toBeInTheDocument()
},
},
},
success: {
on: {
OPEN_LEVEL_MODAL: 'openModal',
},
meta: {
test: ({ getByTestId }) => {
const {
data: { nickname, avatar },
} = GET_USER_INFO
const {
data: { user_level: currentLevel, register_day: registerDay, level: totalLevel },
} = GET_USER_LEVEL
const currentTask = totalLevel?.[currentLevel]?.task
expect(getByTestId(LEVEL_HEADER_AVATAR.ID)).toHaveAttribute('src', avatar)
expect(getByTestId(LEVEL_HEADER_NAME.ID)).toHaveTextContent(nickname)
expect(getByTestId(LEVEL_HEADER_REGISTER_DAY.ID)).toHaveTextContent(registerDay)
expect(getByTestId(LEVEL_MISSION_LIST.ID).children).toHaveLength(currentTask.length)
},
},
},
openModal: {
on: {
CLOSE_LEVEL_MODAL: 'closeModal',
},
meta: {
test: ({ getByTestId }) => {
expect(getByTestId(LEVEL_MODAL_CONTAINER.ID)).toBeInTheDocument()
},
},
},
closeModal: {
meta: {
test: ({ queryByTestId }) => {
expect(queryByTestId(LEVEL_MODAL_CONTAINER.ID)).not.toBeInTheDocument()
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment