Skip to content

Commit 116d5fd

Browse files
committed
swapTestCases and containsTest methods
1 parent 3ff7c79 commit 116d5fd

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/selenium-ide/src/neo/__test__/models/Suite.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ describe("Suite model", () => {
120120
suite.removeTestCase(new TestCase());
121121
expect(suite.tests.length).toBe(1);
122122
});
123+
it("shoul tell if a test exist in the suite", () => {
124+
const suite = new Suite();
125+
const exists = new TestCase();
126+
const nonExistent = new TestCase();
127+
suite.addTestCase(exists);
128+
expect(suite.containsTest(exists)).toBeTruthy();
129+
expect(suite.containsTest(nonExistent)).toBeFalsy();
130+
});
131+
it("should swap the test cases", () => {
132+
const suite = new Suite();
133+
const test1 = new TestCase();
134+
const test2 = new TestCase();
135+
suite.addTestCase(test1);
136+
suite.addTestCase(test2);
137+
expect(suite.tests[0]).toBe(test1);
138+
expect(suite.tests[1]).toBe(test2);
139+
suite.swapTestCases(0, 1);
140+
expect(suite.tests[1]).toBe(test1);
141+
expect(suite.tests[0]).toBe(test2);
142+
});
123143
it("should replace the tests in the suite", () => {
124144
const store = new ProjectStore();
125145
const suite = new Suite();

packages/selenium-ide/src/neo/models/Suite.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class Suite {
3636
}
3737

3838
@computed get tests() {
39+
return this._tests;
3940
return this._tests.sort((t1, t2) => (
4041
naturalCompare(t1.name, t2.name)
4142
));
@@ -71,6 +72,10 @@ export default class Suite {
7172
}
7273
}
7374

75+
@action.bound containsTest(test) {
76+
return this._tests.includes(test);
77+
}
78+
7479
@action.bound addTestCase(test) {
7580
if (!this.isTest(test)) {
7681
throw new Error(`Expected to receive TestCase instead received ${test ? test.constructor.name : test}`);
@@ -79,6 +84,14 @@ export default class Suite {
7984
}
8085
}
8186

87+
@action.bound insertTestCaseAt(test, index) {
88+
if (!this.isTest(test)) {
89+
throw new Error(`Expected to receive TestCase instead received ${test ? test.constructor.name : test}`);
90+
} else {
91+
this._tests.splice(index, 0, test);
92+
}
93+
}
94+
8295
@action.bound removeTestCase(test) {
8396
if (!this.isTest(test)) {
8497
throw new Error(`Expected to receive TestCase instead received ${test ? test.constructor.name : test}`);
@@ -87,6 +100,11 @@ export default class Suite {
87100
}
88101
}
89102

103+
@action.bound swapTestCases(from, to) {
104+
const test = this._tests.splice(from, 1)[0];
105+
this.insertTestCaseAt(test, to);
106+
}
107+
90108
@action.bound replaceTestCases(tests) {
91109
if (tests.filter(test => !this.isTest(test)).length) {
92110
throw new Error("Expected to receive array of TestCase");

0 commit comments

Comments
 (0)