-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Read Status #4
Changes from all commits
4623934
ffff5ae
8094e30
02dadf2
b476d10
7ae7591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/// <reference types="cypress" /> | ||
|
||
const ringo = { | ||
username: "Ringo", | ||
email: "[email protected]", | ||
password: "Z6#6%xfLTarZ9U", | ||
}; | ||
const george = { | ||
username: "George", | ||
email: "[email protected]", | ||
password: "L%e$xZHC4QKP@F", | ||
}; | ||
|
||
describe("Read Status", () => { | ||
it("setup", () => { | ||
cy.signup(ringo.username, ringo.email, ringo.password); | ||
cy.logout(); | ||
cy.signup(george.username, george.email, george.password); | ||
cy.logout(); | ||
}); | ||
|
||
it("displays total unread", () => { | ||
cy.login(ringo.username, ringo.password); | ||
|
||
cy.get("input[name=search]").type("George"); | ||
cy.contains("George").click(); | ||
|
||
cy.get("input[name=text]").type("First message{enter}"); | ||
cy.wait(500) | ||
cy.get("input[name=text]").type("Second message{enter}"); | ||
cy.wait(500) | ||
cy.get("input[name=text]").type("Third message{enter}"); | ||
|
||
cy.logout(); | ||
|
||
cy.login(george.username, george.password); | ||
cy.contains("3"); | ||
cy.logout(); | ||
}); | ||
|
||
it("displays last read message", () => { | ||
cy.login(george.username, george.password); | ||
cy.contains("Ringo").click(); | ||
cy.logout(); | ||
|
||
cy.login(ringo.username, ringo.password); | ||
cy.contains("George").click(); | ||
|
||
cy.get("svg").should(($list) => { | ||
expect($list).to.have.length(6) | ||
}) | ||
|
||
cy.logout(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { Box, Typography } from '@material-ui/core'; | ||
import { Avatar, Box, Typography } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'flex-end', | ||
}, | ||
avatar: { | ||
height: 20, | ||
width: 20, | ||
marginRight: 1, | ||
marginTop: 9, | ||
marginBottom: 5, | ||
}, | ||
date: { | ||
fontSize: 11, | ||
color: '#BECCE2', | ||
|
@@ -27,7 +34,7 @@ const useStyles = makeStyles(() => ({ | |
}, | ||
})); | ||
|
||
const SenderBubble = ({ time, text }) => { | ||
const SenderBubble = ({ isLastRead, otherUser, time, text }) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
|
@@ -36,6 +43,11 @@ const SenderBubble = ({ time, text }) => { | |
<Box className={classes.bubble}> | ||
<Typography className={classes.text}>{text}</Typography> | ||
</Box> | ||
{isLastRead && <Avatar | ||
alt={otherUser.username} | ||
src={otherUser.photoUrl} | ||
className={classes.avatar} | ||
/>} | ||
Comment on lines
+46
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
</Box> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.4 on 2022-04-18 12:43 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('messenger_backend', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='message', | ||
name='readAt', | ||
field=models.DateTimeField(null=True), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ class Message(utils.CustomModel): | |
related_name="messages", | ||
related_query_name="message" | ||
) | ||
readAt = models.DateTimeField(null=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this works for the implementation you created, it adds a lot of complexity to the code, since now you're having to do more work to count the number of read messages and it makes it more difficult to also add the avatar image under the last read message that is present in the mocks. Let's not update time implementation as it would require a lot of code changes throughout the PR. 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback! Yeah, the time implementation was certainly more complex but I was trying to think ahead for future updates that may want to access when messages were read. Absolutely agreed though that for this particular implementation a boolean would have sufficed. |
||
createdAt = models.DateTimeField(auto_now_add=True, db_index=True) | ||
updatedAt = models.DateTimeField(auto_now=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referenced this in my PR description, but had to add these to prevent cypress from moving too quickly and dropping characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can safely ignore cypress tests for tickets other than your first ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, noted! Figured it'd be good practice to implement testing but will skip this in the future.