ember-test-recorder
Version:
An Ember addon for recording and generating acceptance test cases through UI interactions
92 lines (75 loc) • 1.93 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class TestRecorderSidebarComponent extends Component {
testCaseGenerator;
eventManager;
isRecording = false;
assertionMode = false;
assertionType = 'ok';
activeTab = 'recorder';
get isRecorderTab() {
return this.activeTab === 'recorder';
}
get isEventsTab() {
return this.activeTab === 'events';
}
get events() {
return this.eventManager.events;
}
get testCases() {
return this.testCaseGenerator.testCaseCode.map((testCase, index) => ({
code: testCase.code,
index
}));
}
toggleRecording() {
this.isRecording = !this.isRecording;
if (this.isRecording) {
this.startTestRecording();
} else {
this.stopTestRecording();
}
}
copyTests() {
if (this.testCases.length > 0) {
navigator.clipboard.writeText(this.testCases.map((testCase) => testCase.code).join('\n'));
alert('Tests copied to clipboard!');
}
}
clearTests() {
this.testCaseGenerator.clear();
}
startTestRecording() {
this.testCaseGenerator.startRecording();
}
stopTestRecording() {
this.testCaseGenerator.stopRecording();
}
toggleAssertionMode(event) {
this.assertionMode = event.target.checked;
this.testCaseGenerator.setAssertionMode(this.assertionMode);
}
setAssertionType(type) {
this.assertionType = type;
this.testCaseGenerator.setAssertionType(type);
}
removeTest(index) {
this.testCaseGenerator.removeTestCase(index);
}
setActiveTab(tab) {
this.activeTab = tab;
}
toggleEvent(eventId) {
this.eventManager.toggleEvent(eventId);
}
}