File size: 3,275 Bytes
0c591a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { test, expect } from '@playwright/test'

test.describe('Instant SWOT Agent', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/')
  })

  test('should display the home page', async ({ page }) => {
    await expect(page.getByText('Instant SWOT Agent')).toBeVisible()
    await expect(page.getByPlaceholder('Search U.S. listed companies...')).toBeVisible()
  })

  test('should show empty state message', async ({ page }) => {
    await expect(page.getByText('Enter a company name to begin')).toBeVisible()
  })

  test('should toggle between Executive and Full view modes', async ({ page }) => {
    const executiveBtn = page.getByRole('button', { name: 'Executive' })
    const fullBtn = page.getByRole('button', { name: 'Full' })

    await expect(executiveBtn).toBeVisible()
    await expect(fullBtn).toBeVisible()

    // Click Executive
    await executiveBtn.click()
    await expect(executiveBtn).toHaveClass(/bg-primary/)

    // Click Full
    await fullBtn.click()
    await expect(fullBtn).toHaveClass(/bg-primary/)
  })

  test('should toggle dark mode', async ({ page }) => {
    const darkModeBtn = page.locator('button').filter({ has: page.locator('svg') }).last()

    // Check initial state (dark mode)
    await expect(page.locator('html')).toHaveClass(/dark/)

    // Toggle to light mode
    await darkModeBtn.click()
    await expect(page.locator('html')).not.toHaveClass(/dark/)

    // Toggle back to dark mode
    await darkModeBtn.click()
    await expect(page.locator('html')).toHaveClass(/dark/)
  })

  test('should search for stocks', async ({ page }) => {
    const searchInput = page.getByPlaceholder('Search U.S. listed companies...')

    await searchInput.fill('AAPL')

    // Wait for autocomplete dropdown
    await expect(page.getByText('Apple')).toBeVisible({ timeout: 5000 })
  })

  test('should select a stock and show Generate button', async ({ page }) => {
    const searchInput = page.getByPlaceholder('Search U.S. listed companies...')

    await searchInput.fill('TSLA')

    // Wait for and click the Tesla option
    await page.getByText('Tesla').first().click()

    // Generate button should appear
    await expect(page.getByRole('button', { name: /Generate SWOT/i })).toBeVisible()
  })
})

test.describe('SWOT Analysis Workflow', () => {
  test('should complete full analysis workflow', async ({ page }) => {
    // This test requires the backend to be running
    test.skip(!!process.env.CI, 'Skipping in CI - requires backend')

    await page.goto('/')

    // Search and select a stock
    const searchInput = page.getByPlaceholder('Search U.S. listed companies...')
    await searchInput.fill('AAPL')
    await page.getByText('Apple').first().click()

    // Click Generate SWOT
    await page.getByRole('button', { name: /Generate SWOT/i }).click()

    // Wait for loading state
    await expect(page.getByText(/Analyzing/i)).toBeVisible({ timeout: 5000 })

    // Wait for results (up to 2 minutes for full analysis)
    await expect(page.getByText('Strengths')).toBeVisible({ timeout: 120000 })
    await expect(page.getByText('Weaknesses')).toBeVisible()
    await expect(page.getByText('Opportunities')).toBeVisible()
    await expect(page.getByText('Threats')).toBeVisible()
  })
})