fase(20): visual regression refactor
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
21
dist/modules/visual-regression/domain/entities/VisualBaseline.js
vendored
Normal file
21
dist/modules/visual-regression/domain/entities/VisualBaseline.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VisualBaseline = void 0;
|
||||
const Entity_1 = require("../../../../shared/domain/Entity");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class VisualBaseline extends Entity_1.Entity {
|
||||
static create(props, id) {
|
||||
return new VisualBaseline(props, id ?? UniqueId_1.UniqueId.create());
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new VisualBaseline(props, id);
|
||||
}
|
||||
get stateId() { return this.props.stateId; }
|
||||
get url() { return this.props.url; }
|
||||
get screenshotPath() { return this.props.screenshotPath; }
|
||||
get width() { return this.props.width; }
|
||||
get height() { return this.props.height; }
|
||||
get approvedAt() { return this.props.approvedAt; }
|
||||
get approvedBy() { return this.props.approvedBy; }
|
||||
}
|
||||
exports.VisualBaseline = VisualBaseline;
|
||||
46
dist/modules/visual-regression/domain/entities/VisualComparison.js
vendored
Normal file
46
dist/modules/visual-regression/domain/entities/VisualComparison.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VisualComparison = void 0;
|
||||
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
const ComparisonStatus_1 = require("../value-objects/ComparisonStatus");
|
||||
const BaselineApproved_1 = require("../events/BaselineApproved");
|
||||
const RegressionDetected_1 = require("../events/RegressionDetected");
|
||||
class VisualComparison extends AggregateRoot_1.AggregateRoot {
|
||||
static create(props, id) {
|
||||
const comparison = new VisualComparison({ ...props, createdAt: new Date() }, id ?? UniqueId_1.UniqueId.create());
|
||||
if (props.status.isFailed()) {
|
||||
comparison.addDomainEvent(new RegressionDetected_1.RegressionDetected(comparison.id.toString(), {
|
||||
sessionId: props.sessionId,
|
||||
stateId: props.stateId,
|
||||
diffPercent: props.diffPercent ?? 0,
|
||||
}));
|
||||
}
|
||||
return comparison;
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new VisualComparison(props, id);
|
||||
}
|
||||
get sessionId() { return this.props.sessionId; }
|
||||
get stateId() { return this.props.stateId; }
|
||||
get baselineId() { return this.props.baselineId; }
|
||||
get currentScreenshotPath() { return this.props.currentScreenshotPath; }
|
||||
get diffScreenshotPath() { return this.props.diffScreenshotPath; }
|
||||
get diffPixels() { return this.props.diffPixels; }
|
||||
get diffPercent() { return this.props.diffPercent; }
|
||||
get status() { return this.props.status; }
|
||||
get createdAt() { return this.props.createdAt; }
|
||||
approve(newBaselineId) {
|
||||
this.props.status = ComparisonStatus_1.ComparisonStatus.passed();
|
||||
this.props.baselineId = newBaselineId;
|
||||
this.addDomainEvent(new BaselineApproved_1.BaselineApproved(this.id.toString(), {
|
||||
sessionId: this.props.sessionId,
|
||||
stateId: this.props.stateId,
|
||||
baselineId: newBaselineId,
|
||||
}));
|
||||
}
|
||||
reject() {
|
||||
this.props.status = ComparisonStatus_1.ComparisonStatus.failed();
|
||||
}
|
||||
}
|
||||
exports.VisualComparison = VisualComparison;
|
||||
13
dist/modules/visual-regression/domain/events/BaselineApproved.js
vendored
Normal file
13
dist/modules/visual-regression/domain/events/BaselineApproved.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaselineApproved = void 0;
|
||||
class BaselineApproved {
|
||||
constructor(aggregateId, payload) {
|
||||
this.aggregateId = aggregateId;
|
||||
this.payload = payload;
|
||||
this.eventName = 'visual.baseline_approved';
|
||||
this.eventId = crypto.randomUUID();
|
||||
this.occurredOn = new Date();
|
||||
}
|
||||
}
|
||||
exports.BaselineApproved = BaselineApproved;
|
||||
13
dist/modules/visual-regression/domain/events/RegressionDetected.js
vendored
Normal file
13
dist/modules/visual-regression/domain/events/RegressionDetected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RegressionDetected = void 0;
|
||||
class RegressionDetected {
|
||||
constructor(aggregateId, payload) {
|
||||
this.aggregateId = aggregateId;
|
||||
this.payload = payload;
|
||||
this.eventName = 'visual.regression_detected';
|
||||
this.eventId = crypto.randomUUID();
|
||||
this.occurredOn = new Date();
|
||||
}
|
||||
}
|
||||
exports.RegressionDetected = RegressionDetected;
|
||||
2
dist/modules/visual-regression/domain/ports/IVisualBaselineRepository.js
vendored
Normal file
2
dist/modules/visual-regression/domain/ports/IVisualBaselineRepository.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
dist/modules/visual-regression/domain/ports/IVisualComparisonRepository.js
vendored
Normal file
2
dist/modules/visual-regression/domain/ports/IVisualComparisonRepository.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
23
dist/modules/visual-regression/domain/value-objects/ComparisonStatus.js
vendored
Normal file
23
dist/modules/visual-regression/domain/value-objects/ComparisonStatus.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ComparisonStatus = void 0;
|
||||
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
|
||||
class ComparisonStatus extends ValueObject_1.ValueObject {
|
||||
get value() {
|
||||
return this.props.value;
|
||||
}
|
||||
static passed() { return new ComparisonStatus({ value: 'passed' }); }
|
||||
static failed() { return new ComparisonStatus({ value: 'failed' }); }
|
||||
static newState() { return new ComparisonStatus({ value: 'new_state' }); }
|
||||
static pending() { return new ComparisonStatus({ value: 'pending' }); }
|
||||
static from(value) {
|
||||
if (!['passed', 'failed', 'new_state', 'pending'].includes(value)) {
|
||||
throw new Error(`Invalid comparison status: ${value}`);
|
||||
}
|
||||
return new ComparisonStatus({ value: value });
|
||||
}
|
||||
isPassed() { return this.props.value === 'passed'; }
|
||||
isFailed() { return this.props.value === 'failed'; }
|
||||
isNewState() { return this.props.value === 'new_state'; }
|
||||
}
|
||||
exports.ComparisonStatus = ComparisonStatus;
|
||||
Reference in New Issue
Block a user