Skip to content

Commit 861cc89

Browse files
committed
remove targets from commands that dont need it
1 parent 11ac123 commit 861cc89

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@ describe('Command', () => {
7070
expect(command.target).toBe('a')
7171
})
7272
it('should set the targets', () => {
73-
const command = new Command()
73+
const command = new Command(undefined, 'click')
7474
command.setTargets([['button', 'xpath']])
7575
expect(command.targets[0][0]).toBe('button')
7676
expect(command.targets[0][1]).toBe('xpath')
7777
})
78+
it("should remove set targets if command doesn't support targets", () => {
79+
const command = new Command(undefined, 'click')
80+
command.setTargets([['button', 'xpath']])
81+
expect(command.targets.length).toBe(1)
82+
command.setCommand('open')
83+
expect(command.targets.length).toBe(0)
84+
})
7885
it('should set the value', () => {
7986
const command = new Command()
8087
command.setValue('123456')
@@ -177,7 +184,7 @@ describe('Command', () => {
177184
const jsRepresentation = {
178185
id: '1',
179186
comment: 'test',
180-
command: 'open',
187+
command: 'click',
181188
target: '/',
182189
targets: [['button', 'xpath']],
183190
value: 'test',

packages/selenium-ide/src/neo/models/Command/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { action, computed, observable, toJS } from 'mobx'
1919
import uuidv4 from 'uuid/v4'
2020
import Fuse from 'fuse.js'
21-
import { Commands as _Commands } from './Commands'
21+
import { Commands as _Commands, TargetTypes } from './Commands'
2222
import { ArgTypes as _ArgTypes } from './ArgTypes'
2323
const EventEmitter = require('events')
2424
import { mergeEventEmitter } from '../../../common/events'
@@ -74,6 +74,15 @@ export default class Command {
7474
return Commands.array.includes(this.command)
7575
}
7676

77+
@computed
78+
get canHaveTargets() {
79+
if (Commands.list.has(this.command)) {
80+
const { type } = Commands.list.get(this.command)
81+
return type === TargetTypes.LOCATOR
82+
}
83+
return false
84+
}
85+
7786
@action.bound
7887
clone() {
7988
const clone = new Command()
@@ -93,6 +102,10 @@ export default class Command {
93102
} else {
94103
this.command = command || ''
95104
}
105+
106+
if (!this.canHaveTargets) {
107+
this.setTargets()
108+
}
96109
}
97110

98111
@action.bound
@@ -102,7 +115,11 @@ export default class Command {
102115

103116
@action.bound
104117
setTargets(targets = []) {
105-
this.targets.replace(targets)
118+
if (this.canHaveTargets) {
119+
this.targets.replace(targets)
120+
} else {
121+
this.targets.replace([])
122+
}
106123
}
107124

108125
@action.bound

0 commit comments

Comments
 (0)