clean up the code

This commit is contained in:
Abi Raja 2024-05-17 16:49:17 -04:00
parent 72d412fa52
commit 7396160833

View File

@ -32,13 +32,48 @@ describe("Simple Puppeteer Test", () => {
await browser.close(); await browser.close();
}); });
const stacks = Object.values(Stack).slice(0, 1); const stacks = Object.values(Stack);
// For debugging
//.slice(0, 1);
stacks.forEach((stack) => { stacks.forEach((stack) => {
it(`should load the homepage and check the title for stack: ${stack}`, async () => { it(`should load the homepage and check the title for stack: ${stack}`, async () => {
const codeGenerationModel = "claude_3_sonnet"; const codeGenerationModel = "claude_3_sonnet";
const testId = `${codeGenerationModel}_${stack}`;
// Set up local storage await setupLocalStorage(page, stack, codeGenerationModel);
// Upload file
const fileInput = (await page.$(
".file-input"
)) as ElementHandle<HTMLInputElement>;
if (!fileInput) {
throw new Error("File input element not found");
}
await fileInput.uploadFile(IMAGE_PATH);
// Screenshot the first step
await page.screenshot({
path: `${SCREENSHOTS_PATH}/${testId}_image_uploaded.png`,
});
// Click the generate button and wait for the code to be generated
await page.waitForNetworkIdle();
await page.waitForFunction(() => document.body.innerText.includes("v1"), {
timeout: 30000,
});
await page.screenshot({
path: `${SCREENSHOTS_PATH}/${testId}_image_results.png`,
});
});
});
});
async function setupLocalStorage(page: Page, stack: string, model: string) {
const setting = { const setting = {
openAiApiKey: null, openAiApiKey: null,
openAiBaseURL: null, openAiBaseURL: null,
@ -46,7 +81,7 @@ describe("Simple Puppeteer Test", () => {
isImageGenerationEnabled: false, isImageGenerationEnabled: false,
editorTheme: "cobalt", editorTheme: "cobalt",
generatedCodeConfig: stack, generatedCodeConfig: stack,
codeGenerationModel: codeGenerationModel, codeGenerationModel: model,
isTermOfServiceAccepted: false, isTermOfServiceAccepted: false,
accessCode: null, accessCode: null,
}; };
@ -57,39 +92,4 @@ describe("Simple Puppeteer Test", () => {
// Reload the page to apply the local storage // Reload the page to apply the local storage
await page.reload(); await page.reload();
// Generate from image
const fileInput = (await page.$(
".file-input"
)) as ElementHandle<HTMLInputElement>;
// Replace with the path to your image
const imagePath = IMAGE_PATH;
if (!fileInput) {
throw new Error("File input element not found");
} }
// Upload file
await fileInput.uploadFile(imagePath);
// Screenshot of the uploaded image
await page.screenshot({
path: `${SCREENSHOTS_PATH}/${codeGenerationModel}_${stack}_image_uploaded.png`,
});
console.log("starting image code generation for stack: ", stack);
// Click the generate button and wait for the code to be generated
await page.waitForNetworkIdle();
await page.waitForFunction(() => document.body.innerText.includes("v1"), {
timeout: 30000,
});
await page.screenshot({
path: `${SCREENSHOTS_PATH}/${codeGenerationModel}_${stack}_image_generation_results.png`,
});
console.log(`done with image code generation for stack: ${stack}`);
});
});
});