important-noon-13871
05/22/2023, 7:10 AMexport default ({
label,
feature,
featureDetail,
size = 'medium',
} => {
const { t, i18n } = useTranslation();
const userInfo:(userInfoProps|null) = useAppSelector(({ root }) => root.userInfo);
const targetCompanyId:string = useAppSelector(({ root }) => root.targetCompanyId);
const openAirtableLink = () =>{
//formUrl will use userInfo & targetCompanyId to build url
window.open(formUrl, '_blank');
}
return (
<Button
className="account-upgrade-button"
size={size}
label={label || t(`general.btn_upgradeAccount`)}
color={standardColor.secondary}
iconImageSize={16}
iconUrl="./circled-up-2.png"
onButtonClick={openAirtableLink}
/>
);
};
I don't know how to mock a variable, function or hook with cypress, there are only few resource for cypress component testing.
Or maybe I should correct my word, what's the boundary for e2e & component testing in cypress? should I really need it or just always do e2e testing?wonderful-match-15836
05/23/2023, 6:32 PMwonderful-match-15836
05/23/2023, 6:34 PMmagnificent-finland-58048
05/23/2023, 9:26 PMmagnificent-finland-58048
05/23/2023, 9:28 PMmagnificent-finland-58048
05/23/2023, 9:30 PMhttps://cdn.discordapp.com/attachments/1110102483193319455/1110681255596523630/image.png▾
magnificent-finland-58048
05/23/2023, 9:35 PMmagnificent-finland-58048
05/23/2023, 9:40 PMconfigureStore is the mega redux store of the app
we can import it and reuse it in the component tests, and we can also customize it
typescript
Cypress.Commands.add('mount', mount)
const wrappedMount = (
WrappedComponent: React.ReactNode,
theme: ThemeName = 'merchants',
options = {},
): Cypress.Chainable<MountReturn> => {
const wrapped = (
<BrowserRouter>
<ThemeProvider theme={getThemeByName(theme)}>
<GlobalStyles />
{WrappedComponent}
</ThemeProvider>
</BrowserRouter>
)
return cy.mount(wrapped, options)
}
Cypress.Commands.add('wrappedMount', wrappedMount)
const storeWrappedMount = (
WrappedComponent: React.ReactNode,
preLoadedState: DeepPartial<RootState> = {},
theme: ThemeName = 'merchants',
options = {},
): Cypress.Chainable<MountReturn> => {
const wrapped = (
<BrowserRouter>
<ThemeProvider theme={getThemeByName(theme)}>
<GlobalStyles />
<Provider store={configureStore(preLoadedState)}>{WrappedComponent}</Provider>
</ThemeProvider>
</BrowserRouter>
)
return cy.mount(wrapped, options)
}
Cypress.Commands.add('storeWrappedMount', storeWrappedMount)magnificent-finland-58048
05/23/2023, 9:47 PMimportant-noon-13871
05/24/2023, 3:59 AM