|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const TEST_URL = 'http://localhost:3001'; |
| 4 | + |
| 5 | +test.describe('Home Page', () => { |
| 6 | + test.beforeEach(async ({ page }) => { |
| 7 | + await page.goto(`${TEST_URL}`); |
| 8 | + }); |
| 9 | + test('should render the component correctly with default state', async ({ page }) => { |
| 10 | + await expect(page.locator('text=All Streams')).toBeVisible(); |
| 11 | + await expect(page.locator('input[placeholder="Search Stream"]')).toBeVisible(); |
| 12 | + }); |
| 13 | + |
| 14 | + test('should render the component correctly with streams data', async ({ page }) => { |
| 15 | + // Check that the streams are displayed |
| 16 | + await expect(page.locator('text=backend')).toBeVisible(); |
| 17 | + await expect(page.locator('text=frontend')).toBeVisible(); |
| 18 | + }); |
| 19 | + |
| 20 | + test('should filter streams based on search input', async ({ page }) => { |
| 21 | + const searchInput = page.locator('input[placeholder="Search Stream"]'); |
| 22 | + await searchInput.fill('backend'); |
| 23 | + await expect(page.locator('text=backend')).toBeVisible(); |
| 24 | + |
| 25 | + // Clear the search and check if both streams are visible |
| 26 | + await searchInput.fill(''); |
| 27 | + await expect(page.locator('text=backend')).toBeVisible(); |
| 28 | + await expect(page.locator('text=frontend')).toBeVisible(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should display empty state if no streams are available', async ({ page }) => { |
| 32 | + const searchInput = page.locator('input[placeholder="Search Stream"]'); |
| 33 | + await searchInput.fill(Math.random().toString()); |
| 34 | + |
| 35 | + // Expect empty state view to be visible |
| 36 | + await expect(page.locator('text=No Stream found on this account')).toBeVisible(); |
| 37 | + await expect(page.locator('text=All Streams (0)')).toBeVisible(); |
| 38 | + }); |
| 39 | + |
| 40 | + test('should display the create stream button', async ({ page }) => { |
| 41 | + const createButton = page.locator('text=Create Stream'); |
| 42 | + await expect(createButton).toBeVisible(); |
| 43 | + }); |
| 44 | + |
| 45 | + test('should display the create stream modal on click', async ({ page }) => { |
| 46 | + const createButton = page.locator('text=Create Stream'); |
| 47 | + await expect(createButton).toBeVisible(); |
| 48 | + await createButton.click(); |
| 49 | + await expect(page.locator('text=Create Stream').nth(1)).toBeVisible(); |
| 50 | + }); |
| 51 | + |
| 52 | + test.describe('Create Stream Modal', () => { |
| 53 | + test.beforeEach(async ({ page }) => { |
| 54 | + const createButton = page.locator('text=Create Stream'); |
| 55 | + await createButton.click(); |
| 56 | + }); |
| 57 | + |
| 58 | + test('should render the form correctly', async ({ page }) => { |
| 59 | + // Check if essential elements are present in the form |
| 60 | + await expect(page.locator('input[placeholder="Name"]')).toBeVisible(); |
| 61 | + await expect(page.locator('text=Schema Type')).toBeVisible(); |
| 62 | + await expect(page.locator('button:has-text("Create")').nth(1)).toBeVisible(); |
| 63 | + }); |
| 64 | + |
| 65 | + test('should enable the submit button when form is valid', async ({ page }) => { |
| 66 | + // Fill in the form with valid values |
| 67 | + await page.fill('input[placeholder="Name"]', 'PlaywrightStream'); |
| 68 | + |
| 69 | + await page.locator('button:has-text("Create")').nth(1).click(); |
| 70 | + await page.waitForTimeout(1000); |
| 71 | + }); |
| 72 | + |
| 73 | + test.describe('Delete Stream', () => { |
| 74 | + test('search, navigate, and delete demo stream', async ({ page }) => { |
| 75 | + // Step 1: Search for the demo stream |
| 76 | + await page.goto(`${TEST_URL}`); |
| 77 | + const searchInput = page.locator('input[placeholder="Search Stream"]'); |
| 78 | + await searchInput.fill('PlaywrightStream'); |
| 79 | + await expect(page.locator('text=PlaywrightStream')).toBeVisible(); |
| 80 | + |
| 81 | + // Step 2: Navigate to the demo stream |
| 82 | + await page.locator('text=PlaywrightStream').click(); |
| 83 | + const manageBtn = page.locator('[data-id="manage-stream-btn"]'); |
| 84 | + await expect(manageBtn).toBeVisible(); |
| 85 | + await manageBtn.click(); |
| 86 | + |
| 87 | + await page.waitForTimeout(1000); |
| 88 | + |
| 89 | + // Step 3: Delete the demo stream |
| 90 | + const deleteBtn = page.locator('[data-id="delete-stream-btn"]'); |
| 91 | + await expect(deleteBtn).toBeVisible(); |
| 92 | + await deleteBtn.click(); |
| 93 | + await expect(page.locator('text=Delete Stream')).toBeVisible(); |
| 94 | + await page.fill('input[placeholder*="Type the name of the stream to confirm. i.e."]', 'PlaywrightStream'); |
| 95 | + const confirmDeleteBtn = page.getByRole('button', { name: 'Delete' }); |
| 96 | + await expect(confirmDeleteBtn).toBeEnabled(); |
| 97 | + await confirmDeleteBtn.click(); |
| 98 | + |
| 99 | + await page.waitForTimeout(1000); |
| 100 | + |
| 101 | + // Step 4: Check if stream is deleted |
| 102 | + await page.goto(`${TEST_URL}`); |
| 103 | + await expect(searchInput).toBeVisible(); |
| 104 | + await searchInput.fill('PlaywrightStream'); |
| 105 | + await expect(page.locator('text=No Stream found on this account')).toBeVisible(); |
| 106 | + await expect(page.locator('text=All Streams (0)')).toBeVisible(); |
| 107 | + }); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments