From 7756690f5cb13bf36511f5e092306b00fbebe01d Mon Sep 17 00:00:00 2001 From: Fernando Pauer Date: Tue, 19 Nov 2024 10:22:33 -0800 Subject: [PATCH] feat: assistant dashboard e2e --- .../e2e/tests/assistant/assistant.spec.ts | 103 ++++++++++++++++++ .../assistant/assistantFloatingMenu.tsx | 1 + .../dashboard/mocked-dashboard.stories.tsx | 3 + 3 files changed, 107 insertions(+) create mode 100644 packages/dashboard/e2e/tests/assistant/assistant.spec.ts diff --git a/packages/dashboard/e2e/tests/assistant/assistant.spec.ts b/packages/dashboard/e2e/tests/assistant/assistant.spec.ts new file mode 100644 index 000000000..4ac942c9b --- /dev/null +++ b/packages/dashboard/e2e/tests/assistant/assistant.spec.ts @@ -0,0 +1,103 @@ +import { test, expect } from '@playwright/test'; + +const TEST_PAGE = '/iframe.html?id=dashboard-mocked-data--view-only'; + +test('dashboard has assistant enabled', async ({ page }) => { + await page.goto(TEST_PAGE); + + await expect( + page.getByTestId('assistant-menu-buttons-container') + ).toBeVisible(); +}); + +test('enable assistant mode and selects widgets', async ({ page }) => { + await page.goto(TEST_PAGE); + + const assistantBtn = await page.getByRole('button', { + name: /AI Assistant/i, + }); + + await assistantBtn.click(); + + await page.getByRole('checkbox').nth(3).check(); + await page.getByRole('checkbox').nth(4).check(); + + await expect(page.getByText('2/3 items selected')).toBeVisible(); + + const summaryBtn = await page.getByRole('button', { + name: /Generate summary/i, + }); + + expect(await summaryBtn.isDisabled()).toBeFalsy(); +}); + +test('disable assistant buttons when selects more than 3 widgets', async ({ + page, +}) => { + await page.goto(TEST_PAGE); + + const assistantBtn = await page.getByRole('button', { + name: /AI Assistant/i, + }); + + await assistantBtn.click(); + + await page.getByRole('checkbox').nth(1).check(); + await page.getByRole('checkbox').nth(2).check(); + await page.getByRole('checkbox').nth(3).check(); + await page.getByRole('checkbox').nth(4).check(); + + await expect(page.getByText('4/3 items selected')).toBeVisible(); + + const summaryBtn = await page.getByRole('button', { + name: '4/3 items selected', + }); + + await summaryBtn.click(); + + await expect(page.getByText('Property limit reached')).toBeVisible(); +}); + +test('open assistant chatbot when generate summary is clicked', async ({ + page, +}) => { + await page.goto(TEST_PAGE); + + const assistantBtn = await page.getByRole('button', { + name: /AI Assistant/i, + }); + + await assistantBtn.click(); + + await page.getByRole('checkbox').nth(3).check(); + + await expect(page.getByText('1/3 items selected')).toBeVisible(); + + const summaryBtn = await page.getByRole('button', { + name: /Generate summary/i, + }); + + await summaryBtn.click(); + + await expect( + page.getByPlaceholder('Ask me anything about your IoT data') + ).toBeVisible(); +}); + +test('open and close chatbot', async ({ page }) => { + await page.goto(TEST_PAGE); + + const chatbotOpenBtn = await page.getByTestId('collapsed-right-panel-icon'); + + await chatbotOpenBtn.click(); + + await expect( + page.getByPlaceholder('Ask me anything about your IoT data') + ).toBeVisible(); + + const chatbotCloseBtn = await page.getByTestId( + 'assistant-chatbot-close-button' + ); + + await chatbotCloseBtn.click(); +}); diff --git a/packages/dashboard/src/components/assistant/assistantFloatingMenu.tsx b/packages/dashboard/src/components/assistant/assistantFloatingMenu.tsx index d039706cb..5edb5b383 100644 --- a/packages/dashboard/src/components/assistant/assistantFloatingMenu.tsx +++ b/packages/dashboard/src/components/assistant/assistantFloatingMenu.tsx @@ -129,6 +129,7 @@ export const AssistantFloatingMenu = ({ ) : null}
{assistantState.mode === 'on' ? ( diff --git a/packages/dashboard/stories/dashboard/mocked-dashboard.stories.tsx b/packages/dashboard/stories/dashboard/mocked-dashboard.stories.tsx index 5fbb7637f..bddc15c83 100644 --- a/packages/dashboard/stories/dashboard/mocked-dashboard.stories.tsx +++ b/packages/dashboard/stories/dashboard/mocked-dashboard.stories.tsx @@ -87,6 +87,9 @@ export const ViewOnly: ComponentStory = () => ( );