Skip to content

Commit

Permalink
test(e2e-protractor): build detals tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Aug 7, 2017
1 parent b423cbb commit e57b41f
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 63 deletions.
59 changes: 50 additions & 9 deletions e2e/050_builds.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ describe('Builds', () => {
.toContain('No builds has been runned yet.'));
});

it('should start new build (send push event)', () => {
return sendGitHubRequest(pushEventRequest, pushEventHeader)
.then((): any => browser.wait(() => element(by.css('.list-item')).isPresent()));
it('should start new build (send open_pull_request event)', () => {
return sendGitHubRequest(requestOpened, pullRequestHeader)
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 1;
})))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.build-time'))
.then(times => times[0])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05'));
}))
.then((): any => browser.wait(() => {
return element(by.css('.list-item:nth-child(1) .stop-build')).isPresent();
}))
.then((): any => element.all(by.css('.list-item:nth-child(1) .stop-build')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}));
});

it('should redirect after click on first build', () => {
Expand All @@ -47,34 +67,50 @@ describe('Builds', () => {
}));
});

it('should start new build (send open_pull_request event)', () => {
return sendGitHubRequest(requestOpened, pullRequestHeader)
it('should start new build (send reopen_pull_request event)', () => {
return sendGitHubRequest(requestReopened, pullRequestHeader)
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 2;
})))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.build-time'))
.then(times => times[0])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05'));
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
.then((): any => browser.wait(() => {
return element(by.css('.list-item:nth-child(1) .stop-build')).isPresent();
return element.all(by.css('.list-item:nth-child(1) .stop-build')).first().isPresent();
}))
.then((): any => element.all(by.css('.list-item:nth-child(1) .stop-build')).first().click())
.then((): any => {
return browser.wait(() => {
const el = element(by.css('.list-item:nth-child(1) .stop-build'));
return ExpectedConditions.elementToBeClickable(el);
});
})
.then((): any => element.all(by.css('.stop-build')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}));
});

it('should start new build (send reopen_pull_request event)', () => {
return sendGitHubRequest(requestReopened, pullRequestHeader)
it('should start new build (send push event)', () => {
return sendGitHubRequest(pushEventRequest, pushEventHeader)
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 3;
})))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.build-time'))
.then(times => times[0])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05'));
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
Expand Down Expand Up @@ -105,6 +141,11 @@ describe('Builds', () => {
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count > 0);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.build-time'))
.then(times => times[0])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:15'));
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
Expand Down
210 changes: 163 additions & 47 deletions e2e/060_build.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,179 @@ import { isLoaded, login, logout, waitForUrlToChangeTo, delay } from './utils';
import { request, header } from '../tests/e2e/webhooks/github/PushEvent';
import { sendGitHubRequest } from '../tests/e2e/utils/utils';

describe('Build', () => {
function randomNumber(minimum: number, maximum: number): number {
return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
}

describe('Build Details', () => {
beforeAll(() => login().then(() => browser.waitForAngularEnabled(false)));
afterAll(() => logout().then(() => browser.waitForAngularEnabled(true)));

it('should start new build (send open_pull_request event)', () => {
return sendGitHubRequest(request, header)
it('should restart existing build', () => {
return browser.get('/build/1')
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 4;
return cnt > 0;
})))
.then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})))
.then((): any => browser.wait(() => element(by.css('[name="restart-build"]')).isPresent()))
.then((): any => element(by.css('[name="restart-build"]')).click())
.then((): any => element.all(by.css('.list-item')).count())
.then(num => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === num;
})))
.then((): any => browser.wait(() => element(by.css('.list-item:nth-child(1)')).isPresent()))
.then((): any => element(by.css('.list-item:nth-child(1)')).click())
.then((): any => waitForUrlToChangeTo('http://localhost:6500/build/4'))
.then(() => element.all(by.css('[name="stop-job"]')).each(el => el.click()))
.then(num => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})));
});

it('should restart first job', () => {
return Promise.resolve()
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt >= 2;
return cnt > 0;
})))
.then((): any => element(by.css('.list-item:nth-child(1)')).click())
.then((): any => waitForUrlToChangeTo('http://localhost:6500/job/'))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-hidden')).count().then(cnt => cnt === 0);
}))
.then((): any => browser.wait(() => element(by.css('[name="btn-stop"]')).isDisplayed()))
.then((): any => element(by.css('[name="btn-stop"]')).click())
.then((): any => browser.wait(() => {
return element.all(by.css('.yellow')).count().then(count => count === 0);
}))
.then(() => browser.navigate().back())
.then(() => browser.navigate().back())
.then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})))
.then((): any => {
return browser
.wait(() => element.all(by.css('[name="restart-job"]')).first().isPresent());
})
.then((): any => element.all(by.css('[name="restart-job"]')).first().click())
.then((): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 1));
})
.then((): any => {
return browser.wait(() => element.all(by.css('.job-time')).then(els => els[0])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05')));
})
.then((): any => {
return browser
.wait(() => element.all(by.css('[name="stop-job"]')).first().isPresent());
})
.then((): any => element.all(by.css('[name="stop-job"]')).first().click())
.then((num): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 0));
});
});

it('should restart last job', () => {
return Promise.resolve()
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 4;
return cnt > 0;
})))
.then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})))
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
.then((): any => element.all(by.css('.stop-build')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}));
.then((): any => {
return browser
.wait(() => element.all(by.css('[name="restart-job"]')).last().isPresent());
})
.then((): any => element.all(by.css('[name="restart-job"]')).last().click())
.then((): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 1));
})
.then((): any => {
return browser.wait(() => element.all(by.css('.job-time')).then(els => els[els.length - 1])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05')));
})
.then((): any => {
return browser
.wait(() => element.all(by.css('[name="stop-job"]')).last().isPresent());
})
.then((): any => element.all(by.css('[name="stop-job"]')).last().click())
.then((num): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 0));
});
});

