Skip to content
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

Enhance/votestatusbuttons #86

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions cypress/e2e/createContributors.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let cypress = {};
try {
cypress = require('../../cypress.env.json');
} catch (error) {
console.warn('No cypress.env.json file in root directory. To run tests, follow the readme in /cypress');
}

describe('Create users, transfer them VotePower', () => {
it('should create users, and transfer 50_000 VotePower to each one.', () => {
const { testers } = cypress;

for (let objectKey in testers) {
let bot = testers[objectKey];
let { key, user, apiToken } = bot;

cy.findOrCreateUser(
Cypress.env('turbosrcID'),
Cypress.env('gitHubUsername'),
Cypress.env('gitHubRepo'),
key,
user,
key + key,
apiToken
);

cy.getNameSpaceRepo(`${Cypress.env('gitHubUsername')}/${Cypress.env('gitHubRepo')}`).then(res =>
cy
.request({
method: 'POST',
url: 'http://localhost:4000/graphql',
body: {
operationName: 'transferTokens',
query: `
query transferTokens {
transferTokens(
turboSrcID: "${Cypress.env('turboSrcID')}",
owner: "${Cypress.env('gitHubUsername')}",
repo: "${res.repoID}",
from: "${Cypress.env('contributorID')}",
to: "${key}",
amount: ${5000},
token: "${Cypress.env('gitHubToken')}"
)
{ status }
}
`
}
})
.then(response => {
// Your assertions and further actions here
expect(response.body.data.transferTokens).to.have.property('status', 201);
})
);
}
});
});
53 changes: 53 additions & 0 deletions cypress/e2e/createRepo.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
let cypress = {};
try {
cypress = require('../../cypress.env.json');
} catch (error) {
console.warn('No cypress.env.json file in root directory. To run tests, follow the readme in /cypress');
}

const createRepoRequestBody = (repoName, contributorID, token) => {
return {
method: 'POST',
url: 'http://localhost:4000/graphql',
body: {
operationName: 'createRepo',
query: `
query createRepo {
createRepo(
turboSrcID: "${Cypress.env('turboSrcID')}",
owner: "",
repo: "${repoName}",
defaultHash: "",
contributor_id: "${contributorID}",
side: "",
token: "${token}"
)
}
`
}
};
};

describe('Create repo', () => {
it('should create a user and a repo', () => {
// See cypress/support/commands.js

// Create maintainer user:
cy.findOrCreateUser(
Cypress.env('turbosrcID'),
Cypress.env('gitHubUsername'),
Cypress.env('gitHubRepo'),
Cypress.env('contributorID'),
Cypress.env('gitHubUsername'),
Cypress.env('contributorSignature'),
Cypress.env('gitHubToken')
);

const repoName = `${Cypress.env('gitHubUsername')}/${Cypress.env('gitHubRepo')}`;
const createDemoRepoRequestBody = createRepoRequestBody(repoName, Cypress.env('contributorID'), Cypress.env('gitHubToken'))
// Create demo repo
cy.request(createDemoRepoRequestBody).then(response => {
expect(Number(response.body.data.createRepo)).to.equal(201);
});
});
});
18 changes: 0 additions & 18 deletions cypress/e2e/seedData.cy.js

This file was deleted.

63 changes: 63 additions & 0 deletions cypress/e2e/voteToMerge.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
let cypress = {};
try {
cypress = require('../../cypress.env.json');
} catch (error) {
console.warn('No cypress.env.json file in root directory. To run tests, follow the readme in /cypress');
}

const setVoteRequestBody = (turboSrcID, owner, repo, defaultHash, childDefaultHash, mergeable, contributor_id, side, token) => {
return {
method: 'POST',
url: 'http://localhost:4000/graphql',
body: {
operationName: 'setVote',
query: `
query setVote {
setVote(
turboSrcID: "${turboSrcID}",
owner: "${owner}",
repo: "${repo}",
defaultHash: "${defaultHash}",
childDefaultHash: "${childDefaultHash}",
mergeable: ${mergeable},
contributor_id: "${contributor_id}",
side: "${side}",
token: "${token}"
)
}
`
}
};
};

