123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- import {Organization} from 'sentry-fixture/organization';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
- import {textWithMarkupMatcher} from 'sentry-test/utils';
- import {
- platformProductAvailability,
- ProductSelection,
- ProductSolution,
- } from 'sentry/components/onboarding/productSelection';
- describe('Onboarding Product Selection', function () {
- const organization = Organization({
- features: ['session-replay', 'performance-view', 'profiling-view'],
- });
- it('renders default state', async function () {
- const {router, routerContext} = initializeOrg({
- router: {
- location: {
- query: {
- product: [
- ProductSolution.PERFORMANCE_MONITORING,
- ProductSolution.SESSION_REPLAY,
- ],
- },
- },
- params: {},
- },
- });
- render(<ProductSelection organization={organization} platform="javascript-react" />, {
- context: routerContext,
- });
- // Introduction
- expect(
- screen.getByText(
- textWithMarkupMatcher(/In this quick guide you’ll use npm or yarn/)
- )
- ).toBeInTheDocument();
- expect(screen.queryByText('Prefer to set up Sentry using')).not.toBeInTheDocument();
- // Error monitoring shall be checked and disabled by default
- expect(screen.getByRole('checkbox', {name: 'Error Monitoring'})).toBeChecked();
- // Tooltip with explanation shall be displayed on hover
- await userEvent.hover(screen.getByRole('checkbox', {name: 'Error Monitoring'}));
- expect(
- await screen.findByText(/Let's admit it, we all have errors/)
- ).toBeInTheDocument();
- // Try to uncheck error monitoring
- await userEvent.click(screen.getByRole('checkbox', {name: 'Error Monitoring'}));
- await waitFor(() => expect(router.push).not.toHaveBeenCalled());
- // Performance monitoring shall be checked and enabled by default
- expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeChecked();
- expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeEnabled();
- // Tooltip with explanation shall be displayed on hover
- await userEvent.hover(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
- expect(
- await screen.findByText(/Automatic performance issue detection/)
- ).toBeInTheDocument();
- // Uncheck performance monitoring
- await userEvent.click(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
- await waitFor(() =>
- expect(router.replace).toHaveBeenCalledWith({
- pathname: undefined,
- query: {product: [ProductSolution.SESSION_REPLAY]},
- })
- );
- // Session replay shall be checked and enabled by default
- expect(screen.getByRole('checkbox', {name: 'Session Replay'})).toBeChecked();
- expect(screen.getByRole('checkbox', {name: 'Session Replay'})).toBeEnabled();
- // Uncheck sesseion replay
- await userEvent.click(screen.getByRole('checkbox', {name: 'Session Replay'}));
- await waitFor(() =>
- expect(router.replace).toHaveBeenCalledWith({
- pathname: undefined,
- query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
- })
- );
- // Tooltip with explanation shall be displayed on hover
- await userEvent.hover(screen.getByRole('checkbox', {name: 'Session Replay'}));
- expect(
- await screen.findByText(/Video-like reproductions of user sessions/)
- ).toBeInTheDocument();
- });
- it('renders for Loader Script', async function () {
- const {routerContext} = initializeOrg({
- router: {
- location: {
- query: {
- product: [
- ProductSolution.PERFORMANCE_MONITORING,
- ProductSolution.SESSION_REPLAY,
- ],
- },
- },
- params: {},
- },
- });
- const skipLazyLoader = jest.fn();
- render(
- <ProductSelection
- organization={organization}
- lazyLoader
- skipLazyLoader={skipLazyLoader}
- platform="javascript-react"
- />,
- {
- context: routerContext,
- }
- );
- // Introduction
- expect(
- screen.getByText(
- textWithMarkupMatcher(/In this quick guide you’ll use our Loader Script/)
- )
- ).toBeInTheDocument();
- expect(
- screen.getByText(
- textWithMarkupMatcher(/Prefer to set up Sentry using npm or yarn\?/)
- )
- ).toBeInTheDocument();
- await userEvent.click(screen.getByText('Go here'));
- expect(skipLazyLoader).toHaveBeenCalledTimes(1);
- });
- it('renders disabled product', async function () {
- const {router, routerContext} = initializeOrg({
- router: {
- location: {
- query: {product: [ProductSolution.SESSION_REPLAY]},
- },
- params: {},
- },
- });
- const disabledProducts = {
- [ProductSolution.PERFORMANCE_MONITORING]: {
- reason: 'Product unavailable in this SDK version',
- },
- };
- render(
- <ProductSelection
- organization={organization}
- disabledProducts={disabledProducts}
- platform="javascript-react"
- />,
- {
- context: routerContext,
- }
- );
- // Performance Monitoring shall be unchecked and disabled by default
- expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeDisabled();
- expect(
- screen.getByRole('checkbox', {name: 'Performance Monitoring'})
- ).not.toBeChecked();
- await userEvent.hover(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
- // A tooltip with explanation why the option is disabled shall be displayed on hover
- expect(
- await screen.findByText(
- disabledProducts[ProductSolution.PERFORMANCE_MONITORING].reason
- )
- ).toBeInTheDocument();
- await userEvent.click(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
- // Try to uncheck performance monitoring
- await waitFor(() => expect(router.push).not.toHaveBeenCalled());
- });
- it('does not render Session Replay', async function () {
- platformProductAvailability['javascript-react'] = [
- ProductSolution.PERFORMANCE_MONITORING,
- ];
- const {router, routerContext} = initializeOrg({
- router: {
- location: {
- query: {product: [ProductSolution.SESSION_REPLAY]},
- },
- params: {},
- },
- });
- render(<ProductSelection organization={organization} platform="javascript-react" />, {
- context: routerContext,
- });
- expect(
- screen.queryByRole('checkbox', {name: 'Session Replay'})
- ).not.toBeInTheDocument();
- // router.replace is called to remove session-replay from query
- await waitFor(() =>
- expect(router.replace).toHaveBeenCalledWith({
- pathname: undefined,
- query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
- })
- );
- });
- it('render Profiling', async function () {
- const {router, routerContext} = initializeOrg({
- router: {
- location: {
- query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
- },
- params: {},
- },
- });
- render(<ProductSelection organization={organization} platform="python-django" />, {
- context: routerContext,
- });
- expect(screen.getByRole('checkbox', {name: 'Profiling'})).toBeInTheDocument();
- // router.replace is called to add profiling from query
- await waitFor(() =>
- expect(router.replace).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- product: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
- },
- })
- );
- });
- it('renders npm & yarn info text', function () {
- const {routerContext} = initializeOrg({
- router: {
- location: {
- query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
- },
- params: {},
- },
- });
- render(<ProductSelection organization={organization} platform="javascript-react" />, {
- context: routerContext,
- });
- expect(screen.queryByText('npm')).toBeInTheDocument();
- expect(screen.queryByText('yarn')).toBeInTheDocument();
- });
- it('does not render npm & yarn info text', function () {
- const {routerContext} = initializeOrg({
- router: {
- location: {
- query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
- },
- params: {},
- },
- });
- render(<ProductSelection organization={organization} platform="python-django" />, {
- context: routerContext,
- });
- expect(screen.queryByText('npm')).not.toBeInTheDocument();
- expect(screen.queryByText('yarn')).not.toBeInTheDocument();
- });
- });
|