123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- } from 'sentry-test/reactTestingLibrary';
- import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
- import * as useRecentCreatedProjectHook from 'sentry/components/onboarding/useRecentCreatedProject';
- import {PlatformKey} from 'sentry/data/platformCategories';
- import {OnboardingProjectStatus, Project} from 'sentry/types';
- import Onboarding from 'sentry/views/onboarding/onboarding';
- describe('Onboarding', function () {
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('renders the welcome page', function () {
- const routeParams = {
- step: 'welcome',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- expect(screen.getByLabelText('Start')).toBeInTheDocument();
- expect(screen.getByLabelText('Invite Team')).toBeInTheDocument();
- });
- it('renders the select platform step', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- expect(
- await screen.findByText('Select the platform you want to monitor')
- ).toBeInTheDocument();
- });
- it('renders the setup docs step', async function () {
- const nextJsProject: Project = TestStubs.Project({
- platform: 'javascript-nextjs',
- id: '2',
- slug: 'javascript-nextjs-slug',
- });
- const routeParams = {
- step: 'setup-docs',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- router: {
- params: routeParams,
- },
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${nextJsProject.slug}/docs/javascript-nextjs-with-error-monitoring/`,
- body: null,
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${nextJsProject.slug}/`,
- body: [nextJsProject],
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${nextJsProject.slug}/issues/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${nextJsProject.slug}/keys/`,
- method: 'GET',
- body: [TestStubs.ProjectKeys()[0]],
- });
- jest
- .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
- .mockImplementation(() => {
- return {
- ...nextJsProject,
- firstError: false,
- firstTransaction: false,
- hasReplays: false,
- hasSessions: false,
- olderThanOneHour: false,
- firstIssue: undefined,
- };
- });
- render(
- <OnboardingContextProvider
- value={{
- selectedSDK: {
- key: nextJsProject.slug as PlatformKey,
- type: 'framework',
- language: 'javascript',
- category: 'browser',
- },
- projects: {
- [nextJsProject.id]: {
- slug: nextJsProject.slug,
- status: OnboardingProjectStatus.WAITING,
- firstIssueId: undefined,
- },
- },
- }}
- >
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- expect(await screen.findByText('Configure Next.js SDK')).toBeInTheDocument();
- });
- it('renders SDK data removal modal when going back', async function () {
- const reactProject: Project = TestStubs.Project({
- platform: 'javascript-react',
- id: '2',
- slug: 'javascript-react-slug',
- firstTransactionEvent: false,
- firstEvent: false,
- hasReplays: false,
- hasSessions: false,
- });
- const routeParams = {
- step: 'setup-docs',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- organization: {
- features: ['onboarding-project-deletion-on-back-click'],
- },
- router: {
- params: routeParams,
- },
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${reactProject.slug}/`,
- body: [reactProject],
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${reactProject.slug}/keys/`,
- method: 'GET',
- body: [TestStubs.ProjectKeys()[0]],
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${reactProject.slug}/issues/`,
- body: [],
- });
- jest
- .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
- .mockImplementation(() => {
- return {
- ...reactProject,
- firstError: false,
- firstTransaction: false,
- hasReplays: false,
- hasSessions: false,
- olderThanOneHour: false,
- firstIssue: undefined,
- };
- });
- render(
- <OnboardingContextProvider
- value={{
- selectedSDK: {
- key: reactProject.slug as PlatformKey,
- type: 'framework',
- language: 'javascript',
- category: 'browser',
- },
- projects: {
- [reactProject.id]: {
- slug: reactProject.slug,
- status: OnboardingProjectStatus.WAITING,
- firstIssueId: undefined,
- },
- },
- }}
- >
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- // Await for the docs to be loaded
- await screen.findByText('Configure React SDK');
- renderGlobalModal();
- // Click on back button
- await userEvent.click(screen.getByRole('button', {name: 'Back'}));
- // Await for the modal to be open
- expect(
- await screen.findByText(/Are you sure you want to head back?/)
- ).toBeInTheDocument();
- // Close modal
- await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
- });
- it('does not render SDK data removal modal when going back', async function () {
- const reactProject: Project = TestStubs.Project({
- platform: 'javascript-react',
- id: '2',
- slug: 'javascript-react-slug',
- });
- const routeParams = {
- step: 'setup-docs',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- organization: {
- features: ['onboarding-project-deletion-on-back-click'],
- },
- router: {
- params: routeParams,
- },
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${reactProject.slug}/`,
- body: [reactProject],
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${reactProject.slug}/keys/`,
- method: 'GET',
- body: [TestStubs.ProjectKeys()[0]],
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${reactProject.slug}/issues/`,
- body: [],
- });
- jest
- .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
- .mockImplementation(() => {
- return {
- ...reactProject,
- firstError: false,
- firstTransaction: false,
- hasReplays: false,
- hasSessions: true,
- olderThanOneHour: false,
- firstIssue: undefined,
- };
- });
- render(
- <OnboardingContextProvider
- value={{
- selectedSDK: {
- key: reactProject.slug as PlatformKey,
- type: 'framework',
- language: 'javascript',
- category: 'browser',
- },
- projects: {
- [reactProject.id]: {
- slug: reactProject.slug,
- status: OnboardingProjectStatus.WAITING,
- firstIssueId: undefined,
- },
- },
- }}
- >
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- // Await for the docs to be loaded
- await screen.findByText('Configure React SDK');
- renderGlobalModal();
- // Click on back button
- await userEvent.click(screen.getByRole('button', {name: 'Back'}));
- // Await for the modal to be open
- expect(
- screen.queryByText(/Are you sure you want to head back?/)
- ).not.toBeInTheDocument();
- });
- it('renders framework selection modal if vanilla js is selected', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- organization: {
- features: ['onboarding-sdk-selection'],
- },
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- renderGlobalModal();
- // Select the JavaScript platform
- await userEvent.click(screen.getByTestId('platform-javascript'));
- // Click on 'configure SDK' button
- await userEvent.click(screen.getByRole('button', {name: 'Configure SDK'}));
- // Modal is open
- await screen.findByText('Do you use a framework?');
- // Close modal
- await userEvent.click(screen.getByRole('button', {name: 'Skip'}));
- });
- it('does not render framework selection modal if vanilla js is NOT selected', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {routerProps, routerContext, organization} = initializeOrg({
- organization: {
- features: ['onboarding-sdk-selection'],
- },
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding {...routerProps} />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- // Select the React platform
- await userEvent.click(screen.getByTestId('platform-javascript-vue'));
- // Click on 'configure SDK' button
- await userEvent.click(screen.getByRole('button', {name: 'Configure SDK'}));
- // Modal shall not be open
- expect(screen.queryByText('Do you use a framework?')).not.toBeInTheDocument();
- });
- });
|