Last active
December 7, 2020 16:24
-
-
Save vojtech-cerveny/bb3e24886b7b7127e8b5ad62569177d9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const incrementBack = (context) => context.back + 1; | |
const isAnonymous = (context) => context.anonymous === true; | |
const isLoggedIn = (context) => context.anonymous === false; | |
const adcoMachine = Machine({ | |
id: 'wizard', | |
initial: 'buying_stuff', | |
context: { | |
back: 0, | |
modal_confirmed: null, | |
}, | |
states: { | |
buying_stuff: { | |
initial: 'start', | |
context: { | |
anonymous: true, | |
}, | |
on: { | |
LOG: { | |
target: 'buying_stuff.hist', | |
actions: assign((context) => ({ anonymous: !isAnonymous(context) })), | |
cond: !isAnonymous, | |
}, | |
}, | |
states: { | |
start: { | |
id: 'buying_stuff', | |
on: { | |
BOM_UPLOAD: 'uploaded_bom', | |
}, | |
meta: { | |
test: async (plan) => { | |
console.log('Do prdeleeeeee'); | |
console.log(plan.state.context.anonymous); | |
await (await $('[data-qa-id="bom-upload"]')).waitForDisplayed(); | |
if (plan.state.context.anonymous) { | |
await ( | |
await $('//button[contains(text(), "Log in")]') | |
).waitForDisplayed(); | |
} else { | |
await ( | |
await $('//button[contains(text(), "Log out")]') | |
).waitForDisplayed(); | |
} | |
}, | |
}, | |
}, | |
uploaded_bom: { | |
on: { | |
CLICK_BACK: { | |
target: 'start', | |
actions: assign({ back: incrementBack }), | |
}, | |
REQUEST_QUOTE: 'parts_proposal', | |
}, | |
meta: { | |
test: async () => { | |
await ( | |
await browser.$('[data-qa-id="back-button"]') | |
).waitForDisplayed(); | |
await (await $('[data-qa-id="cm-button"]')).waitForDisplayed(); | |
}, | |
}, | |
}, | |
parts_proposal: { | |
on: { | |
CLICK_BACK: 'modal', | |
CONTINUE: 'board_details', | |
}, | |
meta: { | |
test: async () => { | |
await (await $('[data-qa-id="estimated-price"]')).waitForDisplayed(); | |
}, | |
}, | |
}, | |
modal: { | |
on: { | |
MODAL_CONFIRM: { | |
target: 'uploaded_bom', | |
actions: assign({ modal_confirmed: true }), | |
}, | |
MODAL_CANCEL: { | |
target: 'parts_proposal', | |
actions: assign({ modal_confirmed: false }), | |
}, | |
}, | |
meta: { | |
test: async () => { | |
await (await $('div.c-modal-header')).waitForDisplayed(); | |
}, | |
}, | |
}, | |
board_details: { | |
on: { | |
CLICK_BACK: { | |
target: 'parts_proposal', | |
actions: assign({ back: incrementBack }), | |
}, | |
CONTINUE: 'assembly_options', | |
}, | |
}, | |
assembly_options: { | |
on: { | |
CLICK_BACK: { | |
target: 'board_details', | |
actions: assign({ back: incrementBack }), | |
}, | |
CONTINUE: 'final_quote', | |
}, | |
}, | |
final_quote: { | |
on: { | |
CLICK_BACK: { | |
target: 'board_details', | |
actions: assign({ back: incrementBack }), | |
}, | |
CONFIRM: 'billing_details', | |
}, | |
}, | |
billing_details: { | |
on: { | |
CLICK_BACK: { | |
target: 'final_quote', | |
actions: assign({ back: incrementBack }), | |
}, | |
PAY: 'thank_you', | |
}, | |
}, | |
thank_you: { | |
type: 'final', | |
}, | |
hist: { | |
type: 'history' | |
} | |
}, | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment