Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwabco committed Jan 8, 2024
1 parent 7cf73ee commit b89b15c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 68 deletions.
11 changes: 6 additions & 5 deletions src/app/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ export const Sidebar: React.FC = () => {
}, 2000)
}

const buttons = entries.map((entry, key) => (
const menuItems = entries.map((entry, key) => (
<MenuItem

key={key} value={entry.url}
><div className="flex-col" >
><div className="flex-col" data-testid={entry.url}>
<div>{entry.title}</div>
<div style={{ ...styles.entryUrl, whiteSpace: 'nowrap' as 'nowrap' }}>{entry.url}</div>
</div>
Expand All @@ -122,7 +123,7 @@ export const Sidebar: React.FC = () => {
<div className="flex flex-column w-full" style={{ ...styles.textHeaderWrapper, flexDirection: "column", }}>
<div className="mb-3 w-full">
<h4 style={styles.h4}>Select demo url to index</h4>
<Select className="w-full" value={url} onChange={handleUrlChange} MenuProps={{
<Select className="w-full" value={url} data-testid="url-selector" onChange={handleUrlChange} MenuProps={{
keepMounted: true,
PaperProps: {
style: {
Expand All @@ -132,7 +133,7 @@ export const Sidebar: React.FC = () => {
},
},
}}>
{buttons}
{menuItems}
</Select>
</div>
<div className="mb-3 w-full">
Expand Down Expand Up @@ -176,7 +177,7 @@ export const Sidebar: React.FC = () => {
</div>
<div className="flex flex-wrap w-full mt-5 pb-2 border-b border-[#738FAB1F]">
<div className="text-xs uppercase">Index records</div>
<div className="text-[#1B17F5] ml-auto cursor-pointer text-xs" onClick={handleClearIndexClick}>Clear</div>
<div className="text-[#1B17F5] ml-auto cursor-pointer text-xs" onClick={handleClearIndexClick} data-testid="clear-button">Clear</div>
</div>
{(
<div className={`text-xs mt-1
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const metadata = {
description: "Pinecone - Vercel AI SDK Example",
};

import { Inter } from 'next/font/google'
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ['latin'] })


Expand Down
1 change: 1 addition & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ const Page: React.FC = () => {
};

export default Page;

86 changes: 24 additions & 62 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,42 @@
import { test, expect } from '@playwright/test';
import { expect, test } from '@playwright/test';
import { urls } from '../src/app/components/Sidebar/urls';

test('has correct title', async ({ page }) => {
await page.goto('http://localhost:3000');

await expect(page).toHaveTitle('Pinecone - Vercel AI SDK Example')
})

test('renders info modal button', async ({ page }) => {
await page.goto('http://localhost:3000')

const infoButtonCount = await page.locator('.info-button').count()
await expect(infoButtonCount).toBe(1)
})

test('renders GitHub repository button', async ({ page }) => {
await page.goto('http://localhost:3000')

const infoButtonCount = await page.locator('.github-button').count()
await expect(infoButtonCount).toBe(1)
})

test('renders Vercel deploy button', async ({ page }) => {
await page.goto('http://localhost:3000')

const vercelDeployButtonCount = await page.getByRole('link', { name: 'Deploy' }).count()

await expect(vercelDeployButtonCount).toBe(1)
})

test('renders clear index button', async ({ page }) => {
await page.goto('http://localhost:3000')

const clearIndexButtonCount = await page.getByRole('button', { name: 'Clear Index' }).count()

const clearIndexButton = await page.$('[data-testid="clear-button"]');
const clearIndexButtonCount = clearIndexButton ? 1 : 0;
await expect(clearIndexButtonCount).toBe(1)
})

test('renders indonesia deforestation button', async ({ page }) => {
await page.goto('http://localhost:3000')

const indonesiaDeforestationButtonCount = await page.getByRole('button', { name: 'Indonesia Deforestation' }).count()

await expect(indonesiaDeforestationButtonCount).toBe(1)
})

test('renders solar power in India button', async ({ page }) => {
await page.goto('http://localhost:3000')

const solarPowerButtonCount = await page.getByRole('button', { name: 'Solar Power in India' }).count()

await expect(solarPowerButtonCount).toBe(1)
})

test('renders matisee thybulle button', async ({ page }) => {
await page.goto('http://localhost:3000')

const matiseeThybulleButtonCount = await page.getByRole('button', { name: 'Matisee Thybulle' }).count()

await expect(matiseeThybulleButtonCount).toBe(1)
})

/*test('GitHub button goes to project repository', async ({ page, browserName }) => {
test.setTimeout(60000)
test.skip(browserName === 'chromium', 'Chrome doesn\'t work :( ')
await page.goto('http://localhost:3000/');
const githubButton = await page.locator('.github-button');
await githubButton.click();
test('Check Select menu', async ({ page }) => {
// Go to your page
await page.goto('http://localhost:3000');

try {
await page.waitForNavigation('https://github.com/pinecone-io/pinecone-vercel-starter');
} catch (e) {
console.log('Error waiting on navigation...')
// Check if Select is visible
const select = await page.locator('data-testid=url-selector');
await expect(select).toBeVisible();

// Click on the Select box and wait for it
await select.click();
await page.waitForTimeout(1000);

// Check if MenuItems are rendered correctly
for (let i = 0; i < urls.length; i++) {
const menuItem = await page.locator(`div[data-testid="${urls[i].url}"]`);
const title = await menuItem.locator('div').first().innerText();
expect(title).toBe(urls[i].title); // The title should be the title of the entry
const url = await menuItem.locator('div').last().innerText();
expect(url).toBe(urls[i].url); // The url should be the url of the entry
}
});*/
});


// TODO - add tests for other key buttons on the homepage

0 comments on commit b89b15c

Please sign in to comment.