Skip to content

Commit

Permalink
fix: result state after screenshot-accepter image accept
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Jun 26, 2024
1 parent 3a8b257 commit 8a17382
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/gui/tool-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ export class ToolRunner {

return Promise.all(tests.map(async (test): Promise<TestBranch> => {
const updateResult = this._createTestplaneTestResult(test);
const currentResult = formatTestResult(updateResult, UPDATED, test.attempt);
const estimatedStatus = reportBuilder.getUpdatedReferenceTestStatus(currentResult);
const latestAttempt = reportBuilder.getLatestAttempt({
fullName: updateResult.fullTitle(),
browserId: updateResult.browserId
});
const latestResult = formatTestResult(updateResult, UPDATED, latestAttempt);
const estimatedStatus = reportBuilder.getUpdatedReferenceTestStatus(latestResult);

const formattedResultWithoutAttempt = formatTestResult(updateResult, UPDATED);
const formattedResult = reportBuilder.provideAttempt(formattedResultWithoutAttempt);
Expand Down
4 changes: 4 additions & 0 deletions lib/report-builder/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export class StaticReportBuilder {
this._workers = workers;
}

getLatestAttempt(testInfo: {fullName: string, browserId: string}): number {
return this._testAttemptManager.getCurrentAttempt(testInfo);
}

/** If passed test result doesn't have attempt, this method registers new attempt and sets attempt number */
provideAttempt(testResultOriginal: ReporterTestResult): ReporterTestResult {
let formattedResult = testResultOriginal;
Expand Down
40 changes: 40 additions & 0 deletions test/unit/lib/gui/tool-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,46 @@ describe('lib/gui/tool-runner/index', () => {
state: 'plain2'
});
});

it('should determine status based on the latest result', async () => {
const testRefUpdateData = [{
id: 'some-id',
fullTitle: () => 'some-title',
browserId: 'yabro',
suite: {path: ['suite1']},
state: {},
metaInfo: {},
imagesInfo: [{
status: UPDATED,
stateName: 'plain1',
actualImg: {
size: {height: 100, width: 200}
}
}]
}];

const getScreenshotPath = sandbox.stub().returns('/ref/path1');
const config = stubConfig({
browsers: {yabro: {getScreenshotPath}}
});

const testCollection = mkTestCollection_({'some-title.yabro': testRefUpdateData[0]});
const toolAdapter = stubToolAdapter({config, testCollection});

reportBuilder.getLatestAttempt.withArgs({fullName: 'some-title', browserId: 'yabro'}).returns(100500);
reportBuilder.getUpdatedReferenceTestStatus = (result) => {
return result.attempt === 100500 ? TestStatus.UPDATED : TestStatus.FAIL;
};

const gui = initGuiReporter({toolAdapter});
await gui.initialize();

reportBuilder.addTestResult.reset();

await gui.updateReferenceImage(testRefUpdateData);

assert.calledOnceWith(reportBuilder.addTestResult, sinon.match.any, {status: TestStatus.UPDATED});
});
});

describe('undoAcceptImages', () => {
Expand Down

0 comments on commit 8a17382

Please sign in to comment.