Skip to content

Instantly share code, notes, and snippets.

@jf423
Created January 2, 2021 13:13
Show Gist options
  • Save jf423/9e59e6d369a7ca71cd3554b5e6864f84 to your computer and use it in GitHub Desktop.
Save jf423/9e59e6d369a7ca71cd3554b5e6864f84 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const contentMachine = Machine({
id: 'content',
initial: 'initiating',
states: {
initiating: {
on: {
FINISHED_INITIAL: 'login'
},
meta: {
test: ({ queryByTestId }) => {
const loading = queryByTestId(APP_SELECTOR.PAGE_LOADING_ICON.ID);
expect(loading).toBeInTheDocument();
}
}
},
login: {
on: {
RENDER_DEFAULT: 'default',
RENDER_WITH_FLAG: 'flags',
RENDER_UNLICENSED: 'unlicensed',
RENDER_MAINTENANCE: 'maintenance',
RENDER_REDIRECT: 'redirect'
},
meta: {
test: ({ queryByTestId }) => {
const loading = queryByTestId(APP_SELECTOR.PAGE_LOADING_ICON.ID);
const container = queryByTestId(LOGIN_PAGE_SELECTOR.LOGIN_CONTAINER.ID);
const tenant = queryByTestId(LOGIN_PAGE_SELECTOR.TENANT_INPUT.ID);
const username = queryByTestId(LOGIN_PAGE_SELECTOR.USERNAME_INPUT.ID);
const password = queryByTestId(LOGIN_PAGE_SELECTOR.PASSWORD_INPUT.ID);
const button = queryByTestId(LOGIN_PAGE_SELECTOR.LOGIN_BUTTON.ID);
expect(loading).not.toBeInTheDocument();
expect(container).toBeInTheDocument();
expect(tenant).toBeInTheDocument();
expect(username).toBeInTheDocument();
expect(password).toBeInTheDocument();
expect(button).toBeInTheDocument();
}
}
},
default: {
meta: {
test: ({ queryByTestId }) => {
const getStartedPage = queryByTestId(GET_STARTED_SELECTOR.GET_STARTED_CONTAINER.ID);
expect(getStartedPage).toBeInTheDocument();
}
}
},
flags: {
meta: {
test: ({ queryByTestId }) => {
const appliancesPage = queryByTestId(APPLIANCES_SELECTOR.APPLIANCES_CONTAINER.ID);
expect(appliancesPage).not.toBeInTheDocument();
const getStartedPage = queryByTestId(GET_STARTED_SELECTOR.GET_STARTED_CONTAINER.ID);
expect(getStartedPage).toBeInTheDocument();
}
}
},
unlicensed: {
meta: {
test: ({ queryByTestId }) => {
const unLicensedPage = queryByTestId(UNLICENSED_PAGE_SELECTOR.UNLICENSED_PAGE_CONTAINER.ID);
expect(unLicensedPage).toBeInTheDocument();
}
}
},
maintenance: {
meta: {
test: ({ queryByTestId }) => {
const maintenancePage = queryByTestId(MAINTENANCE_PAGE_SELECTOR.MAINTENANCE_PAGE_CONTAINER.ID);
expect(maintenancePage).toBeInTheDocument();
}
}
},
redirect: {
meta: {
test: ({ queryByTestId }) => {
const appliancesPath = ROUTES_CONFIG.filter(({ id }) => id === PAGE_KEY.APPLIANCES)[0].path;
contentComponent.rerender(renderContent({
...initialledStore,
app: { ...initialledAppStore, redirectLocation: appliancesPath }
}));
history.push(appliancesPath);
const appliancesPage = queryByTestId(APPLIANCES_SELECTOR.APPLIANCES_CONTAINER.ID);
expect(appliancesPage).toBeInTheDocument();
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment