branch test

pull/4791/head
Your Name 6 months ago
parent 2e7af0d4f5
commit fb9c7f57b2
  1. 29
      apps/remix-ide-e2e/src/tests/dgit_local.test.ts
  2. 45
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  3. 6
      libs/remix-ui/git/src/components/navigation/branchedetails.tsx
  4. 2
      libs/remix-ui/git/src/components/navigation/branches.tsx
  5. 2
      libs/remix-ui/git/src/components/panels/branches.tsx

@ -3,7 +3,13 @@ import kill from 'tree-kill'
import init from "../helpers/init" import init from "../helpers/init"
import { Nightwatch, NightwatchBrowser } from "nightwatch" import { Nightwatch, NightwatchBrowser } from "nightwatch"
let gitserver: ChildProcess let gitserver: ChildProcess
// if needed kill the server: kill -9 $(sudo lsof -t -i:6868)
/*
/ uses the git-http-backend package to create a git server ( if needed kill the server: kill -9 $(sudo lsof -t -i:6868) )
/ GROUP 1: file operations PUSH PULL COMMIT SYNC FETCH CLONE ADD
/ GROUP 2: branch operations CREATE & PUBLISH
*/
module.exports = { module.exports = {
'@disabled': true, '@disabled': true,
before: function (browser, done) { before: function (browser, done) {
@ -17,14 +23,14 @@ module.exports = {
}) })
}, },
'run server #group1': function (browser: NightwatchBrowser) { 'run server #group1 #group2': function (browser: NightwatchBrowser) {
browser.perform(async (done) => { browser.perform(async (done) => {
gitserver = await spawnGitServer('/tmp/') gitserver = await spawnGitServer('/tmp/')
console.log('working directory', process.cwd()) console.log('working directory', process.cwd())
done() done()
}) })
}, },
'Update settings for git #group1': function (browser: NightwatchBrowser) { 'Update settings for git #group1 #group2': function (browser: NightwatchBrowser) {
browser. browser.
clickLaunchIcon('dgit') clickLaunchIcon('dgit')
.waitForElementVisible('*[data-id="initgit-btn"]') .waitForElementVisible('*[data-id="initgit-btn"]')
@ -35,7 +41,7 @@ module.exports = {
.modalFooterOKClick('github-credentials-error') .modalFooterOKClick('github-credentials-error')
.pause(2000) .pause(2000)
}, },
'clone a repo #group1': function (browser: NightwatchBrowser) { 'clone a repo #group1 #group2': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="clone-panel"]') .waitForElementVisible('*[data-id="clone-panel"]')
.click('*[data-id="clone-panel"]') .click('*[data-id="clone-panel"]')
@ -47,6 +53,9 @@ module.exports = {
.waitForElementVisible('*[data-id="treeViewLitreeViewItemREADME.md"]') .waitForElementVisible('*[data-id="treeViewLitreeViewItemREADME.md"]')
}, },
// GROUP 1
'check file added #group1': function (browser: NightwatchBrowser) { 'check file added #group1': function (browser: NightwatchBrowser) {
browser. browser.
addFile('test.txt', { content: 'hello world' }, 'README.md') addFile('test.txt', { content: 'hello world' }, 'README.md')
@ -94,7 +103,7 @@ module.exports = {
console.log(logs) console.log(logs)
browser.assert.ok(logs.includes('testcommit')) browser.assert.ok(logs.includes('testcommit'))
}, },
'change a file': function (browser: NightwatchBrowser) { 'change a file #group1': function (browser: NightwatchBrowser) {
browser. browser.
openFile('test.txt'). openFile('test.txt').
pause(1000). pause(1000).
@ -163,6 +172,16 @@ module.exports = {
browser browser
.clickLaunchIcon('filePanel') .clickLaunchIcon('filePanel')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtest2.txt"]') .waitForElementVisible('*[data-id="treeViewLitreeViewItemtest2.txt"]')
},
// GROUP 2
'create a branch #group2': function (browser: NightwatchBrowser) {
browser
.clickLaunchIcon('dgit')
.click('*[data-id="branches-panel"]')
.waitForElementVisible('*[data-id="newbranchname"]')
.setValue('*[data-id="newbranchname"]', 'testbranch')
.click('*[data-id="sourcecontrol-create-branch"]')
.waitForElementVisible('*[data-id="branches-current-branch-testbranch"]')
} }
} }

