ctrlshiftleft
Version:
AI-powered toolkit for embedding QA and security testing into development workflows
79 lines (60 loc) • 2.45 kB
text/typescript
import { test, expect } from '@playwright/test';
/**
* Playwright tests for PaymentForm component
* Generated by Ctrl+Shift+Left
*/
// Base URL - update as needed
const baseUrl = 'http://localhost:3000';
test.describe('PaymentForm Component Tests', () => {
test('should render the component properly', async ({ page }) => {
// Navigate to the page containing the component
await page.goto(`${baseUrl}`);
// Verify component is visible
const component = page.locator('[data-testid="paymentform"]');
await expect(component).toBeVisible();
});
test('should validate form inputs', async ({ page }) => {
await page.goto(`${baseUrl}`);
// Try to submit form without required fields
const submitButton = page.locator('button[type="submit"]');
await submitButton.click();
// Expect validation error messages to be visible
const errorMessage = page.locator('.error-message');
await expect(errorMessage).toBeVisible();
});
test('should successfully submit the form with valid data', async ({ page }) => {
await page.goto(`${baseUrl}`);
// Submit the form
const submitButton = page.locator('button[type="submit"]');
await submitButton.click();
// Check for success message or redirect
await expect(page.locator('.success-message')).toBeVisible();
});
test('should handle API responses correctly', async ({ page }) => {
await page.goto(`${baseUrl}`);
// Mock successful API response
await page.route('**/api/**', (route) => {
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ success: true, message: 'Operation successful' })
});
});
// Trigger API call (e.g., by submitting form or clicking button)
await page.click('button[type="submit"]');
// Verify success state is displayed
await expect(page.locator('.success-message')).toBeVisible();
// Mock error API response for another test
await page.route('**/api/**', (route) => {
route.fulfill({
status: 500,
contentType: 'application/json',
body: JSON.stringify({ success: false, message: 'Server error' })
});
});
// Trigger API call again
await page.click('button[type="submit"]');
// Verify error state is displayed
await expect(page.locator('.error-message')).toBeVisible();
});
});