Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Dai committed Oct 10, 2021
1 parent f0384dc commit f0c8887
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 15,850 deletions.
3 changes: 0 additions & 3 deletions .GITHUB_ENV

This file was deleted.

25 changes: 13 additions & 12 deletions app/components/render-tree-toolbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
@value={{@searchValue}}
class="js-render-profiles-search"
/>

<div class="toolbar__checkbox js-hightlight-render">
<label>
<Input
data-test-options-highlight-render
@type="checkbox"
@checked={{@shouldHighlightRender}}
{{on "change" @updateShouldHighlightRender}}
/>
Highlight render
</label>
</div>
{{#if @isHighlightEnabled}}
<div class="toolbar__checkbox js-hightlight-render">
<label>
<Input
data-test-options-highlight-render
@type="checkbox"
@checked={{@shouldHighlightRender}}
{{on "change" @updateShouldHighlightRender}}
/>
Highlight render
</label>
</div>
{{/if}}
</div>
12 changes: 8 additions & 4 deletions app/controllers/render-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { and, equal } from '@ember/object/computed';

export default Controller.extend({
initialEmpty: false,
modelEmpty: equal('model.length', 0),
modelEmpty: equal('model.profiles.length', 0),
showEmpty: and('initialEmpty', 'modelEmpty'),
shouldHighlightRender: false,

Expand Down Expand Up @@ -59,16 +59,20 @@ export default Controller.extend({
return escapeRegExp(this.search.toLowerCase());
}),

isHighlightEnabled: computed('model.isHighlighSupported', function () {
return get(this.model, 'isHighlighSupported');
}),

filtered: computed(
'escapedSearch',
'[email protected]',
'model.profiles.@each.name',
'search',
function () {
if (isEmpty(this.escapedSearch)) {
return this.model;
return get(this.model, 'profiles');
}

return this.model.filter((item) => {
return get(this.model, 'profiles').filter((item) => {
const regExp = new RegExp(this.escapedSearch);
return recursiveMatch(item, regExp);
});
Expand Down
34 changes: 24 additions & 10 deletions app/routes/render-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, get, set } from '@ember/object';
import EmberObject, { action, get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { Promise } from 'rsvp';
import TabRoute from 'ember-inspector/routes/tab';
Expand All @@ -9,17 +9,20 @@ export default class RenderTreeRoute extends TabRoute {
model() {
const port = this.port;
return new Promise(function (resolve) {
port.one('render:profilesAdded', function (message) {
resolve(message.profiles);
});
port.one(
'render:profilesAdded',
function ({ profiles, isHighlighSupported }) {
resolve(EmberObject.create({ profiles, isHighlighSupported }));
}
);
port.send('render:watchProfiles');
});
}

setupController(controller, model) {
super.setupController(...arguments);

if (model.length === 0) {
if (get(model, 'profiles.length') === 0) {
controller.set('initialEmpty', true);
}
const port = this.port;
Expand All @@ -37,16 +40,27 @@ export default class RenderTreeRoute extends TabRoute {
}

profilesUpdated(message) {
set(this, 'controller.model', message.profiles);
set(this, 'controller.model.profiles', message.profiles);
}

profilesAdded(message) {
const model = get(this, 'controller.model');
const currentProfiles = get(this, 'controller.model.profiles');
const profiles = message.profiles;
if (
message.isHighlighSupported !== undefined &&
message.isHighlighSupported !==
get(this, 'controller.model.isHighlighSupported')
) {
set(
this,
'controller.model.isHighlighSupported',
message.isHighlighSupported
);
}

model.pushObjects(profiles);
if (model.length > 100) {
set(this, 'controller.model', model.slice(0, 100));
currentProfiles.pushObjects(profiles);
if (currentProfiles.length > 100) {
set(this, 'controller.model.profiles', currentProfiles.slice(0, 100));
}
}

Expand Down
1 change: 1 addition & 0 deletions app/templates/render-tree.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@showEmpty={{this.showEmpty}}
@shouldHighlightRender={{this.shouldHighlightRender}}
@updateShouldHighlightRender={{this.updateShouldHighlightRender}}
@isHighlightEnabled={{this.isHighlightEnabled}}
/>
{{/in-element}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion ember_debug/libs/promise-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Promise from 'ember-debug/models/promise';

import { A } from '../utils/ember/array';
import EmberObject from '../utils/ember/object';
import EmberObject, { computed } from '../utils/ember/object';
import Evented from '../utils/ember/object/evented';
import { isNone } from '../utils/ember/utils';
import RSVP from '../utils/rsvp';
Expand Down
11 changes: 6 additions & 5 deletions ember_debug/models/profile-manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import ProfileNode from './profile-node';
import Ember from '../utils/ember';
import { compareVersion } from 'ember-debug/utils/version';

import { later, scheduleOnce } from '../utils/ember/runloop';
const { guidFor } = Ember;
const {
run: { later, scheduleOnce, cancel },
} = Ember;
import { later, scheduleOnce, cancel } from '../utils/ember/runloop';
const { VERSION } = Ember;

function getEdges(first, last, closest) {
let start = null;
Expand Down Expand Up @@ -77,6 +76,7 @@ export default class ProfileManager {
this.stylesheet = insertStylesheet();
// keep track of all the active highlights
this.highlights = [];
this.isHighlightEnabled = compareVersion(VERSION, '3.20.0') !== -1;
}

began(timestamp, payload, now) {
Expand All @@ -85,6 +85,7 @@ export default class ProfileManager {
if (this.shouldHighlightRender && payload.view) {
this._highLightView(payload.view);
}
this.current.isHighlightEnabled = this.isHighlightEnabled;
return this.current;
});
}
Expand Down
5 changes: 4 additions & 1 deletion ember_debug/render-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default EmberObject.extend(PortMixin, {
},

sendAdded(profiles) {
this.sendMessage('profilesAdded', { profiles });
this.sendMessage('profilesAdded', {
profiles,
isHighlighSupported: this.profileManager.isHighlightEnabled,
});
},

/**
Expand Down
9 changes: 0 additions & 9 deletions tests/acceptance/render-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ module('Render Tree Tab', function (outer) {
.hasText('Second View Rendering');
});

test('Renders checkbox for highlight render', async function (assert) {
await visit('/render-tree');

assert
.dom('[data-test-options-highlight-render]')
.exists('checkbox input is rendered');
assert.dom('.js-hightlight-render').hasText('Highlight render');
});

test('It should clear the search filter when the clear button is clicked', async function (assert) {
await visit('/render-tree');

Expand Down
Loading

0 comments on commit f0c8887

Please sign in to comment.