Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/test/view/reviewManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PullRequestChangesTreeDataProvider } from '../../view/prChangesTreeData
import { PullRequestsTreeDataProvider } from '../../view/prsTreeDataProvider';
import { ReviewManager, ShowPullRequest } from '../../view/reviewManager';
import { WebviewViewCoordinator } from '../../view/webviewViewCoordinator';
import { FOCUS_REVIEW_MODE } from '../../constants';
import { MockPrsTreeModel } from '../mocks/mockPRsTreeModel';
import { MockCommandRegistry } from '../mocks/mockCommandRegistry';
import { MockExtensionContext } from '../mocks/mockExtensionContext';
Expand All @@ -39,6 +40,7 @@ describe('ReviewManager polling', function () {
let gitApi: GitApiImpl;
let manager: FolderRepositoryManager;
let reviewManager: ReviewManager;
let showPullRequest: ShowPullRequest;
let onDidChangeWindowStateCallback: ((state: vscode.WindowState) => unknown) | undefined;
let isWindowFocused: boolean;
let setTimeoutSpy: sinon.SinonSpy;
Expand Down Expand Up @@ -75,6 +77,7 @@ describe('ReviewManager polling', function () {
reposManager.insertFolderManager(manager);

const changesTreeProvider = new PullRequestChangesTreeDataProvider(gitApi, reposManager);
showPullRequest = new ShowPullRequest();
reviewManager = new ReviewManager(
0,
context,
Expand All @@ -83,7 +86,7 @@ describe('ReviewManager polling', function () {
telemetry,
changesTreeProvider,
prsTreeProvider,
new ShowPullRequest(),
showPullRequest,
activePrViewCoordinator,
createPrHelper,
gitApi,
Expand Down Expand Up @@ -211,4 +214,24 @@ describe('ReviewManager polling', function () {
await flushMicrotasks();
assert.strictEqual(latestScheduledDelay(), POLL_MIN_INTERVAL_MS * 6);
});

it('shows a deferred pull request reveal only once', async function () {
await context.workspaceState.update(FOCUS_REVIEW_MODE, true);
const pullRequest = {} as PullRequestModel;
const reviewManagerLayout = reviewManager as unknown as {
layout(pr: PullRequestModel, updateLayout: boolean, silent: boolean): void;
_doFocusShow(pr: PullRequestModel, updateLayout: boolean): void;
};
const focusShow = sinon.stub(reviewManagerLayout, '_doFocusShow');

reviewManagerLayout.layout(pullRequest, true, true);
showPullRequest.shouldShow = true;

assert.strictEqual(focusShow.callCount, 1);
assert.deepStrictEqual(focusShow.firstCall.args, [pullRequest, true]);

reviewManagerLayout.layout(pullRequest, true, true);

assert.strictEqual(focusShow.callCount, 1);
});
});
15 changes: 9 additions & 6 deletions src/view/reviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,17 +797,18 @@ export class ReviewManager extends Disposable {

private layout(pr: PullRequestModel, updateLayout: boolean, silent: boolean) {
const isFocusMode = this._context.workspaceState.get<boolean>(FOCUS_REVIEW_MODE);
const shouldShow = isFocusMode ? this._showPullRequest.takeShouldShow() : false;

Logger.appendLine(`Using focus mode = ${isFocusMode}.`, this.id);
Logger.appendLine(`State validation silent = ${silent}.`, this.id);
Logger.appendLine(`PR show should show = ${this._showPullRequest.shouldShow}.`, this.id);
Logger.appendLine(`PR show should show = ${shouldShow}.`, this.id);

if ((!silent || this._showPullRequest.shouldShow) && isFocusMode) {
if ((!silent || shouldShow) && isFocusMode) {
this._doFocusShow(pr, updateLayout);
} else if (!this._showPullRequest.shouldShow && isFocusMode) {
} else if (isFocusMode) {
const showPRChangedDisposable = this._showPullRequest.onChangedShowValue(shouldShow => {
Logger.appendLine(`PR show value changed = ${shouldShow}.`, this.id);
if (shouldShow) {
if (shouldShow && this._showPullRequest.takeShouldShow()) {
this._doFocusShow(pr, updateLayout);
}
showPRChangedDisposable.dispose();
Expand Down Expand Up @@ -1612,8 +1613,10 @@ export class ShowPullRequest {
private _onChangedShowValue: vscode.EventEmitter<boolean> = new vscode.EventEmitter();
public readonly onChangedShowValue: vscode.Event<boolean> = this._onChangedShowValue.event;
constructor() { }
get shouldShow(): boolean {
return this._shouldShow;
takeShouldShow(): boolean {
const shouldShow = this._shouldShow;
this._shouldShow = false;
return shouldShow;
}
set shouldShow(shouldShow: boolean) {
const oldShowValue = this._shouldShow;
Expand Down