describe('Voting', () => {
it('should vote on PR #1', () => {
cy.login();

cy.visit(`https://github.com/${Cypress.env('gitHubUsername')}/${Cypress.env('gitHubRepo')}/pulls`);

const { testers } = cypress;
for (let objectKey in testers) {
let bot = testers[objectKey];
let { key, apiToken } = bot;

const testerVoteRequestBody = setVoteRequestBody(
Cypress.env('turboSrcID'),
Cypress.env('gitHubUsername'),
res.repoID,
'issue_1',
'issue_1',
true,
key,
'yes',
apiToken
);

cy.getNameSpaceRepo(`${Cypress.env('gitHubUsername')}/${Cypress.env('gitHubRepo')}`).then(res =>
cy.request(testerVoteRequestBody).then(response => {
expect(response.body.data.setVote).to.equal('201');
})
);
}
});
});
61 changes: 52 additions & 9 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ Cypress.Commands.add(
`
}
}).then(response => {
expect(response.body.data.findOrCreateUser).to.have.property('contributor_name', Cypress.env('gitHubUsername'));
expect(response.body.data.findOrCreateUser).to.have.property('contributor_id', Cypress.env('contributorID'));
expect(response.body.data.findOrCreateUser).to.have.property(
'contributor_signature',
Cypress.env('contributorSignature')
);
expect(response.body.data.findOrCreateUser).to.have.property('token', Cypress.env('gitHubToken'));
expect(response.body.data.findOrCreateUser).to.have.property('contributor_name', contributor_name);
});
}
);
Expand All @@ -105,7 +99,7 @@ Cypress.Commands.add('createRepo', () => {
query createRepo {
createRepo(
turboSrcID: "${Cypress.env('turboSrcID')}",
owner: "",
owner: "${Cypress.env('gitHubUsername')}",
repo: "${Cypress.env('gitHubUsername')}/${Cypress.env('gitHubRepo')}",
defaultHash: "",
contributor_id: "${Cypress.env('contributorID')}",
Expand Down Expand Up @@ -184,6 +178,55 @@ Cypress.Commands.add('getRepoData', () => {
}`
}
}).then(response => {
expect(response.body.data.getRepoData).to.have.property('contributor_id', Cypress.env('contributorID'));
Cypress.env('repoID', response.body.data.getRepoData.repo_id);
});
});

Cypress.Commands.add('getNameSpaceRepo', repo => {
cy.request({
method: 'POST',
url: 'http://localhost:4000/graphql',
body: {
operationName: 'getNameSpaceRepo',
query: `
query getNameSpaceRepo {
getNameSpaceRepo(
repoNameOrID: "${repo}",
)
{ status, repoID }
}
`
}
}).then(response => {
// Your assertions and further actions here
expect(response.body.data.getNameSpaceRepo).to.have.property('status', 200);
return cy.wrap(response.body.data.getNameSpaceRepo);
});
});

Cypress.Commands.add('transferTokens', (turboSrcID, owner, repo, from, to, amount, token) => {
cy.request({
method: 'POST',
url: 'http://localhost:4000/graphql',
body: {
operationName: 'transferTokens',
query: `
query transferTokens {
transferTokens(
turboSrcID: "${Cypress.env('turboSrcID')}",
owner: "${Cypress.env('gitHubUsername')}",
repo: "${Cypress.env('repoID')}",
from: "${from}",
to: "${to}",
amount: ${amount},
token: "${Cypress.env('gitHubToken')}"
)
{ status }
}
`
}
}).then(response => {
// Your assertions and further actions here
expect(response.body.data.transferTokens).to.have.property('status', 201);
});
});
Binary file added icons/Lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/triangle-arrow-down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/triangle-arrow-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions src/Components/DOM/ButtonProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import styled from 'styled-components';

const YesBar = styled.div`
background-color: #038800;
height: 3px;
flex-basis: ${props => props.flexBasis}%;
border-radius: ${props => props.roundedCorners || '0px'};
`;

const NoBar = styled(YesBar)`
background-color: #d33131;
flex-basis: ${props => props.flexBasis}%;
`;

const RemainingBar = styled(YesBar)`
background-color: #d9d9d9;
flex-basis: ${props => props.flexBasis}%;
`;

const VoteBar = styled.div`
display: flex;
height: 5px;
width: 100%;
margin-bottom: 4px;
margin-top: 5px;
filter: drop-shadow(0px 1px 1px rgba(0, 0, 0, 0.35));
& > div:first-child {
border-radius: 2px 0px 0px 2px;
}

& > div:last-child {
border-radius: 0px 2px 2px 0px;
}
`;

const ButtonProgress = ({ yesPercent, noPercent, quorum, totalVotes }) => {
const difference = 1 / quorum;
const yesWidth = yesPercent * 100 * difference;
const noWidth = noPercent * 100 * difference;
const remainingVotesPercent = 100 - (yesWidth + noWidth);

if (totalVotes > 0) {
return (
<>
<VoteBar>
{yesPercent >= noPercent ? (
<>
<NoBar flexBasis={noWidth} />
<YesBar flexBasis={yesWidth} />
</>
) : (
<>
<YesBar flexBasis={yesWidth} />
<NoBar flexBasis={noWidth} />
</>
)}
{remainingVotesPercent > 0 && <RemainingBar flexBasis={remainingVotesPercent} />}
</VoteBar>
</>
);
} else {
return null;
}
};
export default ButtonProgress;
Empty file.
Loading