From 9620a171671bdee53325876564e65da57c458e1a Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 28 Mar 2022 22:40:28 +0200 Subject: [PATCH] Add verified badge to commit listing Signed-off-by: Sebastian Martinez --- cypress/fixtures/groupedCommits.json | 42 ++++++++++++ cypress/fixtures/projectCommits.json | 71 +++++++++++++++++--- cypress/integration/project.spec.ts | 70 ++++++++++--------- src/base/projects/Commit/CommitTeaser.svelte | 26 ++++--- src/base/projects/History.svelte | 18 ++--- src/commit.ts | 31 +++++++-- 6 files changed, 191 insertions(+), 67 deletions(-) create mode 100644 cypress/fixtures/groupedCommits.json diff --git a/cypress/fixtures/groupedCommits.json b/cypress/fixtures/groupedCommits.json new file mode 100644 index 000000000..f661f4fc6 --- /dev/null +++ b/cypress/fixtures/groupedCommits.json @@ -0,0 +1,42 @@ +[ + { + "groupDate": "Thursday, March 3, 2022", + "commits": [ + { + "sha": "9cd3532", + "summary": "Second commit", + "description": "", + "committer": { + "name": "dabit3", + "mail": "dabit3@gmail.com" + }, + "committerTime": "Thu, 03 Mar 2022 05:51:25 GMT" + } + ] + }, + { + "groupDate": "Wednesday, March 2, 2022", + "commits": [ + { + "sha": "e045b92", + "summary": "Update README", + "description": "", + "committer": { + "name": "dabit3", + "mail": "dabit3@gmail.com" + }, + "committerTime": "Wed, 02 Mar 2022 16:14:45 GMT" + }, + { + "sha": "cbf5df4", + "summary": "initial commit", + "description": "this is the first commit of many", + "committer": { + "name": "dabit3", + "mail": "dabit3@gmail.com" + }, + "committerTime": "Wed, 02 Mar 2022 15:58:05 GMT" + } + ] + } +] diff --git a/cypress/fixtures/projectCommits.json b/cypress/fixtures/projectCommits.json index 7548d36b2..480d0d3ce 100644 --- a/cypress/fixtures/projectCommits.json +++ b/cypress/fixtures/projectCommits.json @@ -1,18 +1,69 @@ { "headers": [ { - "sha1": "cbf5df499ab4f4a908f1756fbe2c236a4530516a", - "author": { - "name": "dabit3", - "email": "dabit3@gmail.com" + "header": { + "sha1": "cbf5df499ab4f4a908f1756fbe2c236a4530516a", + "author": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "summary": "initial commit", + "description": "", + "committer": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "committerTime": 1646236685 }, - "summary": "initial commit", - "description": "", - "committer": { - "name": "dabit3", - "email": "dabit3@gmail.com" + "context": { + "committer": { + "peer": { + "id": "hyyg555wwkkutaysg6yr67qnu5d5ji54iur3n5uzzszndh8dp7ofue", + "person": { + "name": "sebastinez" + }, + "delegate": true + } + } + } + }, + { + "header": { + "sha1": "e045b92297d21a709f3dea84d692c482ee61f6b2", + "author": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "summary": "Update README", + "description": "", + "committer": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "committerTime": 1646237685 }, - "committerTime": 1646236685 + "context": { + "committer": null + } + }, + { + "header": { + "sha1": "9cd353282bec77fef5dd56227173fc675d2363ce", + "author": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "summary": "Second commit", + "description": "", + "committer": { + "name": "dabit3", + "email": "dabit3@gmail.com" + }, + "committerTime": 1646286685 + }, + "context": { + "committer": null + } } ], "stats": { diff --git a/cypress/integration/project.spec.ts b/cypress/integration/project.spec.ts index df967f704..87f5164fa 100644 --- a/cypress/integration/project.spec.ts +++ b/cypress/integration/project.spec.ts @@ -77,39 +77,47 @@ describe("Project View", () => { }); cy.get("div.stat.commit-count").should("have.class", "active"); - cy.log("Commit Group"); - cy.get("header.commit-date").should("have.text", "Wednesday, March 2, 2022"); + cy.log("Commit Group & Commit Trailer"); + cy.fixture("groupedCommits.json").then((commitGroup) => { + // This iterates over the commit groups and then over each commit. + cy.get("div.commit-group").should("have.length", 2) + .each((item, index) => { + expect(Cypress.$(item.children(".commit-date")).text()).to.eq(commitGroup[index].groupDate); + const $el = Cypress.$(item.find(".commit")); + cy.wrap($el).each((commit, commitIndex) => { + expect(Cypress.$(commit).find(".hash").text()).to.eq(commitGroup[index].commits[commitIndex].sha); + expect(Cypress.$(commit).find("span.summary").text()).to.eq(commitGroup[index].commits[commitIndex].summary); + expect(Cypress.$(commit).find(".author").text()).to.eq(commitGroup[index].commits[commitIndex].committer.name); + expect(Cypress.$(commit).find(".time").text()).to.eq(commitGroup[index].commits[commitIndex].committerTime); + }); + }); - cy.log("Commit Trailer"); - cy.get("div.summary span.hash") - .should("have.text", "cbf5df4") - .next() - .should("have.text", "initial commit"); - cy.get("div.commit div.right span") - .first() - .should("have.text", "dabit3") - .next() - .should("have.text", "Wed, 02 Mar 2022 15:58:05 GMT"); - cy.get("div.summary").click(); + // Checking that the initial commit has the Verified badge + cy.get(".badge").last().should("have.text", "Verified"); + cy.get("div.summary").last().click(); - cy.log("Commit Detail View"); - cy.location().should((location) => { - expect(location.pathname).to.eq('/seeds/willow.radicle.garden/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/remotes/hyndc7nx9keq76p1bkw9831arcndeeu3trwsc7kxt3osmpi6j9oeke/commits/cbf5df499ab4f4a908f1756fbe2c236a4530516a'); + cy.log("Commit Detail View"); + // We get the initial commit from the fixture file to assert here + const { committer, committerTime, summary, description } = commitGroup[1].commits[1]; + + cy.location().should((location) => { + expect(location.pathname).to.eq('/seeds/willow.radicle.garden/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/remotes/hyndc7nx9keq76p1bkw9831arcndeeu3trwsc7kxt3osmpi6j9oeke/commits/cbf5df499ab4f4a908f1756fbe2c236a4530516a'); + }); + cy.get("header div.summary h3").should("have.text", summary); + cy.get("header pre.description").should("have.text", description); + cy.get("header div.meta") + .first() + .should("have.text", `Committed by ${committer.name} <${committer.mail}> ${committerTime}`) + .next() + .should("have.text", `Authored by ${committer.name} <${committer.mail}>`); + cy.get("div.changeset-summary").should("have.text", "1 file(s) changed\n with\n 0 addition(s)\n and\n 0 deletion(s)"); + cy.get("header.file-header:nth-child(1) div.file-data > *") + .first() + .should("have.text", "README.md") + .next() + .should("have.text", "created"); + cy.get("tr.diff-line td.diff-line-number").contains("16"); + cy.get("tr.diff-line td.diff-line-content").contains("To prevent front-running, the RAD/USDC balances are set through the Uniswap router *proxy* contract"); }); - cy.get("header div.summary h3").should("have.text", "initial commit"); - cy.get("header pre.description").should("have.text", "this is the first commit of many"); - cy.get("header div.meta") - .first() - .should("have.text", "Committed by dabit3 Wed, 02 Mar 2022 15:58:05 GMT") - .next() - .should("have.text", "Authored by dabit3 "); - cy.get("div.changeset-summary").should("have.text", "1 file(s) changed\n with\n 0 addition(s)\n and\n 0 deletion(s)"); - cy.get("header.file-header:nth-child(1) div.file-data > *") - .first() - .should("have.text", "README.md") - .next() - .should("have.text", "created"); - cy.get("tr.diff-line td.diff-line-number").contains("16"); - cy.get("tr.diff-line td.diff-line-content").contains("To prevent front-running, the RAD/USDC balances are set through the Uniswap router *proxy* contract"); }); }); diff --git a/src/base/projects/Commit/CommitTeaser.svelte b/src/base/projects/Commit/CommitTeaser.svelte index 1c5ff9317..8c03b7fa2 100644 --- a/src/base/projects/Commit/CommitTeaser.svelte +++ b/src/base/projects/Commit/CommitTeaser.svelte @@ -1,11 +1,18 @@