|
1 | 1 | import React from 'react'; |
2 | 2 | import { expect } from 'chai'; |
3 | 3 | import sinon from 'sinon'; |
4 | | -import { screen, within, userEvent } from '@mongodb-js/testing-library-compass'; |
| 4 | +import { |
| 5 | + screen, |
| 6 | + within, |
| 7 | + userEvent, |
| 8 | + renderWithConnections, |
| 9 | +} from '@mongodb-js/testing-library-compass'; |
5 | 10 | import type { PreferencesAccess } from 'compass-preferences-model'; |
6 | 11 | import { createSandboxFromDefaultPreferences } from 'compass-preferences-model'; |
7 | 12 | import { CrudToolbar } from './crud-toolbar'; |
8 | 13 | import { renderWithQueryBar } from '../../test/render-with-query-bar'; |
| 14 | +import { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry'; |
| 15 | +import { ExperimentTestGroup } from '@mongodb-js/compass-telemetry/provider'; |
9 | 16 |
|
10 | 17 | const noop = () => { |
11 | 18 | /* noop */ |
@@ -821,4 +828,170 @@ describe('CrudToolbar Component', function () { |
821 | 828 | expect(() => screen.getByTestId('insight-badge-button')).to.throw(); |
822 | 829 | }); |
823 | 830 | }); |
| 831 | + |
| 832 | + // @experiment Skills in Atlas | Jira Epic: CLOUDP-346311 |
| 833 | + describe('Atlas Skills Banner', function () { |
| 834 | + function renderCrudToolbarWithExperimentation(experimentationOptions?: { |
| 835 | + isInExperiment?: boolean; |
| 836 | + isInVariant?: boolean; |
| 837 | + }) { |
| 838 | + const mockUseAssignment = sinon.stub(); |
| 839 | + const mockUseTrackInSample = sinon.stub(); |
| 840 | + const mockAssignExperiment = sinon.stub(); |
| 841 | + const mockGetAssignment = sinon.stub(); |
| 842 | + |
| 843 | + const commonAsyncStatus = { |
| 844 | + asyncStatus: null, |
| 845 | + error: null, |
| 846 | + isLoading: false, |
| 847 | + isError: false, |
| 848 | + isSuccess: true, |
| 849 | + }; |
| 850 | + |
| 851 | + // Configure the mock based on experiment options |
| 852 | + if (experimentationOptions?.isInExperiment) { |
| 853 | + if (experimentationOptions?.isInVariant) { |
| 854 | + mockUseAssignment.returns({ |
| 855 | + assignment: { |
| 856 | + assignmentData: { |
| 857 | + variant: ExperimentTestGroup.atlasSkillsVariant, |
| 858 | + }, |
| 859 | + }, |
| 860 | + ...commonAsyncStatus, |
| 861 | + }); |
| 862 | + } else { |
| 863 | + mockUseAssignment.returns({ |
| 864 | + assignment: { |
| 865 | + assignmentData: { |
| 866 | + variant: ExperimentTestGroup.atlasSkillsControl, |
| 867 | + }, |
| 868 | + }, |
| 869 | + ...commonAsyncStatus, |
| 870 | + }); |
| 871 | + } |
| 872 | + } else { |
| 873 | + mockUseAssignment.returns({ |
| 874 | + assignment: null, |
| 875 | + ...commonAsyncStatus, |
| 876 | + }); |
| 877 | + } |
| 878 | + |
| 879 | + mockUseTrackInSample.returns(commonAsyncStatus); |
| 880 | + mockAssignExperiment.returns(Promise.resolve(null)); |
| 881 | + mockGetAssignment.returns(Promise.resolve(null)); |
| 882 | + |
| 883 | + const renderResult = renderWithConnections( |
| 884 | + <CompassExperimentationProvider |
| 885 | + useAssignment={mockUseAssignment} |
| 886 | + useTrackInSample={mockUseTrackInSample} |
| 887 | + assignExperiment={mockAssignExperiment} |
| 888 | + getAssignment={mockGetAssignment} |
| 889 | + > |
| 890 | + <CrudToolbar |
| 891 | + activeDocumentView="List" |
| 892 | + count={55} |
| 893 | + end={20} |
| 894 | + getPage={noop} |
| 895 | + insertDataHandler={noop} |
| 896 | + loadingCount={false} |
| 897 | + isFetching={false} |
| 898 | + docsPerPage={25} |
| 899 | + isWritable |
| 900 | + instanceDescription="" |
| 901 | + onApplyClicked={noop} |
| 902 | + onResetClicked={noop} |
| 903 | + onUpdateButtonClicked={noop} |
| 904 | + onDeleteButtonClicked={noop} |
| 905 | + onExpandAllClicked={noop} |
| 906 | + onCollapseAllClicked={noop} |
| 907 | + openExportFileDialog={noop} |
| 908 | + outdated={false} |
| 909 | + page={0} |
| 910 | + readonly={false} |
| 911 | + refreshDocuments={noop} |
| 912 | + resultId="123" |
| 913 | + start={0} |
| 914 | + viewSwitchHandler={noop} |
| 915 | + updateMaxDocumentsPerPage={noop} |
| 916 | + queryLimit={0} |
| 917 | + querySkip={0} |
| 918 | + /> |
| 919 | + </CompassExperimentationProvider>, |
| 920 | + { preferences: preferences.getPreferences() } |
| 921 | + ); |
| 922 | + return renderResult; |
| 923 | + } |
| 924 | + |
| 925 | + it('should show skills banner when user is in experiment and in variant', function () { |
| 926 | + renderCrudToolbarWithExperimentation({ |
| 927 | + isInExperiment: true, |
| 928 | + isInVariant: true, |
| 929 | + }); |
| 930 | + |
| 931 | + expect( |
| 932 | + screen.getByText( |
| 933 | + 'Practice creating, reading, updating, and deleting documents efficiently.' |
| 934 | + ) |
| 935 | + ).to.be.visible; |
| 936 | + const goToSkillsButton = screen.getByRole('link', { |
| 937 | + name: /go to skills/i, |
| 938 | + }); |
| 939 | + expect(goToSkillsButton).to.be.visible; |
| 940 | + expect(screen.getByLabelText('Award Icon')).to.be.visible; |
| 941 | + |
| 942 | + expect(goToSkillsButton.getAttribute('href')).to.equal( |
| 943 | + 'https://learn.mongodb.com/courses/crud-operations-in-mongodb?team=growth' |
| 944 | + ); |
| 945 | + }); |
| 946 | + |
| 947 | + it('should not show skills banner when user is in experiment but not in variant', function () { |
| 948 | + renderCrudToolbarWithExperimentation({ |
| 949 | + isInExperiment: true, |
| 950 | + isInVariant: false, |
| 951 | + }); |
| 952 | + |
| 953 | + expect( |
| 954 | + screen.queryByText( |
| 955 | + 'Practice creating, reading, updating, and deleting documents efficiently.' |
| 956 | + ) |
| 957 | + ).to.not.exist; |
| 958 | + expect(screen.queryByRole('link', { name: /go to skills/i })).to.not |
| 959 | + .exist; |
| 960 | + }); |
| 961 | + |
| 962 | + it('should not show skills banner by default when user is not in experiment', function () { |
| 963 | + renderCrudToolbarWithExperimentation({ |
| 964 | + isInExperiment: false, |
| 965 | + isInVariant: false, |
| 966 | + }); |
| 967 | + |
| 968 | + expect( |
| 969 | + screen.queryByText( |
| 970 | + 'Practice creating, reading, updating, and deleting documents efficiently.' |
| 971 | + ) |
| 972 | + ).to.not.exist; |
| 973 | + expect(screen.queryByRole('link', { name: /go to skills/i })).to.not |
| 974 | + .exist; |
| 975 | + }); |
| 976 | + |
| 977 | + it('should dismiss banner when close button is clicked', function () { |
| 978 | + renderCrudToolbarWithExperimentation({ |
| 979 | + isInExperiment: true, |
| 980 | + isInVariant: true, |
| 981 | + }); |
| 982 | + |
| 983 | + const closeButton = screen.getByRole('button', { |
| 984 | + name: 'Dismiss Skills Banner', |
| 985 | + }); |
| 986 | + |
| 987 | + expect(closeButton).to.be.visible; |
| 988 | + userEvent.click(closeButton); |
| 989 | + |
| 990 | + expect( |
| 991 | + screen.queryByText( |
| 992 | + 'Practice creating, reading, updating, and deleting documents efficiently.' |
| 993 | + ) |
| 994 | + ).to.not.exist; |
| 995 | + }); |
| 996 | + }); |
824 | 997 | }); |
0 commit comments