-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View tree search filter #720
Changes from 5 commits
c64278e
ca0dbfb
f719298
fa01fe4
b3575bc
f734ad7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,19 @@ export default Controller.extend({ | |
components: false | ||
}, | ||
|
||
searchText: "", | ||
|
||
filteredList: computed('model', 'searchText', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
/**
* The filtered view list.
*
* @property filteredList
* @type {Array<Object>}
*/ |
||
let searchText = this.get('searchText'); | ||
|
||
if (!searchText) { | ||
return this.get('model'); | ||
} | ||
|
||
let filtered = this.get('model').filter(v => v.value.name.includes(searchText)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use search-match just so we're consistent in our query matching. If we later improve our matching it would improve everywhere. You can also just return it directly. |
||
return filtered; | ||
}), | ||
|
||
optionsChanged: on('init', observer('options.components', function() { | ||
this.port.send('view:setOptions', { options: this.get('options') }); | ||
})), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import Ember from "ember"; | |
import { test } from 'ember-qunit'; | ||
import { module } from 'qunit'; | ||
import startApp from '../helpers/start-app'; | ||
import { visit, find, findAll, click, triggerEvent } from 'ember-native-dom-helpers'; | ||
import { visit, fillIn, find, findAll, click, triggerEvent } from 'ember-native-dom-helpers'; | ||
|
||
let App; | ||
const { run } = Ember; | ||
|
@@ -118,6 +118,7 @@ test("It should correctly display the view tree", async function(assert) { | |
|
||
let treeNodes = findAll('.js-view-tree-item'); | ||
assert.equal(treeNodes.length, 3, 'expected some tree nodes'); | ||
|
||
let controllerNames = []; | ||
let templateNames = []; | ||
let modelNames = []; | ||
|
@@ -186,6 +187,71 @@ test("It should correctly display the view tree", async function(assert) { | |
], 'expected title tips'); | ||
}); | ||
|
||
test("It should filter the view tree using the search text", async function(assert) { | ||
let viewTree = defaultViewTree(); | ||
|
||
await visit('/'); | ||
run(() => { | ||
port.trigger('view:viewTree', { tree: viewTree }); | ||
}); | ||
await wait(); | ||
|
||
let treeNodes = findAll('.js-view-tree-item'); | ||
assert.equal(treeNodes.length, 3, 'expected some tree nodes'); | ||
|
||
fillIn('.js-filter-views input', 'post'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize we had to use In other words:
So to fix it, I would have to use either
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes precisely, you got it. |
||
treeNodes = findAll('.js-view-tree-item'); | ||
assert.equal(treeNodes.length, 1, 'expected filtered tree nodes'); | ||
|
||
let controllerNames = []; | ||
let templateNames = []; | ||
let modelNames = []; | ||
let viewClassNames = []; | ||
let durations = []; | ||
|
||
function textFor(selector, context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this function outside the tests callbacks so we can reuse the same one to avoid duplication? |
||
return find(selector, context).textContent.trim(); | ||
} | ||
|
||
[...treeNodes].forEach(function(node) { | ||
templateNames.push(textFor('.js-view-template', node)); | ||
controllerNames.push(textFor('.js-view-controller', node)); | ||
viewClassNames.push(textFor('.js-view-class', node)); | ||
modelNames.push(textFor('.js-view-model', node)); | ||
durations.push(textFor('.js-view-duration', node)); | ||
}); | ||
|
||
assert.deepEqual(controllerNames, [ | ||
'App.PostsController', | ||
], 'expected controller names'); | ||
|
||
assert.deepEqual(templateNames, [ | ||
'posts', | ||
], 'expected template names'); | ||
|
||
assert.deepEqual(modelNames, [ | ||
'PostsArray', | ||
], 'expected model names'); | ||
|
||
assert.deepEqual(viewClassNames, [ | ||
'App.PostsView', | ||
], 'expected view class names'); | ||
|
||
assert.deepEqual(durations, [ | ||
'1.00ms', | ||
], 'expected render durations'); | ||
|
||
let titleTips = [...findAll('span[title]')].map(node => node.getAttribute('title')).sort(); | ||
|
||
assert.deepEqual(titleTips, [ | ||
'App.PostsController', | ||
'App.PostsView', | ||
'PostsArray', | ||
'posts', | ||
'posts' | ||
], 'expected title tips'); | ||
}); | ||
|
||
test("It should update the view tree when the port triggers a change", async function(assert) { | ||
assert.expect(4); | ||
let treeNodes, viewTree = defaultViewTree(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single quotes.
We're also trying to document any new code so that we slowly migrate to a more documented code base.