@orfeas126/box-ui-elements
Version:
Box UI Elements
314 lines • 12.8 kB
JavaScript
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
import * as React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import { expect, userEvent, waitFor, within } from '@storybook/test';
import { Notification } from '@box/blueprint-web';
import { http, HttpResponse } from 'msw';
import { DEFAULT_HOSTNAME_API } from '../../../../constants';
import { defaultVisualConfig } from '../../../../utils/storybook';
import ContentPreview from '../../ContentPreview';
export const basic = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
expect(modal.getByText('Welcome to Box AI')).toBeInTheDocument();
expect(modal.getByText('Ask questions about')).toBeInTheDocument();
expect(modal.getByText('This chat will be cleared when you close this pdf')).toBeInTheDocument();
expect(modal.getByText('Summarize this document')).toBeInTheDocument();
expect(modal.getByText('What are the key takeaways?')).toBeInTheDocument();
expect(modal.getByText('How can this document be improved?')).toBeInTheDocument();
expect(modal.getByText('Are there any next steps defined?')).toBeInTheDocument();
expect(modal.getByText('Ask anything about this pdf')).toBeInTheDocument();
}
};
export const closeModal = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const closeButton = modal.getByRole('button', {
name: 'Close Modal'
});
await userEvent.click(closeButton);
}
};
export const submitAnswer = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const textInput = modal.getByRole('textbox', {
name: 'Ask anything about this pdf'
});
expect(textInput).toBeInTheDocument();
textInput.focus();
await userEvent.keyboard('Why are public APIs important?');
await userEvent.click(modal.getByRole('button', {
name: 'Ask'
}), {
pointerEventsCheck: 0
});
const answer = await modal.findByText('Public APIs are important because of key and important reasons.');
expect(answer).toBeInTheDocument();
expect(modal.getByText('Based on:')).toBeInTheDocument();
}
};
export const clickOnSuggestion = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const suggestion = modal.getByText('Summarize this document');
await userEvent.click(suggestion);
const answer = await modal.findByText('Public APIs are important because of key and important reasons.');
expect(answer).toBeInTheDocument();
expect(modal.getByText('Based on:')).toBeInTheDocument();
}
};
export const hoverOverCitation = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const suggestion = modal.getByText('Summarize this document');
await userEvent.click(suggestion);
const answer = await modal.findByText('Public APIs are important because of key and important reasons.');
expect(answer).toBeInTheDocument();
expect(modal.getByText('Based on:')).toBeInTheDocument();
const citation = await modal.getByRole('button', {
name: 'Reference 1'
});
expect(citation).toBeInTheDocument();
await userEvent.hover(citation);
}
};
export const citationDisabled = {
args: {
contentAnswersProps: {
show: true,
isCitationsEnabled: false,
isMarkdownEnabled: true
}
},
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const suggestion = modal.getByText('Summarize this document');
await userEvent.click(suggestion);
const answer = await modal.findByText('Public APIs are important because of key and important reasons.');
expect(answer).toBeInTheDocument();
expect(modal.queryByText('Based on:')).not.toBeInTheDocument();
}
};
export const clearConversation = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const suggestion = modal.getByText('Summarize this document');
await userEvent.click(suggestion);
const answer = await modal.findByText('Public APIs are important because of key and important reasons.');
expect(answer).toBeInTheDocument();
expect(modal.getByText('Based on:')).toBeInTheDocument();
const clearConversationButton = modal.getByRole('button', {
name: 'Clear conversation'
});
await userEvent.click(clearConversationButton);
const oldAnswer = modal.queryByText('Public APIs are important because of key and important reasons.');
expect(oldAnswer).not.toBeInTheDocument();
}
};
export const markdownEnabled = {
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const textInput = modal.getByRole('textbox', {
name: 'Ask anything about this pdf'
});
expect(textInput).toBeInTheDocument();
textInput.focus();
await userEvent.keyboard('table summarizing the highlights from the document');
await userEvent.click(modal.getByRole('button', {
name: 'Ask'
}), {
pointerEventsCheck: 0
});
const answer = await modal.findByText('Here’s a table summarizing the highlights from the document:');
expect(answer).toBeInTheDocument();
}
};
export const markdownDisabled = {
args: {
contentAnswersProps: {
show: true,
isCitationsEnabled: false,
isMarkdownEnabled: false
}
},
play: async ({
canvasElement
}) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole('button', {
name: 'Box AI'
}, {
timeout: 5000
});
expect(button).toBeInTheDocument();
await userEvent.click(button);
const dialog = await waitFor(() => document.querySelector('[role="dialog"]'));
expect(dialog).toBeInTheDocument();
const modal = within(dialog);
const textInput = modal.getByRole('textbox', {
name: 'Ask anything about this pdf'
});
expect(textInput).toBeInTheDocument();
textInput.focus();
await userEvent.keyboard('table summarizing the highlights from the document');
await userEvent.click(modal.getByRole('button', {
name: 'Ask'
}), {
pointerEventsCheck: 0
});
}
};
export default {
title: 'Elements/ContentPreview/tests/visual/BoxAI',
component: ContentPreview,
render: _ref => {
let args = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
return /*#__PURE__*/React.createElement(Notification.Provider, null, /*#__PURE__*/React.createElement(Router, null, /*#__PURE__*/React.createElement(ContentPreview, _extends({
key: `${args.fileId}-${args.token}`
}, args))));
},
args: {
features: global.FEATURE_FLAGS,
fileId: global.FILE_ID,
hasHeader: true,
token: global.TOKEN,
contentAnswersProps: {
show: true,
isCitationsEnabled: true,
isMarkdownEnabled: true
}
},
parameters: _objectSpread(_objectSpread({}, defaultVisualConfig.parameters), {}, {
msw: {
handlers: [http.post(`${DEFAULT_HOSTNAME_API}/2.0/ai/ask`, async ({
request
}) => {
const body = await request.json();
switch (body.prompt) {
case 'table summarizing the highlights from the document':
return HttpResponse.json({
answer: 'Here’s a table summarizing the highlights from the document:\n\n| **Highlight** |\n|---------------------------------------------------------------------------------------------------|\n| Captain of the NCAA Division I Women’s Lacrosse Team, with a 3.8 GPA in Business at Brown University and experience in sales, marketing, and operations across various internships. |',
created_at: '2024-09-20T12:25:51.816-07:00',
completion_reason: 'done'
});
default:
return HttpResponse.json({
answer: 'Public APIs are important because of key and important reasons.',
citations: [{
content: 'Public APIs are key drivers of innovation and growth.',
id: '123',
type: 'file',
name: 'The importance of public APIs.pdf'
}],
completion_reason: 'done',
created_at: '2012-12-12T10:53:43-08:00'
});
}
})]
}
})
};
//# sourceMappingURL=ContentPreview-visual.stories.js.map