testing: use inherited state is a test is updated into an unset state
Fixes #126160
This commit is contained in:
parent
478f95345c
commit
7103a76195
|
@ -111,8 +111,15 @@ export class HierarchicalByLocationProjection extends Disposable implements ITes
|
|||
// when test states change, reflect in the tree
|
||||
// todo: optimize this to avoid needing to iterate
|
||||
this._register(results.onTestChanged(({ item: result }) => {
|
||||
if (result.ownComputedState === TestResultState.Unset) {
|
||||
const fallback = results.getStateById(result.item.extId);
|
||||
if (fallback) {
|
||||
result = fallback[1];
|
||||
}
|
||||
}
|
||||
|
||||
for (const { items } of this.folders.values()) {
|
||||
const item = items.get(result.item.extId);
|
||||
let item = items.get(result.item.extId);
|
||||
if (item) {
|
||||
item.retired = result.retired;
|
||||
item.ownState = result.ownComputedState;
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { HierarchicalByLocationProjection } from 'vs/workbench/contrib/testing/browser/explorerProjections/hierarchalByLocation';
|
||||
import { testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
|
||||
import { TestResultItem } from 'vs/workbench/contrib/testing/common/testCollection';
|
||||
import { TestResultItemChange, TestResultItemChangeReason } from 'vs/workbench/contrib/testing/common/testResult';
|
||||
import { TestResultState, testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
|
||||
import { makeTestWorkspaceFolder, TestTreeTestHarness } from 'vs/workbench/contrib/testing/test/browser/testObjectTree';
|
||||
|
||||
class TestHierarchicalByLocationProjection extends HierarchicalByLocationProjection {
|
||||
|
@ -18,12 +21,18 @@ suite('Workbench - Testing Explorer Hierarchal by Location Projection', () => {
|
|||
let harness: TestTreeTestHarness<TestHierarchicalByLocationProjection>;
|
||||
const folder1 = makeTestWorkspaceFolder('f1');
|
||||
const folder2 = makeTestWorkspaceFolder('f2');
|
||||
let onTestChanged: Emitter<TestResultItemChange>;
|
||||
let resultsService: any;
|
||||
|
||||
setup(() => {
|
||||
harness = new TestTreeTestHarness([folder1, folder2], l => new TestHierarchicalByLocationProjection(l, {
|
||||
onTestChanged = new Emitter();
|
||||
resultsService = {
|
||||
onResultsChanged: () => undefined,
|
||||
onTestChanged: () => undefined,
|
||||
onTestChanged: onTestChanged.event,
|
||||
getStateById: () => ({ state: { state: 0 }, computedState: 0 }),
|
||||
} as any));
|
||||
};
|
||||
|
||||
harness = new TestTreeTestHarness([folder1, folder2], l => new TestHierarchicalByLocationProjection(l, resultsService as any));
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
|
@ -117,5 +126,49 @@ suite('Workbench - Testing Explorer Hierarchal by Location Projection', () => {
|
|||
{ e: 'b' }
|
||||
]);
|
||||
});
|
||||
|
||||
test('applies state changes', async () => {
|
||||
const tests = testStubs.nested();
|
||||
harness.c.addRoot(tests, 'a');
|
||||
harness.flush(folder1);
|
||||
resultsService.getStateById = () => [undefined, resultInState(TestResultState.Failed)];
|
||||
|
||||
const resultInState = (state: TestResultState): TestResultItem => ({
|
||||
item: harness.c.itemToInternal.get(tests.children.get('id-a')!)!.item,
|
||||
parent: 'id-root',
|
||||
tasks: [],
|
||||
retired: false,
|
||||
ownComputedState: state,
|
||||
computedState: state,
|
||||
});
|
||||
|
||||
// Applies the change:
|
||||
onTestChanged.fire({
|
||||
reason: TestResultItemChangeReason.OwnStateChange,
|
||||
result: null as any,
|
||||
previous: TestResultState.Unset,
|
||||
item: resultInState(TestResultState.Queued),
|
||||
});
|
||||
harness.projection.applyTo(harness.tree);
|
||||
|
||||
assert.deepStrictEqual(harness.tree.getRendered('state'), [
|
||||
{ e: 'a', data: String(TestResultState.Queued) },
|
||||
{ e: 'b', data: String(TestResultState.Unset) }
|
||||
]);
|
||||
|
||||
// Falls back if moved into unset state:
|
||||
onTestChanged.fire({
|
||||
reason: TestResultItemChangeReason.OwnStateChange,
|
||||
result: null as any,
|
||||
previous: TestResultState.Queued,
|
||||
item: resultInState(TestResultState.Unset),
|
||||
});
|
||||
harness.projection.applyTo(harness.tree);
|
||||
|
||||
assert.deepStrictEqual(harness.tree.getRendered('state'), [
|
||||
{ e: 'a', data: String(TestResultState.Failed) },
|
||||
{ e: 'b', data: String(TestResultState.Unset) }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import { ITestTreeProjection, TestExplorerTreeElement, TestItemTreeElement } fro
|
|||
import { TestSubscriptionListener } from 'vs/workbench/contrib/testing/common/workspaceTestCollectionService';
|
||||
import { TestOwnedTestCollection, TestSingleUseCollection } from 'vs/workbench/contrib/testing/test/common/ownedTestCollection';
|
||||
|
||||
type SerializedTree = { e: string; children?: SerializedTree[] };
|
||||
type SerializedTree = { e: string; children?: SerializedTree[], data?: string };
|
||||
|
||||
const element = document.createElement('div');
|
||||
element.style.height = '1000px';
|
||||
|
@ -31,6 +31,7 @@ export class TestObjectTree<T> extends ObjectTree<T, any> {
|
|||
{
|
||||
disposeTemplate: () => undefined,
|
||||
renderElement: (node, _index, container: HTMLElement) => {
|
||||
Object.assign(container.dataset, node.element);
|
||||
container.textContent = `${node.depth}:${serializer(node.element)}`;
|
||||
},
|
||||
renderTemplate: c => c,
|
||||
|
@ -50,15 +51,18 @@ export class TestObjectTree<T> extends ObjectTree<T, any> {
|
|||
return this.model;
|
||||
}
|
||||
|
||||
public getRendered() {
|
||||
const elements = element.querySelectorAll('.monaco-tl-contents');
|
||||
public getRendered(getProperty?: string) {
|
||||
const elements = element.querySelectorAll<HTMLElement>('.monaco-tl-contents');
|
||||
const sorted = [...elements].sort((a, b) => pos(a) - pos(b));
|
||||
let chain: SerializedTree[] = [{ e: '', children: [] }];
|
||||
for (const element of sorted) {
|
||||
const [depthStr, label] = element.textContent!.split(':');
|
||||
const depth = Number(depthStr);
|
||||
const parent = chain[depth - 1];
|
||||
const child = { e: label };
|
||||
const child: SerializedTree = { e: label };
|
||||
if (getProperty) {
|
||||
child.data = element.dataset[getProperty];
|
||||
}
|
||||
parent.children = parent.children?.concat(child) ?? [child];
|
||||
chain[depth] = child;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue