diff --git a/browser_tests/bee.spec.js b/browser_tests/bee.spec.js index cc18975..d323d22 100644 --- a/browser_tests/bee.spec.js +++ b/browser_tests/bee.spec.js @@ -259,8 +259,8 @@ test.describe('New BeeWalk', () => { // Click another row await page.click('#S2'); await assertRecordCastes(page, '#queenSpotted', '1', queenColumn); - const otherRow = page.getByText("S2").nth(1); - await otherRow.click(); + const s2Row = page.getByText("S2").nth(1); + await s2Row.click(); // Expect no comment to be displayed await expect(textArea).not.toContainText("Lavender"); @@ -272,10 +272,50 @@ test.describe('New BeeWalk', () => { // Expect changes not saved await expect(page.getByText('💬')).not.toBeVisible(); - await otherRow.click(); + await s2Row.click(); await expect(textArea).not.toContainText("Cornflower"); await expect(textArea).toBeEmpty(); }); + + test('Add multiple comments', async ({page}) => { + const beePage = new BeeTrackerPage(page); + const textArea = page.locator('#commentText'); + const saveButton = page.locator('#saveComment'); + const discardButton = page.locator('#discardComment'); + const s1Row = page.getByText("S1").nth(1); + const s2Row = page.getByText("S2").nth(1); + + // Visit web app, add some bees + await beePage.goto(); + await assertRecordCastes(page, '#unknownSpotted', '1', unknownCasteColumn); + await page.click('#S2'); + await assertRecordCastes(page, '#queenSpotted', '1', queenColumn); + + // Add multiple comments + await s1Row.click(); + await textArea.fill("Knapweed"); + await saveButton.click(); + + await s2Row.click(); + await textArea.fill("Sage"); + await saveButton.click(); + + // Expect both rows to have a comment + await expect(page.getByText('💬')).toHaveCount(2); + + // Expect each row to display the correct text + await s1Row.click(); + await expect(page.getByText('Knapweed')).toBeVisible; + await expect(page.getByText('Sage')).not.toBeVisible; + + // Close the text area + await discardButton.click(); + + // Expect each row to display the correct text + await s2Row.click(); + await expect(page.getByText('Knapweed')).not.toBeVisible; + await expect(page.getByText('Sage')).toBeVisible; + }); }); async function assertRecordCastes(page, buttonId, row, column) { diff --git a/src/localStorage.js b/src/localStorage.js index 7222953..9516b91 100644 --- a/src/localStorage.js +++ b/src/localStorage.js @@ -25,15 +25,7 @@ export function getSightings() { export function addComment(species, section, comment) { let storedComments = getComments(); - console.log("getting all stored comments: ", storedComments) - console.log("comment.species: ", comment.species) - console.log("species passed in: ", species) - console.log("comment.section: ", comment.section) - console.log("section passed in: ", section) - - if(storedComments) { - storedComments = storedComments.filter(i => i.species !== species && i.section !== section); - } + storedComments = storedComments.filter(comment => comment.species !== species || comment.section !== section); storedComments.push({ species, diff --git a/src/main.js b/src/main.js index 06f225e..ab581cb 100644 --- a/src/main.js +++ b/src/main.js @@ -93,12 +93,11 @@ commentSaveButton.addEventListener("click", () => { const section = currentRow.get("section"); const comment = document.getElementById("commentText").value - console.log("species, section, comment: ", species, section, comment); addComment(species, section, comment); + commentSaveButton.hidden = true; discardCommentButton.hidden = true; commentBox.hidden = true; - console.log("comment to display: ",getComment(species, section)); commentBox.innerText = getComment(species, section); renderSummary(); @@ -205,7 +204,7 @@ function renderSummary() { row.insertCell(i + 2).innerText = casteCounts[caste] ? casteCounts[caste] : ""; }) - if (comments.filter(comment => comment.species === species && comment.section === section && comment.comment != "").at(0)) { + if (comments.filter(comment => comment.species === species && comment.section === section && comment.comment !== "").at(0)) { row.insertCell(6).innerHTML = '💬'; } else { row.insertCell(6).innerHTML = ''; diff --git a/static/bundle.js b/static/bundle.js index 35548b8..702241d 100644 --- a/static/bundle.js +++ b/static/bundle.js @@ -61,15 +61,7 @@ function addComment(species, section, comment) { let storedComments = getComments(); - console.log("getting all stored comments: ", storedComments); - console.log("comment.species: ", comment.species); - console.log("species passed in: ", species); - console.log("comment.section: ", comment.section); - console.log("section passed in: ", section); - - if(storedComments) { - storedComments = storedComments.filter(i => i.species !== species && i.section !== section); - } + storedComments = storedComments.filter(comment => comment.species !== species || comment.section !== section); storedComments.push({ species, @@ -329,12 +321,11 @@ const section = currentRow.get("section"); const comment = document.getElementById("commentText").value; - console.log("species, section, comment: ", species, section, comment); addComment(species, section, comment); + commentSaveButton.hidden = true; discardCommentButton.hidden = true; commentBox.hidden = true; - console.log("comment to display: ",getComment(species, section)); commentBox.innerText = getComment(species, section); renderSummary();