Skip to content

Commit 29892c1

Browse files
Add test for test run list
1 parent e38a48c commit 29892c1

File tree

6 files changed

+177
-7
lines changed

6 files changed

+177
-7
lines changed

e2e/elements/autocomplete.element.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ export class Autocomplete extends BaseElement implements WithSearch {
4444
async isEnabled() {
4545
return !(await this.disabledElement.isPresent());
4646
}
47+
48+
async hasOption(value: string) {
49+
await this.enterValue(value);
50+
return this.findOption(value).isPresent();
51+
}
4752
}

e2e/pages/testrun/list.po/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const names = {
1212
};
1313

1414
export const columns = {
15-
build: 'Build'
15+
build: 'Build',
16+
milestone: 'Milestone'
1617
};
1718

e2e/pages/testrun/list.po/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class TestRunList extends BasePage {
2727
return elements.testRunsTable.setFilter(buildName, columns.build);
2828
}
2929

30+
filterByMilestone(name: string) {
31+
return elements.testRunsTable.setFilter(name, columns.milestone);
32+
}
33+
3034
clickSuiteMatrix() {
3135
return elements.matrixButton.click();
3236
}
@@ -42,6 +46,19 @@ class TestRunList extends BasePage {
4246
return await this.isTestRunRowDisplayed(buildName);
4347
}, 5, 3000);
4448
}
49+
50+
async doesMilestonePresentInEdit(name: string, build_name: string): Promise<boolean> {
51+
const cellElements = await elements.testRunsTable.getElementsForCell(columns.milestone, build_name, columns.build);
52+
return cellElements.autocomplete().hasOption(name);
53+
}
54+
55+
setMilestone(name: string, build_name: string): Promise<void> {
56+
return elements.testRunsTable.editRow(name, columns.milestone, build_name, columns.build);
57+
}
58+
59+
isTableEditable(): any {
60+
return elements.testRunsTable.isRowEditableByIndex(0);
61+
}
4562
}
4663

4764
export const testRunList = new TestRunList();
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { logIn } from '../../pages/login.po';
2+
import { projectView } from '../../pages/project/view.po';
3+
import { ProjectHelper } from '../../helpers/project.helper';
4+
import { TestSuite } from '../../../src/app/shared/models/testSuite';
5+
import { testRunList } from '../../pages/testrun/list.po';
6+
import { TestRun } from '../../../src/app/shared/models/testRun';
7+
import { Milestone } from '../../../src/app/shared/models/milestone';
8+
import users from '../../data/users.json';
9+
import using from 'jasmine-data-provider';
10+
import cucumberImport from '../../data/import/cucumber.json';
11+
12+
const editorExamples = {
13+
localAdmin: users.localAdmin,
14+
localManager: users.localManager,
15+
manager: users.manager,
16+
localEngineer: users.localEngineer
17+
};
18+
19+
const notEditorExamples = {
20+
viewer: users.viewer,
21+
};
22+
23+
describe('Test Run List:', () => {
24+
const projectHelper: ProjectHelper = new ProjectHelper();
25+
const testRuns: { build_1: TestRun, build_2: TestRun } = {
26+
build_1: { build_name: 'build_1' },
27+
build_2: { build_name: 'build_2' }
28+
};
29+
const suite: TestSuite = { name: 'Smoke' };
30+
const milestones: { inactive: Milestone, active: Milestone } = {
31+
inactive: { name: '0.1.1', active: 0 },
32+
active: { name: '0.1.2' }
33+
};
34+
35+
beforeAll(async () => {
36+
await projectHelper.init({
37+
localEngineer: users.localEngineer,
38+
viewer: users.viewer,
39+
localAdmin: users.localAdmin,
40+
localManager: users.localManager
41+
});
42+
milestones.active = await projectHelper.editorAPI.createMilestone(milestones.active);
43+
milestones.inactive = await projectHelper.editorAPI.createMilestone(milestones.inactive);
44+
testRuns.build_1 = (await projectHelper.importer
45+
.executeCucumberImport(suite.name, [cucumberImport], [`${testRuns.build_1.build_name}.json`]))[0];
46+
testRuns.build_2 = (await projectHelper.importer
47+
.executeCucumberImport(suite.name, [cucumberImport], [`${testRuns.build_2.build_name}.json`]))[0];
48+
testRuns.build_1.milestone_id = milestones.inactive.id;
49+
testRuns.build_1 = await projectHelper.editorAPI.createTestRun(testRuns.build_1);
50+
});
51+
52+
afterAll(async () => {
53+
return projectHelper.dispose();
54+
});
55+
56+
using(editorExamples, (user, description) => {
57+
describe(`${description} role:`, () => {
58+
59+
beforeAll(async () => {
60+
await logIn.logInAs(user.user_name, user.password);
61+
return projectHelper.openProject();
62+
});
63+
64+
it('Can open Test Run List Page', async () => {
65+
await projectView.menuBar.testRuns();
66+
return expect(testRunList.isOpened()).toBe(true, 'Should be able to open Test Run List!');
67+
});
68+
69+
it('Can edit Test Run Milestone with only active milestones', async () => {
70+
return expect(testRunList.doesMilestonePresentInEdit(milestones.inactive.name, testRuns.build_2.build_name))
71+
.toBe(false, 'Inactive milestones should not be available in edit!');
72+
});
73+
74+
it('Can add Test Run Milestone', async () => {
75+
await testRunList.setMilestone(milestones.active.name, testRuns.build_2.build_name);
76+
return testRunList.notification.assertIsSuccess();
77+
});
78+
79+
it('Can filter by inactive Milestone', async () => {
80+
await testRunList.filterByMilestone(milestones.inactive.name);
81+
await expect(testRunList.isTestRunRowDisplayed(testRuns.build_2.build_name))
82+
.toBe(false, 'Test run with another milestone is still present');
83+
return expect(testRunList.isTestRunRowDisplayed(testRuns.build_1.build_name))
84+
.toBe(true, 'Test run with milestone is not present');
85+
});
86+
87+
it('Can filter by active Milestone', async () => {
88+
await testRunList.filterByMilestone(milestones.active.name);
89+
await expect(testRunList.isTestRunRowDisplayed(testRuns.build_1.build_name))
90+
.toBe(false, 'Test run with another milestone is still present');
91+
return expect(testRunList.isTestRunRowDisplayed(testRuns.build_2.build_name))
92+
.toBe(true, 'Test run with milestone is not present');
93+
});
94+
95+
it('Can remove Test Run Milestone', async () => {
96+
await testRunList.setMilestone('Not Assigned', testRuns.build_2.build_name);
97+
return testRunList.notification.assertIsSuccess();
98+
});
99+
});
100+
});
101+
102+
using(notEditorExamples, (user, description) => {
103+
describe(`${description} role:`, () => {
104+
105+
beforeAll(async () => {
106+
testRuns.build_2.milestone_id = milestones.active.id;
107+
testRuns.build_2 = await projectHelper.editorAPI.createTestRun(testRuns.build_2);
108+
await logIn.logInAs(user.user_name, user.password);
109+
return projectHelper.openProject();
110+
});
111+
112+
it('Can open Test Run List Page', async () => {
113+
await projectView.menuBar.testRuns();
114+
return expect(testRunList.isOpened()).toBe(true, 'Should be able to open Test Run List!');
115+
});
116+
117+
it('Can not edit Test Runs table', async () => {
118+
await projectView.menuBar.testRuns();
119+
return expect(testRunList.isTableEditable()).toBe(false, 'Should not be able to edit Test Runs!');
120+
});
121+
122+
it('Can filter by inactive Milestone', async () => {
123+
await testRunList.filterByMilestone(milestones.inactive.name);
124+
await expect(testRunList.isTestRunRowDisplayed(testRuns.build_2.build_name))
125+
.toBe(false, 'Test run with another milestone is still present');
126+
return expect(testRunList.isTestRunRowDisplayed(testRuns.build_1.build_name))
127+
.toBe(true, 'Test run with milestone is not present');
128+
});
129+
130+
it('Can filter by active Milestone', async () => {
131+
await testRunList.filterByMilestone(milestones.active.name);
132+
await expect(testRunList.isTestRunRowDisplayed(testRuns.build_1.build_name))
133+
.toBe(false, 'Test run with another milestone is still present');
134+
return expect(testRunList.isTestRunRowDisplayed(testRuns.build_2.build_name))
135+
.toBe(true, 'Test run with milestone is not present');
136+
});
137+
});
138+
});
139+
});