@ -7,7 +7,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { syncStateContext } from "./sourceControlBase"; import { syncStateContext } from "./sourceControlBase";
enum buttonStateValues { enum buttonStateValues {
Commit , Commit,
Sync = 1, Sync = 1,
PublishBranch = 2 PublishBranch = 2
} }
@ -24,7 +24,7 @@ export const CommitMessage = () => {
setMessage({ value: e.currentTarget.value }) setMessage({ value: e.currentTarget.value })
} }
const commit = async() => { const commit = async () => {
if (context.staged.length === 0 && context.allchangesnotstaged.length == 0) return if (context.staged.length === 0 && context.allchangesnotstaged.length == 0) return
if (context.staged.length === 0) if (context.staged.length === 0)
await actions.addall(context.allchangesnotstaged) await actions.addall(context.allchangesnotstaged)
@ -36,7 +36,7 @@ export const CommitMessage = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
} }
const sync = async() => { const sync = async () => {
await actions.pull({ await actions.pull({
remote: getRemote(), remote: getRemote(),
ref: context.currentBranch ref: context.currentBranch
@ -52,7 +52,7 @@ export const CommitMessage = () => {
} }
const commitNotAllowed = () => { const commitNotAllowed = () => {
return context.canCommit === false || message.value === "" || ( context.staged.length === 0 && context.allchangesnotstaged.length == 0 ) return context.canCommit === false || message.value === "" || (context.staged.length === 0 && context.allchangesnotstaged.length == 0)
} }
const commitMessagePlaceholder = () => { const commitMessagePlaceholder = () => {
@ -68,21 +68,28 @@ export const CommitMessage = () => {
const upDownArrows = () => { const upDownArrows = () => {
return ( return (
<> <>
{syncState.commitsBehind && syncState.commitsBehind.length ? <>{syncState.commitsBehind.length}<FontAwesomeIcon icon={faArrowDown} className="ml-1" /></>: null} {syncState.commitsBehind && syncState.commitsBehind.length ? <>{syncState.commitsBehind.length}<FontAwesomeIcon icon={faArrowDown} className="ml-1" /></> : null}
{syncState.commitsAhead && syncState.commitsAhead.length ? <>{syncState.commitsAhead.length}<FontAwesomeIcon icon={faArrowUp} className="ml-1" /></>: null} {syncState.commitsAhead && syncState.commitsAhead.length ? <>{syncState.commitsAhead.length}<FontAwesomeIcon icon={faArrowUp} className="ml-1" /></> : null}
</> </>
) )
} }
const publishEnabled = () => { const publishEnabled = () => {
const remoteEquivalentBranch = context.branches.find((b) => b.name === context.currentBranch.name && b.remote) const remoteEquivalentBranch = context.branches.find((b) => b.name === context.currentBranch.name && b.remote)
return remoteEquivalentBranch === undefined && getRemote()!== null return remoteEquivalentBranch === undefined && getRemote() !== null
} }
const publishBranch = async () => { const publishBranch = async () => {
if (context.currentBranch === undefined || context.currentBranch.name === "") if (context.currentBranch === undefined || context.currentBranch.name === "")
return return
//await actions.push(context.currentBranch.name) await actions.push({
remote: getRemote(),
ref: context.currentBranch
})
await actions.pull({
remote: getRemote(),
ref: context.currentBranch
})
} }
const messageEnabled = () => { const messageEnabled = () => {
@ -91,19 +98,19 @@ export const CommitMessage = () => {
const setButtonStateValues = () => { const setButtonStateValues = () => {
if (!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0){ if (!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0) {
if (context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()){ if (context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()) {
setButtonState(buttonStateValues.PublishBranch) setButtonState(buttonStateValues.PublishBranch)
return return
} }
setButtonState(buttonStateValues.Commit) setButtonState(buttonStateValues.Commit)
return return
} }
if (syncEnabled()){ if (syncEnabled()) {
setButtonState(buttonStateValues.Sync) setButtonState(buttonStateValues.Sync)
return return
} }
if (publishEnabled()){ if (publishEnabled()) {
setButtonState(buttonStateValues.PublishBranch) setButtonState(buttonStateValues.PublishBranch)
return return
} }
@ -112,24 +119,24 @@ export const CommitMessage = () => {
useEffect(() => { useEffect(() => {
setButtonStateValues() setButtonStateValues()
},[context.canCommit, context.staged, context.allchangesnotstaged, context.currentBranch, syncState.commitsAhead, syncState.commitsBehind, message.value]) }, [context.canCommit, context.staged, context.allchangesnotstaged, context.currentBranch, syncState.commitsAhead, syncState.commitsBehind, message.value])
return ( return (
<> <>
<div className="form-group"> <div className="form-group">
<input placeholder={commitMessagePlaceholder()} data-id='commitMessage' disabled={!messageEnabled()} className="form-control" type="text" onChange={handleChange} value={message.value} /> <input placeholder={commitMessagePlaceholder()} data-id='commitMessage' disabled={!messageEnabled()} className="form-control" type="text" onChange={handleChange} value={message.value} />
</div> </div>
<button data-id='commitButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Commit ?'':'d-none'}`} disabled={commitNotAllowed()} onClick={async () => await commit()} > <button data-id='commitButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Commit ? '' : 'd-none'}`} disabled={commitNotAllowed()} onClick={async () => await commit()} >
<FontAwesomeIcon icon={faCheck} className="mr-1" /> <FontAwesomeIcon icon={faCheck} className="mr-1" />
Commit Commit
</button> </button>
<button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ?'':'d-none'}`} disabled={!syncEnabled()} onClick={async () => await sync()} > <button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ? '' : 'd-none'}`} disabled={!syncEnabled()} onClick={async () => await sync()} >
<FontAwesomeIcon icon={faSync} className="mr-1" aria-hidden="true" /> <FontAwesomeIcon icon={faSync} className="mr-1" aria-hidden="true" />
Sync Changes {upDownArrows()} Sync Changes {upDownArrows()}
</button> </button>
<button data-id='publishBranchButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.PublishBranch ?'':'d-none'}`} onClick={async () => await publishBranch()} > <button data-id='publishBranchButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.PublishBranch ? '' : 'd-none'}`} onClick={async () => await publishBranch()} >
<FontAwesomeIcon icon={faCloudArrowUp} className="mr-1" aria-hidden="true" /> <FontAwesomeIcon icon={faCloudArrowUp} className="mr-1" aria-hidden="true" />
Publish Branch Publish Branch
</button> </button>
<hr></hr> <hr></hr>
</> </>

@ -58,7 +58,7 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
return ( return (
<> <>
<div className="d-flex flex-row w-100 mb-2 mt-2"> <div className="d-flex flex-row w-100 mb-2 mt-2">
<div onClick={() => handleClick()} role={'button'} className='pointer d-flex flex-row w-100 commit-navigation'> <div data-id={`branches-${context.currentBranch.name === branch.name ? 'current-' : ''}branch-${branch.name}`} onClick={() => handleClick()} role={'button'} className='pointer d-flex flex-row w-100 commit-navigation'>
{ {
activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon> activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon>
} }
@ -67,11 +67,11 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
</div> </div>
{context.currentBranch && context.currentBranch.name === branch.name ? {context.currentBranch && context.currentBranch.name === branch.name ?
<GitUIButton className="btn btn-sm p-0 mr-1" onClick={() => { }}> <GitUIButton data-id={`branches-toggle-current-branch-${branch.name}`} className="btn btn-sm p-0 mr-1" onClick={() => { }}>
<FontAwesomeIcon className='pointer text-success' icon={faToggleOff} ></FontAwesomeIcon> <FontAwesomeIcon className='pointer text-success' icon={faToggleOff} ></FontAwesomeIcon>
</GitUIButton> </GitUIButton>
: :
<GitUIButton className="btn btn-sm p-0 mr-1" onClick={() => checkout(branch)}> <GitUIButton data-id={`branches-toggle-branch-${branch.name}`} className="btn btn-sm p-0 mr-1" onClick={() => checkout(branch)}>
<FontAwesomeIcon icon={faToggleOn}></FontAwesomeIcon> <FontAwesomeIcon icon={faToggleOn}></FontAwesomeIcon>
</GitUIButton> </GitUIButton>
} }

@ -19,7 +19,7 @@ export const BranchesNavigation = ({ eventKey, activePanel, callback }) => {
return ( return (
<> <>
<div className={'d-flex justify-content-between pt-1 ' + (activePanel === eventKey? 'bg-light': '')}> <div className={'d-flex justify-content-between pt-1 ' + (activePanel === eventKey? 'bg-light': '')}>
<span onClick={()=>handleClick()} role={'button'} className='nav d-flex justify-content-start align-items-center w-75'> <span data-id='branches-panel' onClick={()=>handleClick()} role={'button'} className='nav d-flex justify-content-start align-items-center w-75'>
{ {
activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon> activePanel === eventKey ? <FontAwesomeIcon className='' icon={faCaretDown}></FontAwesomeIcon> : <FontAwesomeIcon className='' icon={faCaretRight}></FontAwesomeIcon>
} }

@ -41,11 +41,13 @@ export const Branches = () => {
placeholder="branch name" placeholder="branch name"
onChange={handleChange} onChange={handleChange}
className="form-control w-md-25 w-100" className="form-control w-md-25 w-100"
data-id="newbranchname"
type="text" type="text"
id="newbranchname" id="newbranchname"
/> />
</div> </div>
<GitUIButton <GitUIButton
data-id="sourcecontrol-create-branch"
onClick={async () => actions.createBranch(newBranch.value)} onClick={async () => actions.createBranch(newBranch.value)}
className="btn w-md-25 w-100 btn-primary" className="btn w-md-25 w-100 btn-primary"
id="createbranch-btn" id="createbranch-btn"

Loading…
Cancel
Save