diff --git a/cypress/e2e/notes-100/comment-delete.cy.js b/cypress/e2e/notes-100/comment-delete.cy.js new file mode 100644 index 000000000..3f727a6bc --- /dev/null +++ b/cypress/e2e/notes-100/comment-delete.cy.js @@ -0,0 +1,27 @@ +import '@percy/cypress' +import { + homepageSetup, + returningUserVisitsHomepageWaitForModel, + auth0Login, +} from '../../support/utils' + +/** {@link https://github.com/bldrs-ai/Share/issues/1187} */ +describe('Notes 100: Comment delete', () => { + beforeEach(homepageSetup) + context('Returning user visits homepage', () => { + beforeEach(returningUserVisitsHomepageWaitForModel) + context('Open Notes > first note', () => { + beforeEach(() => { + cy.get('[data-testid="control-button-notes"]').click() + cy.get('[data-testid="list-notes"] :nth-child(1) > [data-testid="note-body"]').first().click() + }) + it('Deleted comment disappears from the list', () => { + auth0Login() + cy.get(`[data-testid="list-notes"] > :nth-child(3) + > [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="deleteComment"]`).click() + cy.get('[data-testid="list-notes"] > :nth-child(3) > [data-testid="note-card"]').should('not.contain', 'testComment_1') + cy.percySnapshot() + }) + }) + }) +}) diff --git a/package.json b/package.json index 9d2b28347..79726ee09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bldrs", - "version": "1.0.1073", + "version": "1.0.1072", "main": "src/index.jsx", "license": "AGPL-3.0", "homepage": "https://github.com/bldrs-ai/Share", diff --git a/src/Components/Notes/NoteCard.jsx b/src/Components/Notes/NoteCard.jsx index 2b2dcc79b..e369092c5 100644 --- a/src/Components/Notes/NoteCard.jsx +++ b/src/Components/Notes/NoteCard.jsx @@ -7,8 +7,10 @@ import {useAuth0} from '../../Auth0/Auth0Proxy' import { closeIssue, updateIssue, - // TODO(pablo): deleteComment as deleteCommentGitHub, } from '../../net/github/Issues' +import { + deleteComment, +} from '../../net/github/Comments' import useStore from '../../store/useStore' import {assertDefined} from '../../utils/assert' import {getHashParamsFromHashStr, setHashParams} from '../../utils/location' @@ -61,9 +63,8 @@ export default function NoteCard({ const notes = useStore((state) => state.notes) const repository = useStore((state) => state.repository) const selectedNoteId = useStore((state) => state.selectedNoteId) - // TODO(pablo) - // const comments = useStore((state) => state.comments) - // const setComments = useStore((state) => state.setComments) + const comments = useStore((state) => state.comments) + const setComments = useStore((state) => state.setComments) const setNotes = useStore((state) => state.setNotes) const setSelectedNoteId = useStore((state) => state.setSelectedNoteId) const setSelectedNoteIndex = useStore((state) => state.setSelectedNoteIndex) @@ -158,16 +159,12 @@ export default function NoteCard({ * @param {string} accessToken * @param {number} commentId */ - // TODO(pablo) - /* async function deleteComment(commentId) { - // TODO(pablo): handle response - await deleteCommentGitHub(repository, commentId, accessToken) - const newComments = comments.map((comment) => ({ - ...comment, - synched: (comment.id !== commentId) && comment.synched, - })) + async function deleteCommentGithub(commentId) { + // eslint-disable-next-line no-unused-vars + const res = await deleteComment(repository, commentId, accessToken) + const newComments = comments.filter((comment) => comment.id !== commentId) setComments(newComments) - } */ + } /** Update issue on GH, set read-only */ @@ -227,6 +224,7 @@ export default function NoteCard({ selectCard={selectCard} selected={selected} submitUpdate={submitUpdate} + deleteComment={deleteCommentGithub} synched={synched} username={username} /> diff --git a/src/Components/Notes/NoteFooter.jsx b/src/Components/Notes/NoteFooter.jsx index 257d11c55..276268f29 100644 --- a/src/Components/Notes/NoteFooter.jsx +++ b/src/Components/Notes/NoteFooter.jsx @@ -11,6 +11,7 @@ import AddCommentOutlinedIcon from '@mui/icons-material/AddCommentOutlined' import CheckIcon from '@mui/icons-material/Check' import ForumOutlinedIcon from '@mui/icons-material/ForumOutlined' import GitHubIcon from '@mui/icons-material/GitHub' +import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline' import PhotoCameraIcon from '@mui/icons-material/PhotoCamera' import CameraIcon from '../../assets/icons/Camera.svg' import PlaceMarkIcon from '../../assets/icons/PlaceMark.svg' @@ -23,6 +24,7 @@ import ShareIcon from '../../assets/icons/Share.svg' */ export default function NoteFooter({ accessToken, + deleteComment, editMode, embeddedCameras, id, @@ -63,13 +65,14 @@ export default function NoteFooter({ '_blank') } + return ( {isNote && } aboutInfo={false} @@ -80,7 +83,7 @@ export default function NoteFooter({ } aboutInfo={false} @@ -90,7 +93,7 @@ export default function NoteFooter({ { onClickShare() setShareIssue(!shareIssue) @@ -113,7 +116,7 @@ export default function NoteFooter({ { togglePlaceMarkActive(id) }} @@ -130,7 +133,7 @@ export default function NoteFooter({ { setScreenshotUri(viewer.takeScreenshot()) }} @@ -138,40 +141,48 @@ export default function NoteFooter({ /> } - {editMode && - } - onClick={() => submitUpdate(repository, accessToken, id)} - /> - } - {isNote && !selected && } /> } - {numberOfComments > 0 && !editMode && - - {!selected && + + {editMode && } + title='Save' + placement='top' + icon={} + onClick={() => submitUpdate(repository, accessToken, id)} /> - } - {!selected && numberOfComments} - - } + } + {!selected && numberOfComments > 0 && !editMode && + <> + } + /> + {numberOfComments} + + } + {!isNote && user && username === user.nickname && + } + onClick={() => deleteComment(id)} + /> + } + ) } diff --git a/src/Components/Notes/Notes.jsx b/src/Components/Notes/Notes.jsx index a08f24204..29b2b93f8 100644 --- a/src/Components/Notes/Notes.jsx +++ b/src/Components/Notes/Notes.jsx @@ -29,7 +29,6 @@ export default function Notes() { const repository = useStore((state) => state.repository) const selectedNoteId = useStore((state) => state.selectedNoteId) const setComments = useStore((state) => state.setComments) - const [hasError, setHasError] = useState(false) const {user} = useAuth0() diff --git a/src/__mocks__/api-handlers.js b/src/__mocks__/api-handlers.js index e232c709a..aa378e091 100644 --- a/src/__mocks__/api-handlers.js +++ b/src/__mocks__/api-handlers.js @@ -66,7 +66,7 @@ function githubHandlers(githubStore) { rest.get(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber/comments`, (req, res, ctx) => { const {org, repo, issueNumber} = req.params - + // TODO(oleg) replace org with cypresstester https://github.com/bldrs-ai/Share/issues/1218 if (org !== 'pablo-mayrgundter' || repo !== 'Share' || !issueNumber) { return res(ctx.status(httpNotFound)) } @@ -208,7 +208,7 @@ function githubHandlers(githubStore) { rest.post(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber/comments`, (req, res, ctx) => { const {org, repo, issueNumber} = req.params - if (org !== 'pablo-mayrgundter' || repo !== 'Share' || !issueNumber) { + if (org !== 'cypresstester' || repo !== 'Share' || !issueNumber) { return res(ctx.status(httpNotFound)) } return res( @@ -218,6 +218,7 @@ function githubHandlers(githubStore) { rest.patch(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber`, (req, res, ctx) => { const {org, repo} = req.params + // TODO(oleg) add org cypresstester condition https://github.com/bldrs-ai/Share/issues/1218 if (org !== 'pablo-mayrgundter' || repo !== 'Share' ) { return res( ctx.status(httpNotFound), @@ -233,9 +234,9 @@ function githubHandlers(githubStore) { }), rest.delete(`${GH_BASE}/repos/:org/:repo/issues/comments/:commentId`, (req, res, ctx) => { - const {org, repo, commentId} = req.params - - if (org !== 'bldrs-ai' || repo !== 'Share' || !commentId) { + const {repo, commentId} = req.params + // TODO(oleg) add org cypresstester condition https://github.com/bldrs-ai/Share/issues/1218 + if (repo !== 'Share' || !commentId) { return res(ctx.status(httpNotFound)) } diff --git a/src/net/github/Comments.fixture.js b/src/net/github/Comments.fixture.js index 5efaa99c4..f8e15c142 100644 --- a/src/net/github/Comments.fixture.js +++ b/src/net/github/Comments.fixture.js @@ -11,7 +11,7 @@ export const MOCK_COMMENTS = { node_id: 'IC_kwDOFwgxOc5EPlQ3', number: 1, user: { - login: 'OlegMoshkovich', + login: 'cypresstester', id: 3433607, node_id: 'MDQ6VXNlcjM0MzM2MDY=', avatar_url: 'https://avatars.githubusercontent.com/u/3433606?v=4', @@ -56,7 +56,7 @@ export const MOCK_COMMENTS = { number: 2, node_id: 'IC_kwDOFwgxOc5EPlQ3', user: { - login: 'OlegMoshkovich', + login: 'cypresstester', id: 3433606, node_id: 'MDQ6VXNlcjM0MzM2MDY=', avatar_url: 'https://avatars.githubusercontent.com/u/3433606?v=4', diff --git a/src/net/github/Comments.test.js b/src/net/github/Comments.test.js index 642ccf627..e95f51c7e 100644 --- a/src/net/github/Comments.test.js +++ b/src/net/github/Comments.test.js @@ -9,12 +9,12 @@ const httpCreated = 201 describe('net/github/Comments', () => { it('successfully create comment', async () => { - const res = await createComment({orgName: 'pablo-mayrgundter', name: 'Share'}, 1, {title: 'title', body: 'body'}) + const res = await createComment({orgName: 'cypresstester', name: 'Share'}, 1, {title: 'title', body: 'body'}) expect(res.status).toEqual(httpCreated) }) it('successfully delete comment', async () => { - const res = await deleteComment({orgName: 'bldrs-ai', name: 'Share'}, 1) + const res = await deleteComment({orgName: 'cypresstester', name: 'Share'}, 1) expect(res.status).toEqual(httpOK) }) })