Skip to content

Commit

Permalink
Switch logic so multiple comments can be displayed no matter the comb…
Browse files Browse the repository at this point in the history
…o of bees/section they're assigned to
  • Loading branch information
ruthmoog committed Jun 22, 2023
1 parent 6c46e97 commit a27f983
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
46 changes: 43 additions & 3 deletions browser_tests/bee.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
10 changes: 1 addition & 9 deletions src/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = '';
Expand Down
13 changes: 2 additions & 11 deletions static/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a27f983

Please sign in to comment.