Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…p24-group6 into UnitTest-ToDoListPage
  • Loading branch information
yashilvora19 committed Jun 9, 2024
2 parents 72d7951 + 0775efb commit 695cbee
Show file tree
Hide file tree
Showing 4 changed files with 1,831 additions and 21 deletions.
113 changes: 113 additions & 0 deletions __tests__/E2EhompageProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import puppeteer from 'puppeteer';

describe('Homepage Task Progress Tests', () => {
let browser;
let page;

beforeAll(async () => {
try {
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto('http://127.0.0.1:5501/source/todolist.html');
} catch (error) {
console.error('Failed to initialize browser:', error);
}
});

afterAll(async () => {
if (browser) {
await browser.close();
}
});


test('adds a new task and updates progress', async () => {
await page.type('#task-input', 'Test Task');
await page.type('#due-date', '12/31/2024');
await page.type('#task-description', 'This is a test task description.');
await page.select('#task-tags', 'Project');
await page.click('#submit');

// Navigate to the homepage
await page.goto('http://127.0.0.1:5501/source/homepage.html');
await page.waitForSelector('iframe');

const frameHandle = await page.$('iframe');
const frame = await frameHandle.contentFrame();

const taskProgress = await frame.evaluate(() => {
return JSON.parse(localStorage.getItem('taskProgress')) || { completedTasks: 0, totalTasks: 0 };
});

expect(taskProgress.completedTasks).toBe(0); // 0 completed
expect(taskProgress.totalTasks).toBe(1); // 1 total task
});



test('checks off a task and updates progress', async () => {
await page.goto('http://127.0.0.1:5501/source/todolist.html'); // Go back to the to-do list page
await page.waitForSelector('li input[type="checkbox"]');
await page.click('li input[type="checkbox"]');

// Navigate to the homepage
await page.goto('http://127.0.0.1:5501/source/homepage.html');
await page.waitForSelector('iframe');

const frameHandle = await page.$('iframe');
const frame = await frameHandle.contentFrame();

const taskProgress = await frame.evaluate(() => {
return JSON.parse(localStorage.getItem('taskProgress')) || { completedTasks: 0, totalTasks: 0 };
});

expect(taskProgress.completedTasks).toBe(1); // 1 completed
expect(taskProgress.totalTasks).toBe(1); // 1 total task
});

test('deletes a task and updates progress', async () => {
await page.goto('http://127.0.0.1:5501/source/todolist.html'); // Go back to the to-do list page
await page.waitForSelector('.delete-button');
await page.click('.delete-button');

// Navigate to the homepage
await page.goto('http://127.0.0.1:5501/source/homepage.html');
await page.waitForSelector('iframe');

const frameHandle = await page.$('iframe');
const frame = await frameHandle.contentFrame();

const taskProgress = await frame.evaluate(() => {
return JSON.parse(localStorage.getItem('taskProgress')) || { completedTasks: 0, totalTasks: 0 };
});

expect(taskProgress.completedTasks).toBe(0); // 0 completed
expect(taskProgress.totalTasks).toBe(0); // 0 total tasks
});

test('deletes all tasks and updates progress', async () => {
await page.goto('http://127.0.0.1:5501/source/todolist.html'); // Go back to the to-do list page

// Delete all tasks if any exist
let taskExists = await page.$('.task-item') !== null;
while (taskExists) {
await page.click('.task-item .delete-button');
await page.waitForTimeout(100); // Small delay to ensure the task is deleted
taskExists = await page.$('.task-item') !== null;
}

// Navigate to the homepage
await page.goto('http://127.0.0.1:5501/source/homepage.html');
await page.waitForSelector('iframe');

const frameHandle = await page.$('iframe');
const frame = await frameHandle.contentFrame();

const taskProgress = await frame.evaluate(() => {
return JSON.parse(localStorage.getItem('taskProgress')) || { completedTasks: 0, totalTasks: 0 };
});

expect(taskProgress.completedTasks).toBe(0); // 0 completed
expect(taskProgress.totalTasks).toBe(0); // 0 total tasks
});
});
125 changes: 125 additions & 0 deletions __tests__/dailyLogCRUD.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// const puppeteer = require('puppeteer');
import puppeteer from "puppeteer";
describe('Basic user flow for Website', () => {
let browser;
let page;

beforeAll(async () => {
browser = await puppeteer.launch({ headless: false });
page = await browser.newPage();
await page.goto('https://cse110-sp24-group6.github.io/cse110-sp24-group6/source/dailylog.html');
});

afterAll(async () => {
await browser.close();
});

const logData = {
progress: "Completed unit testing",
challenges: "Faced issues with async operations",
learnings: "Learned about async/await",
futurePlan: "Implement E2E tests"
};

async function fillLogEntry(data) {
await page.type('#progress', data.progress);
await page.type('#challenges', data.challenges);
await page.type('#learnings', data.learnings);
await page.type('#future-plan', data.futurePlan);
}

it('Add a NEW log', async () => {
console.log('Adding a log...');

// Select a date (today's date for simplicity)
await page.click('.date.today'); // Click today's date

// Fill out the log entry
await fillLogEntry(logData);
// await new Promise(resolve => setTimeout(resolve, 5000));
// Save the entry
await page.click('#save-entry');
// Verify the log is saved in localStorage
const logs = await page.evaluate(() => localStorage.getItem('logs'));
const parsedLogs = JSON.parse(logs);
const todayStr = new Date().toISOString().split('T')[0];
// await new Promise(resolve => setTimeout(resolve, 5000));
console.log(todayStr);
expect(parsedLogs[todayStr].progress).toBe(logData.progress);
expect(parsedLogs[todayStr].challenges).toBe(logData.challenges);
expect(parsedLogs[todayStr].learnings).toBe(logData.learnings);
expect(parsedLogs[todayStr].futurePlan).toBe(logData.futurePlan);
}, 20000);

it('Refreshing page', async () => {
console.log('Refreshing page to check local storage...');

// Select a date (today's date for simplicity)
await page.click('.date.today'); // Click today's date

// Refreshing page here
await page.reload();
// Verify the log is saved in localStorage
const logs = await page.evaluate(() => localStorage.getItem('logs'));
const parsedLogs = JSON.parse(logs);
const todayStr = new Date().toISOString().split('T')[0];
// await new Promise(resolve => setTimeout(resolve, 5000));
console.log(todayStr);
expect(parsedLogs[todayStr].progress).toBe(logData.progress);
expect(parsedLogs[todayStr].challenges).toBe(logData.challenges);
expect(parsedLogs[todayStr].learnings).toBe(logData.learnings);
expect(parsedLogs[todayStr].futurePlan).toBe(logData.futurePlan);
}, 20000);

it('Editing today log', async () => {
console.log('Editing a log...');

// Select a date (today's date for simplicity)
await page.click('.date.today'); // Click today's date
// Fill out the log entry
await page.type('#progress', " and end to end testing");
// Save the entry
await page.click('#save-entry');
// Verify the log is saved in localStorage
const logs = await page.evaluate(() => localStorage.getItem('logs'));
const parsedLogs = JSON.parse(logs);
const todayStr = new Date().toISOString().split('T')[0];
expect(parsedLogs[todayStr].progress).toBe("Completed unit testing and end to end testing");
expect(parsedLogs[todayStr].challenges).toBe(logData.challenges);
expect(parsedLogs[todayStr].learnings).toBe(logData.learnings);
expect(parsedLogs[todayStr].futurePlan).toBe(logData.futurePlan);
}, 20000);

it('Delete one', async () => {
console.log('Delete log...');

// Select the same date (today's date for simplicity)
await page.click('.date.today'); // Click today's date

// Delete the entry
await page.waitForSelector('button[id="delete-entry"]');
await page.click('button[id="delete-entry"]');

// Verify the log is removed from localStorage
const logs = await page.evaluate(() => localStorage.getItem('logs'));
const parsedLogs = JSON.parse(logs);
const todayStr = new Date().toISOString().split('T')[0];

expect(parsedLogs[todayStr]).toBeUndefined();
}, 20000);

// checking if deletion of log works
it('Refresh and check after deletion', async () => {
console.log('Refreshing...');

// Reload the page
await page.reload();

// Verify the log is still deleted in localStorage
const logs = await page.evaluate(() => localStorage.getItem('logs'));
const parsedLogs = JSON.parse(logs);
const todayStr = new Date().toISOString().split('T')[0];

expect(parsedLogs[todayStr]).toBeUndefined();
}, 20000);
});
Loading

0 comments on commit 695cbee

Please sign in to comment.