it('should restart job', () => {
return browser.get('/')
.then((): any => browser.wait(() => element(by.css('.list-item:nth-child(1)')).isPresent()))
.then((): any => element(by.css('.list-item:nth-child(1)')).click())
.then(() => waitForUrlToChangeTo('http://localhost:6500/build/'))
.then((): any => browser.wait(() => element(by.css('.list-item')).isPresent()))
.then((): any => element(by.css('.list-item:nth-child(1)')).click())
.then(() => waitForUrlToChangeTo('http://localhost:6500/job/'))
.then((): any => browser.wait(() => element(by.css('[name="btn-restart"]')).isDisplayed()))
.then((): any => element(by.css('[name="btn-restart"]')).click())
.then(() => browser.wait(() => {
return element.all(by.css('.yellow')).count().then(count => count > 0);
}))
.then(() => browser.get('/'))
.then((): any => browser.wait(() => element(by.css('.stop-build')).isPresent()))
.then(() => element.all(by.css('.stop-build')).first().click())
.then(() => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}));
it('should restart random job', () => {
let num = null;
return Promise.resolve()
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt > 0;
})))
.then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})))
.then((): any => element.all(by.css('.list-item')).count())
.then(numJobs => num = randomNumber(0, numJobs - 1))
.then((): any => {
return browser.wait(() => {
return element.all(by.css(`[name="restart-job"]`)).then(els => els[num])
.then(el => el.isPresent());
});
})
.then((): any => {
return element.all(by.css(`[name="restart-job"]`))
.then(els => els[num])
.then(el => el.click());
})
.then((): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 1));
})
.then((): any => {
return browser.wait(() => element.all(by.css('.job-time')).then(els => els[num])
.then(el => el.getAttribute('innerHTML').then(html => html === '00:05')));
})
.then((): any => {
return browser.wait(() => {
return element.all(by.css(`[name="stop-job"]`)).then(els => els[num])
.then(el => el.isPresent());
});
})
.then((): any => {
return element.all(by.css(`[name="stop-job"]`)).then(els => els[num])
.then(el => el.click());
})
.then((num): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 0));
});
});

it('should restart all jobs', () => {
return Promise.resolve()
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt > 0;
})))
.then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
return cnt === 0;
})))
.then((): any => {
return browser.wait(() => {
return element.all(by.css(`[name="restart-job"]`)).each(el => el.isPresent());
});
})
.then((): any => element.all(by.css(`[name="restart-job"]`)).each(el => el.click()))
.then((): any => element.all(by.css('.list-item')).count())
.then((num): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === num));
})
.then((): any => {
return browser.wait(() => element.all(by.css('.job-time')).each(el => {
return el.getAttribute('innerHTML').then(html => parseInt(html, 10) > 5);
}));
})
.then((): any => {
return browser.wait(() => {
return element.all(by.css(`[name="stop-job"]`)).each(el => el.isPresent());
});
})
.then((): any => {
return element.all(by.css(`[name="stop-job"]`)).each(el => el.click());
})
.then((num): any => {
return browser.wait(() => element.all(by.css('.is-running')).count()
.then(cnt => cnt === 0));
});
});
});
2 changes: 1 addition & 1 deletion protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.config = {
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
defaultTimeoutInterval: 120000,
print: function() {}
},
useAllAngular2AppRoots: true,
Expand Down
2 changes: 1 addition & 1 deletion src/api/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function stopJob(jobId: number): Promise<void> {
const job = processes.find(proc => proc.job_id == jobId);
if (!job) {
return Promise.resolve()
.then(() => dbJob.getJob(jobId))
.then(() => dbJob.resetJob(jobId))
.then(job => killContainer(`abstruse_${job.build_id}_${job.job_id}`));
} else {
return Promise.resolve()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="bold">
</h1>
</div>
<div class="column is-2">
<button class="button is-fullwidth" type="button" (click)="restartBuild($event, build.id)" [disabled]="processingBuild">
<button class="button is-fullwidth" name="restart-build" type="button" (click)="restartBuild($event, build.id)" [disabled]="processingBuild">
<div class="centered">
<span class="icon">
<img src="images/icons/restart.svg">
Expand Down Expand Up @@ -107,10 +107,10 @@ <h2>{{ build?.message }}</h2>
</div>
</div>
<div class="column is-1">
<span>{{ job.time }}</span>
<span class="job-time">{{ job.time }}</span>
</div>
<div class="column is-1">
<span class="icon" (click)="restartJob($event, job.id)">
<span class="icon" name="restart-job" (click)="restartJob($event, job.id)">
<svg width="15px" height="14px" viewBox="0 0 15 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="icon" fill-rule="nonzero" fill="#FFFFFF">
Expand All @@ -119,7 +119,7 @@ <h2>{{ build?.message }}</h2>
</g>
</svg>
</span>
<span class="icon" (click)="stopJob($event, job.id)">
<span class="icon" name="stop-job" (click)="stopJob($event, job.id)">
<svg width="44px" height="44px" viewBox="0 0 44 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="cancel-2" fill-rule="nonzero" fill="#FFFFFF">
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/app-builds/app-builds.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1>Dashboard</h1>
<span>{{ build?.author }}</span>
</div>
<div class="column is-1">
<span>{{ build?.totalTime }}</span>
<span class="build-time">{{ build?.totalTime }}</span>
</div>
<div class="column is-1 justify-end">
<span class="icon restart-build" (click)="restartBuild($event, build.id)" [class.disabled]="build.processingRequest">
Expand Down

0 comments on commit e57b41f

Please sign in to comment.