src/app/pages/project/testrun/testrun-list/testruns.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TestRunsComponent implements OnInit {
9494
values: this.labels,
9595
propToShow: ['name']
9696
},
97-
editable: true,
97+
editable: this.canEdit,
9898
class: 'fit'
9999
},
100100
{

src/app/services/testRun.service.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ import { TestRunStat } from '../shared/models/testrunStats';
1010
export class TestRunService extends SimpleRequester {
1111

1212
getTestRun(testRun: TestRun, limit: number = 0): Promise<TestRun[]> {
13-
if (!testRun.project_id) {
14-
testRun.project_id = this.route.snapshot.params['projectId'];
15-
}
13+
testRun = this.setProjectId(testRun);
1614
testRun['limit'] = limit;
1715
return this.doGet(`/testrun`, testRun).map(res => res.json()).toPromise();
1816
}
1917

2018
getTestRunWithChilds(testRun: TestRun, limit: number = 0): Promise<TestRun[]> {
21-
testRun.project_id = this.route.snapshot.params['projectId'];
19+
testRun = this.setProjectId(testRun);
2220
testRun['limit'] = limit;
2321
testRun['withChildren'] = 1;
2422
return this.doGet(`/testrun`, testRun).map(res => res.json()).toPromise();
2523
}
2624

2725
createTestRun(testRun: TestRun): Promise<TestRun> {
26+
testRun = this.setProjectId(testRun);
2827
if (testRun.testResults) {
2928
testRun.testResults = undefined;
3029
}
3130
return this.doPost('/testrun', testRun).map(res => res.json()).toPromise();
3231
}
3332

3433
removeTestRun(testRun: TestRun): Promise<void> {
34+
testRun = this.setProjectId(testRun);
3535
return this.doDelete(`/testrun`, { id: testRun.id, project_id: testRun.project_id })
3636
.map(() => this.handleSuccess(`Test run '${testRun.build_name}/${testRun.start_time}' was deleted.`)).toPromise();
3737
}
3838

3939
getTestsRunStats(testRun: TestRun, overlay: boolean = true): Promise<TestRunStat[]> {
40-
testRun.project_id = this.route.snapshot.params['projectId'];
40+
testRun = this.setProjectId(testRun);
4141
return this.doGet('/stats/testrun', testRun, overlay).map(res => res.json()).toPromise<TestRunStat[]>();
4242
}
4343

@@ -66,4 +66,12 @@ export class TestRunService extends SimpleRequester {
6666
getPassRate(stat: TestRunStat): string | number {
6767
return stat ? ((stat.passed / stat.total) * 100).toFixed(2) : 0;
6868
}
69+
70+
private setProjectId(testRun: TestRun): TestRun {
71+
if (!testRun.project_id) {
72+
testRun.project_id = this.route.snapshot.params.projectId;
73+
}
74+
75+
return testRun;
76+
}
6977
}

0 commit comments

Comments
 (0)