Skip to content

Commit bb79c07

Browse files
committed
WIP
1 parent d0cfda3 commit bb79c07

File tree

4 files changed

+233
-78
lines changed

4 files changed

+233
-78
lines changed

package-lock.json

Lines changed: 24 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-generative-ai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
5353
},
5454
"dependencies": {
55-
"@leafygreen-ui/marketing-modal": "^7.0.0",
55+
"@leafygreen-ui/marketing-modal": "^8.0.0",
5656
"@mongodb-js/atlas-service": "^0.55.0",
5757
"@mongodb-js/compass-app-registry": "^9.4.19",
5858
"@mongodb-js/compass-components": "^1.48.0",

packages/compass-generative-ai/src/components/ai-optin-modal.spec.tsx

Lines changed: 146 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ let mockPreferences: PreferencesAccess;
1111
describe('AIOptInModal Component', function () {
1212
beforeEach(async function () {
1313
mockPreferences = await createSandboxFromDefaultPreferences();
14+
15+
// Mock showModal for MarketingModal v8.0.0 which uses HTML dialog element
16+
if (!HTMLDialogElement.prototype.showModal) {
17+
HTMLDialogElement.prototype.showModal = function () {
18+
this.open = true;
19+
};
20+
}
21+
if (!HTMLDialogElement.prototype.close) {
22+
HTMLDialogElement.prototype.close = function () {
23+
this.open = false;
24+
};
25+
}
1426
});
1527

1628
afterEach(function () {
@@ -52,8 +64,7 @@ describe('AIOptInModal Component', function () {
5264
expect(screen.getByText('Not now')).to.exist;
5365
});
5466

55-
// TODO: Re-enable this test once the LG-5416 is released
56-
it.skip('should show the opt in button enabled when project AI setting is enabled', async function () {
67+
it('should show the opt in button enabled when project AI setting is enabled', async function () {
5768
await mockPreferences.savePreferences({
5869
enableGenAIFeaturesAtlasProject: true,
5970
});
@@ -70,12 +81,11 @@ describe('AIOptInModal Component', function () {
7081
</AIOptInModal>
7182
</PreferencesProvider>
7283
);
73-
const button = screen.getByText('Use Natural Language').closest('button');
84+
const button = screen.getByText('Use AI Features').closest('button');
7485
expect(button?.getAttribute('aria-disabled')).to.equal('false');
7586
});
7687

77-
// TODO: Re-enable this test once the LG-5416 is released
78-
it.skip('should disable the opt in button if project AI setting is disabled ', async function () {
88+
it('should disable the opt in button if project AI setting is disabled', async function () {
7989
await mockPreferences.savePreferences({
8090
enableGenAIFeaturesAtlasProject: false,
8191
});
@@ -92,7 +102,137 @@ describe('AIOptInModal Component', function () {
92102
</AIOptInModal>
93103
</PreferencesProvider>
94104
);
95-
const button = screen.getByText('Use Natural Language').closest('button');
105+
const button = screen.getByText('Use AI Features').closest('button');
96106
expect(button?.getAttribute('aria-disabled')).to.equal('true');
97107
});
108+
109+
describe('conditional banner messages', function () {
110+
it('should show warning banner when AI features are disabled', async function () {
111+
await mockPreferences.savePreferences({
112+
enableGenAIFeaturesAtlasProject: false,
113+
enableGenAISampleDocumentPassingOnAtlasProject: false,
114+
});
115+
render(
116+
<PreferencesProvider value={mockPreferences}>
117+
<AIOptInModal
118+
projectId="ab123"
119+
isOptInModalVisible={true}
120+
isOptInInProgress={false}
121+
onOptInModalClose={() => {}}
122+
onOptInClick={() => {}}
123+
/>
124+
</PreferencesProvider>
125+
);
126+
expect(
127+
screen.getByText(
128+
/AI features are disabled for project users with data access/
129+
)
130+
).to.exist;
131+
expect(
132+
screen.getByText(/Project Owners can enable Data Explorer AI features/)
133+
).to.exist;
134+
});
135+
136+
it('should show info banner with correct copy when only the "Sending Sample Field Values in DE Gen AI Features" setting is disabled', async function () {
137+
await mockPreferences.savePreferences({
138+
enableGenAIFeaturesAtlasProject: true,
139+
enableGenAISampleDocumentPassingOnAtlasProject: false,
140+
});
141+
render(
142+
<PreferencesProvider value={mockPreferences}>
143+
<AIOptInModal
144+
projectId="ab123"
145+
isOptInModalVisible={true}
146+
isOptInInProgress={false}
147+
onOptInModalClose={() => {}}
148+
onOptInClick={() => {}}
149+
/>
150+
</PreferencesProvider>
151+
);
152+
expect(
153+
screen.getByText(
154+
/AI features are enabled for project users with data access/
155+
)
156+
).to.exist;
157+
expect(
158+
screen.getByText(
159+
/enable sending sample field values in Data Explorer AI features/
160+
)
161+
).to.exist;
162+
});
163+
164+
it('should show info banner with correct copy when both project settings are enabled', async function () {
165+
await mockPreferences.savePreferences({
166+
enableGenAIFeaturesAtlasProject: true,
167+
enableGenAISampleDocumentPassingOnAtlasProject: true,
168+
});
169+
render(
170+
<PreferencesProvider value={mockPreferences}>
171+
<AIOptInModal
172+
projectId="ab123"
173+
isOptInModalVisible={true}
174+
isOptInInProgress={false}
175+
onOptInModalClose={() => {}}
176+
onOptInClick={() => {}}
177+
/>
178+
</PreferencesProvider>
179+
);
180+
expect(
181+
screen.getByText(
182+
/AI features are enabled for project users with data access/
183+
)
184+
).to.exist;
185+
expect(
186+
screen.getByText(/Project Owners can disable Data Explorer AI features/)
187+
).to.exist;
188+
});
189+
});
190+
191+
describe('button click behavior', function () {
192+
it('should not call onOptInClick when main AI features are disabled', async function () {
193+
let onOptInClickCalled = false;
194+
await mockPreferences.savePreferences({
195+
enableGenAIFeaturesAtlasProject: false,
196+
});
197+
render(
198+
<PreferencesProvider value={mockPreferences}>
199+
<AIOptInModal
200+
projectId="ab123"
201+
isOptInModalVisible={true}
202+
isOptInInProgress={false}
203+
onOptInModalClose={() => {}}
204+
onOptInClick={() => {
205+
onOptInClickCalled = true;
206+
}}
207+
/>
208+
</PreferencesProvider>
209+
);
210+
const button = screen.getByText('Use AI Features');
211+
button.click();
212+
expect(onOptInClickCalled).to.be.false;
213+
});
214+
215+
it('should call onOptInClick when main AI features are enabled', async function () {
216+
let onOptInClickCalled = false;
217+
await mockPreferences.savePreferences({
218+
enableGenAIFeaturesAtlasProject: true,
219+
});
220+
render(
221+
<PreferencesProvider value={mockPreferences}>
222+
<AIOptInModal
223+
projectId="ab123"
224+
isOptInModalVisible={true}
225+
isOptInInProgress={false}
226+
onOptInModalClose={() => {}}
227+
onOptInClick={() => {
228+
onOptInClickCalled = true;
229+
}}
230+
/>
231+
</PreferencesProvider>
232+
);
233+
const button = screen.getByText('Use AI Features');
234+
button.click();
235+
expect(onOptInClickCalled).to.be.true;
236+
});
237+
});
98238
});

0 commit comments

Comments
 (0)