Add end-to-end test using playwright

This commit is contained in:
sosokker 2024-05-14 04:49:44 +07:00
parent 9738a61c1e
commit 84d17066ac
5 changed files with 76 additions and 1 deletions

View File

@ -93,7 +93,7 @@ const Statistic: React.FC = () => {
</div>
{/* Recommendation Card */}
<div className="mt-6">
<div className="mt-6" id="alert-container">
<Alert
indoor_temp={indoorWeatherData?.avg_indoor_temp}
outdoor_temp={outdoorWeatherData?.avg_outdoor_temp}

View File

@ -0,0 +1,19 @@
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByRole('link', { name: 'Camera' }).click();
await page.getByRole('combobox').selectOption('2');
await page.getByRole('button', { name: 'Start Connection' }).click();
await page.waitForSelector('text=Loading...');
const loadingText = await page.$('text=Loading...');
expect(loadingText).not.toBeNull();
// await page.waitForSelector('text=Loading...', { state: 'hidden' });
// const hiddenLoadingText = await page.$('text=Loading...');
// expect(hiddenLoadingText).toBeNull();
await page.waitForSelector('canvas');
const canvas = await page.$('canvas');
expect(canvas).not.toBeNull();
});

View File

@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('http://localhost:5173/');
// Check if elements with specific text exist on the page
const outdoorTempElement = await page
.locator('span')
.getByText(/^Outdoor Temperature$/)
.first();
const outdoorHumidityElement = await page
.locator('span')
.getByText(/^Outdoor Humidity$/)
.first();
const outdoorPM25Element = await page
.locator('span')
.getByText(/^Outdoor PM2.5$/)
.first();
const outdoorPM10Element = await page
.locator('span')
.getByText(/^Outdoor PM10$/)
.first();
const indoorTempElement = await page
.locator('span')
.getByText(/^Indoor Temperature$/)
.first();
const indoorLightElement = await page
.locator('span')
.getByText(/^Indoor Light$/)
.first();
expect(outdoorTempElement).not.toBeNull();
expect(outdoorHumidityElement).not.toBeNull();
expect(outdoorPM25Element).not.toBeNull();
expect(outdoorPM10Element).not.toBeNull();
expect(indoorTempElement).not.toBeNull();
expect(indoorLightElement).not.toBeNull();
});

View File

@ -0,0 +1,8 @@
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('http://localhost:5173/');
const alertContainer = await page.waitForSelector('#alert-container');
expect(alertContainer).not.toBeNull();
});

View File

@ -0,0 +1,10 @@
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByRole('link', { name: 'Snapshot' }).click();
await page.getByRole('button', { name: 'Today' }).click();
const image = await page.waitForSelector('img');
expect(image).not.toBeNull();
});