From 333180e47e5e65889c41f6d65780c6f3947e485d Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Mon, 25 Sep 2017 17:04:46 +0200 Subject: [PATCH 1/9] add initial prototype of functionality --- lib/command-palette-package.js | 11 ++++++++-- lib/command-palette-view.js | 40 +++++++++++++++++++++++++++++++--- package.json | 8 +++++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/lib/command-palette-package.js b/lib/command-palette-package.js index d4332b9..a686f5d 100644 --- a/lib/command-palette-package.js +++ b/lib/command-palette-package.js @@ -4,8 +4,8 @@ import {CompositeDisposable} from 'atom' import CommandPaletteView from './command-palette-view' class CommandPalettePackage { - activate () { - this.commandPaletteView = new CommandPaletteView() + activate (state) { + this.commandPaletteView = new CommandPaletteView(state) this.disposables = new CompositeDisposable() this.disposables.add(atom.commands.add('atom-workspace', 'command-palette:toggle', () => { this.commandPaletteView.toggle() @@ -16,9 +16,16 @@ class CommandPalettePackage { this.disposables.add(atom.config.observe('command-palette.preserveLastSearch', (newValue) => { this.commandPaletteView.update({preserveLastSearch: newValue}) })) + this.disposables.add(atom.config.observe('command-palette.preserveMostUsed', (newValue) => { + this.commandPaletteView.update({preserveMostUsed: newValue}) + })) return this.commandPaletteView.show() } + serialize() { + return this.commandPaletteView.serialize() + } + async deactivate () { this.disposables.dispose() await this.commandPaletteView.destroy() diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index 1526f72..e02e61f 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -6,7 +6,8 @@ import fuzzaldrin from 'fuzzaldrin' import fuzzaldrinPlus from 'fuzzaldrin-plus' export default class CommandPaletteView { - constructor () { + constructor (state) { + this.elementScores = state || {} this.keyBindingsForActiveElement = [] this.commandsForActiveElement = [] this.selectListView = new SelectListView({ @@ -38,7 +39,9 @@ export default class CommandPaletteView { leftBlock.appendChild(titleEl) const query = this.selectListView.getQuery() - this.highlightMatchesInElement(item.displayName, query, titleEl) + const itemScore = this.elementScores[item.name] || 0 + const title = `${item.displayName} (${itemScore})` + this.highlightMatchesInElement(title, query, titleEl) if (selected) { let secondaryEl = document.createElement('div') @@ -69,6 +72,14 @@ export default class CommandPaletteView { }, didConfirmSelection: (keyBinding) => { this.hide() + console.log(keyBinding.displayName) + const elementName = keyBinding.name + if(this.elementScores.hasOwnProperty(elementName)) { + this.elementScores[elementName]++ + } + else { + this.elementScores[elementName] = 1 + } const event = new CustomEvent(keyBinding.name, {bubbles: true, cancelable: true}) this.activeElement.dispatchEvent(event) }, @@ -130,6 +141,10 @@ export default class CommandPaletteView { if (props.hasOwnProperty('useAlternateScoring')) { this.useAlternateScoring = props.useAlternateScoring } + + if (props.hasOwnProperty('preserveMostUsed')) { + this.preserveMostUsed = props.preserveMostUsed + } } get fuzz () { @@ -171,9 +186,28 @@ export default class CommandPaletteView { } } + serialize = () => { + return this.elementScores? this.elementScores: {} + } + filter = (items, query) => { if (query.length === 0) { - return items + if (this.preserveMostUsed) { + const scoredItems = items + .filter(e => this.elementScores[e.name]) + .map(item => ({ + item, + score: this.elementScores[item.name] + })) + .sort((a, b) => b.score - a.score) + + return scoredItems + .map(i => i.item) + .concat(items.filter(e => !!!this.elementScores[e.name])) + } + else { + return items + } } const scoredItems = [] diff --git a/package.json b/package.json index 1a95a87..47e882c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,9 @@ "semver": "^5.4.1", "sinon": "^3.2.1" }, + "deserializers": { + "commandPalettePackage": "deserialize" + }, "configSchema": { "useAlternateScoring": { "type": "boolean", @@ -36,6 +39,11 @@ "type": "boolean", "default": false, "description": "Preserve the last search when reopening the command palette." + }, + "preserveMostUsed": { + "type": "boolean", + "default": true, + "description": "Show most used commands when opening the command palette." } } } From 370c97e2c94e24356290b5a94237cd55196a6cc9 Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Tue, 26 Sep 2017 17:25:43 +0200 Subject: [PATCH 2/9] rework filter method a bit, scoped state better --- lib/command-palette-view.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index e02e61f..2038159 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -6,8 +6,8 @@ import fuzzaldrin from 'fuzzaldrin' import fuzzaldrinPlus from 'fuzzaldrin-plus' export default class CommandPaletteView { - constructor (state) { - this.elementScores = state || {} + constructor (state = {}) { + this.elementScores = state.elementScores || {} this.keyBindingsForActiveElement = [] this.commandsForActiveElement = [] this.selectListView = new SelectListView({ @@ -186,24 +186,30 @@ export default class CommandPaletteView { } } - serialize = () => { - return this.elementScores? this.elementScores: {} - } + serialize = () => ({ + elementScores: this.elementScores + }) filter = (items, query) => { if (query.length === 0) { if (this.preserveMostUsed) { - const scoredItems = items - .filter(e => this.elementScores[e.name]) - .map(item => ({ - item, - score: this.elementScores[item.name] - })) - .sort((a, b) => b.score - a.score) + const scoredItems = [] + const unscoredItems = [] + + for (const item of items) { + const score = this.elementScores[item.name] + if(score) { + scoredItems.push({item, score}) + } + else { + unscoredItems.push(item) + } + } return scoredItems + .sort((a, b) => b.score - a.score) .map(i => i.item) - .concat(items.filter(e => !!!this.elementScores[e.name])) + .concat(unscoredItems) } else { return items From 26d7c20951d933ccda75cbbe966921234d1ed88e Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Tue, 26 Sep 2017 17:44:02 +0200 Subject: [PATCH 3/9] change settings to include more options --- lib/command-palette-package.js | 4 ++-- lib/command-palette-view.js | 12 ++++++++---- package.json | 12 ++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/command-palette-package.js b/lib/command-palette-package.js index a686f5d..6b9a584 100644 --- a/lib/command-palette-package.js +++ b/lib/command-palette-package.js @@ -16,8 +16,8 @@ class CommandPalettePackage { this.disposables.add(atom.config.observe('command-palette.preserveLastSearch', (newValue) => { this.commandPaletteView.update({preserveLastSearch: newValue}) })) - this.disposables.add(atom.config.observe('command-palette.preserveMostUsed', (newValue) => { - this.commandPaletteView.update({preserveMostUsed: newValue}) + this.disposables.add(atom.config.observe('command-palette.initialOrderingOfItems', (newValue) => { + this.commandPaletteView.update({initialOrderingOfItems: newValue}) })) return this.commandPaletteView.show() } diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index 2038159..6f15ce5 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -142,8 +142,8 @@ export default class CommandPaletteView { this.useAlternateScoring = props.useAlternateScoring } - if (props.hasOwnProperty('preserveMostUsed')) { - this.preserveMostUsed = props.preserveMostUsed + if (props.hasOwnProperty('initialOrderingOfItems')) { + this.initialOrderingOfItems = props.initialOrderingOfItems } } @@ -187,12 +187,12 @@ export default class CommandPaletteView { } serialize = () => ({ - elementScores: this.elementScores + elementScores: this.elementScores }) filter = (items, query) => { if (query.length === 0) { - if (this.preserveMostUsed) { + if (this.initialOrderingOfItems === "frequency") { const scoredItems = [] const unscoredItems = [] @@ -211,6 +211,10 @@ export default class CommandPaletteView { .map(i => i.item) .concat(unscoredItems) } + else if(this.initialOrderingOfItems === "recent") { + throw new Error("Ordering by recently used is not implemented yet") + } + else { return items } diff --git a/package.json b/package.json index 47e882c..1312e65 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,14 @@ "default": false, "description": "Preserve the last search when reopening the command palette." }, - "preserveMostUsed": { - "type": "boolean", - "default": true, - "description": "Show most used commands when opening the command palette." + "initialOrderingOfItems": { + "type": "string", + "default": "frequency", + "enum": [ + {"value": "frequency", "description": "By frequency of use"}, + {"value": "recent", "description": "By most recently used"} + ] + } } } From 3e9e2f46d1544c39e880576d9936ad54f0767d20 Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Tue, 26 Sep 2017 18:06:20 +0200 Subject: [PATCH 4/9] add options for sorting by recent usage --- lib/command-palette-view.js | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index 6f15ce5..e49d43e 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -7,7 +7,7 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus' export default class CommandPaletteView { constructor (state = {}) { - this.elementScores = state.elementScores || {} + this.itemLaunches = state.itemLaunches || {} this.keyBindingsForActiveElement = [] this.commandsForActiveElement = [] this.selectListView = new SelectListView({ @@ -39,8 +39,8 @@ export default class CommandPaletteView { leftBlock.appendChild(titleEl) const query = this.selectListView.getQuery() - const itemScore = this.elementScores[item.name] || 0 - const title = `${item.displayName} (${itemScore})` + const itemLaunches = this.itemLaunches[item.name] || [] + const title = `${item.displayName} (${itemLaunches.length})` this.highlightMatchesInElement(title, query, titleEl) if (selected) { @@ -72,13 +72,13 @@ export default class CommandPaletteView { }, didConfirmSelection: (keyBinding) => { this.hide() - console.log(keyBinding.displayName) const elementName = keyBinding.name - if(this.elementScores.hasOwnProperty(elementName)) { - this.elementScores[elementName]++ + const launchedAt = new Date().getTime() + if(this.itemLaunches.hasOwnProperty(elementName)) { + this.itemLaunches[elementName].push(launchedAt) } else { - this.elementScores[elementName] = 1 + this.itemLaunches[elementName] = [launchedAt] } const event = new CustomEvent(keyBinding.name, {bubbles: true, cancelable: true}) this.activeElement.dispatchEvent(event) @@ -187,37 +187,37 @@ export default class CommandPaletteView { } serialize = () => ({ - elementScores: this.elementScores + itemLaunches: this.itemLaunches }) filter = (items, query) => { if (query.length === 0) { - if (this.initialOrderingOfItems === "frequency") { - const scoredItems = [] - const unscoredItems = [] - - for (const item of items) { - const score = this.elementScores[item.name] - if(score) { - scoredItems.push({item, score}) - } - else { - unscoredItems.push(item) - } - } + if (Object.keys(this.itemLaunches).length === 0) return items; - return scoredItems - .sort((a, b) => b.score - a.score) - .map(i => i.item) - .concat(unscoredItems) - } - else if(this.initialOrderingOfItems === "recent") { - throw new Error("Ordering by recently used is not implemented yet") - } + const scoredItems = [] + const unscoredItems = [] - else { - return items + for (const item of items) { + const launchDates = this.itemLaunches[item.name] || [] + let score; + if (this.initialOrderingOfItems === "frequency") { + score = launchDates.length + } + else if(this.initialOrderingOfItems === "recent") { + score = launchDates[0] + } + + if(score) { + scoredItems.push({item, score}) + } + else { + unscoredItems.push(item) + } } + return scoredItems + .sort((a, b) => b.score - a.score) + .map(i => i.item) + .concat(unscoredItems) } const scoredItems = [] From d72748da7f65365e74ef2924da51892165a601cc Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Tue, 26 Sep 2017 18:55:04 +0200 Subject: [PATCH 5/9] fix small bug and revert item titles --- lib/command-palette-view.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index e49d43e..180b433 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -39,9 +39,7 @@ export default class CommandPaletteView { leftBlock.appendChild(titleEl) const query = this.selectListView.getQuery() - const itemLaunches = this.itemLaunches[item.name] || [] - const title = `${item.displayName} (${itemLaunches.length})` - this.highlightMatchesInElement(title, query, titleEl) + this.highlightMatchesInElement(item.displayName, query, titleEl) if (selected) { let secondaryEl = document.createElement('div') @@ -204,7 +202,7 @@ export default class CommandPaletteView { score = launchDates.length } else if(this.initialOrderingOfItems === "recent") { - score = launchDates[0] + score = launchDates[launchDates.length-1] } if(score) { From f808337eead2eb514987aa70ee18fe6b7352305d Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Fri, 29 Sep 2017 16:22:50 +0200 Subject: [PATCH 6/9] started working on tests, added third option for alphabetic sorting --- lib/command-palette-view.js | 5 +- package.json | 6 +- test/command-palette-view.test.js | 106 ++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) diff --git a/lib/command-palette-view.js b/lib/command-palette-view.js index 180b433..69152d4 100644 --- a/lib/command-palette-view.js +++ b/lib/command-palette-view.js @@ -191,6 +191,7 @@ export default class CommandPaletteView { filter = (items, query) => { if (query.length === 0) { if (Object.keys(this.itemLaunches).length === 0) return items; + if (this.initialOrderingOfItems === 'alphabetic') return items; const scoredItems = [] const unscoredItems = [] @@ -198,10 +199,10 @@ export default class CommandPaletteView { for (const item of items) { const launchDates = this.itemLaunches[item.name] || [] let score; - if (this.initialOrderingOfItems === "frequency") { + if (this.initialOrderingOfItems === 'frequency') { score = launchDates.length } - else if(this.initialOrderingOfItems === "recent") { + else if(this.initialOrderingOfItems === 'recent') { score = launchDates[launchDates.length-1] } diff --git a/package.json b/package.json index 1312e65..efe2177 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,6 @@ "semver": "^5.4.1", "sinon": "^3.2.1" }, - "deserializers": { - "commandPalettePackage": "deserialize" - }, "configSchema": { "useAlternateScoring": { "type": "boolean", @@ -45,7 +42,8 @@ "default": "frequency", "enum": [ {"value": "frequency", "description": "By frequency of use"}, - {"value": "recent", "description": "By most recently used"} + {"value": "recent", "description": "By most recently used"}, + {"value": "alphabetic", "description": "Alphabetical order"} ] } diff --git a/test/command-palette-view.test.js b/test/command-palette-view.test.js index 2e50a8e..3f45926 100644 --- a/test/command-palette-view.test.js +++ b/test/command-palette-view.test.js @@ -22,6 +22,112 @@ describe('CommandPaletteView', () => { workspaceElement.remove() }) + describe('initial sorting', () => { + const fakeCommands = [ + "first", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "last" + ].map(e => `command-palette:${e}`) + + describe('when initially sorting by frequency', () => { + let commandPalette + + beforeEach(async () => { + commandPalette = new CommandPaletteView() + await commandPalette.update({initialOrderingOfItems: 'frequency'}) + for (let i=0; i {}) + + const numTimesToLaunch = fakeCommands.length - i + //console.log(`Launching ${command.displayName} ${numTimesToLaunch} times`) + + for (j=0; j { + await commandPalette.show() + await commandPalette.selectListView.refs.queryEditor.setText('') + await commandPalette.selectListView.update() + + fakeCommands.forEach(command => { + const selectedItem = commandPalette.selectListView.getSelectedItem().name + assert.equal(selectedItem, command) + commandPalette.selectListView.selectNext() + }) + }) + + it('orders the rest of the palette items alphabetically', async () => { + await commandPalette.show() + await commandPalette.selectListView.refs.queryEditor.setText('') + await commandPalette.selectListView.update() + + // skip scored items + for(let i=0; i { + + }) + }) + + xdescribe('when initially sorting by recentness', () => { + it('has selected the "recent" option in palette settings', async () => { + + }) + + it('orders the palette items correctly', async () => { + + }) + + it('orders the rest of the palette items alphabetically', async () => { + + }) + + it('remembers the ordering between launches', async () => { + + }) + }) + + xdescribe('when initially sorting alphabetically', () => { + it('has selected the "alphabetic" option in palette settings', async () => { + + }) + + it('orders the palette items correctly', async () => { + + }) + + it('remembers the ordering between launches', async () => { + + }) + }) + }) + describe('toggle', () => { describe('when an element is focused', () => { it('shows a list of all valid command descriptions, names, and keybindings for the previously focused element', async () => { From d1da17be528eb8288032c5f6cb47cec2724a041a Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Fri, 29 Sep 2017 16:37:33 +0200 Subject: [PATCH 7/9] added more test cases, broke out common code --- test/command-palette-view.test.js | 91 +++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/test/command-palette-view.test.js b/test/command-palette-view.test.js index 3f45926..1bf7b5c 100644 --- a/test/command-palette-view.test.js +++ b/test/command-palette-view.test.js @@ -23,6 +23,7 @@ describe('CommandPaletteView', () => { }) describe('initial sorting', () => { + let commandPalette const fakeCommands = [ "first", "one", @@ -35,29 +36,30 @@ describe('CommandPaletteView', () => { "last" ].map(e => `command-palette:${e}`) - describe('when initially sorting by frequency', () => { - let commandPalette - - beforeEach(async () => { - commandPalette = new CommandPaletteView() - await commandPalette.update({initialOrderingOfItems: 'frequency'}) - for (let i=0; i {}) + beforeEach(async () => { + commandPalette = new CommandPaletteView() + for (let i=0; i {}) - const numTimesToLaunch = fakeCommands.length - i - //console.log(`Launching ${command.displayName} ${numTimesToLaunch} times`) + const numTimesToLaunch = fakeCommands.length - i + //console.log(`Launching ${command.displayName} ${numTimesToLaunch} times`) - for (j=0; j { + beforeEach(async () => { + await commandPalette.update({initialOrderingOfItems: 'frequency'}) }) it('orders the scored items correctly', async () => { @@ -95,17 +97,39 @@ describe('CommandPaletteView', () => { }) }) - xdescribe('when initially sorting by recentness', () => { - it('has selected the "recent" option in palette settings', async () => { - + describe('when initially sorting by recentness', () => { + beforeEach(async () => { + await commandPalette.update({initialOrderingOfItems: 'recent'}) }) - it('orders the palette items correctly', async () => { + it('orders the scored items correctly', async () => { + await commandPalette.show() + await commandPalette.selectListView.refs.queryEditor.setText('') + await commandPalette.selectListView.update() + fakeCommands.reverse().forEach(command => { + const selectedItem = commandPalette.selectListView.getSelectedItem().name + assert.equal(selectedItem, command) + commandPalette.selectListView.selectNext() + }) }) it('orders the rest of the palette items alphabetically', async () => { + await commandPalette.show() + await commandPalette.selectListView.refs.queryEditor.setText('') + await commandPalette.selectListView.update() + // skip scored items + for(let i=0; i { @@ -113,16 +137,27 @@ describe('CommandPaletteView', () => { }) }) - xdescribe('when initially sorting alphabetically', () => { - it('has selected the "alphabetic" option in palette settings', async () => { - + describe('when initially sorting alphabetically', () => { + beforeEach(async () => { + await commandPalette.update({initialOrderingOfItems: 'alphabetic'}) }) it('orders the palette items correctly', async () => { + await commandPalette.show() + await commandPalette.selectListView.refs.queryEditor.setText('') + await commandPalette.selectListView.update() + // compare pairwise items + let currentItem, previousItem + do { + previousItem = commandPalette.selectListView.getSelectedItem().name + currentItem = commandPalette.selectListView.selectNext().name + assert.equal(previousItem.localeCompare(currentItem), -1) + } + while (currentItem) }) - it('remembers the ordering between launches', async () => { + xit('remembers the ordering between launches', async () => { }) }) From 98acb8e407578a0ea06e5eaa293ecccd4df1fae7 Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Fri, 29 Sep 2017 18:58:23 +0200 Subject: [PATCH 8/9] implemented tests for serializing view, fixed alphabetic assertion --- test/command-palette-view.test.js | 75 +++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/test/command-palette-view.test.js b/test/command-palette-view.test.js index 1bf7b5c..c42ca9e 100644 --- a/test/command-palette-view.test.js +++ b/test/command-palette-view.test.js @@ -79,6 +79,9 @@ describe('CommandPaletteView', () => { await commandPalette.selectListView.refs.queryEditor.setText('') await commandPalette.selectListView.update() + commandPalette.selectListView.selectFirst() + const firstItem = commandPalette.selectListView.getSelectedItem().name + // skip scored items for(let i=0; i { let currentItem, previousItem do { previousItem = commandPalette.selectListView.getSelectedItem().name - currentItem = commandPalette.selectListView.selectNext().name + commandPalette.selectListView.selectNext() + currentItem = commandPalette.selectListView.getSelectedItem().name + if(currentItem == firstItem) break; assert.equal(previousItem.localeCompare(currentItem), -1) } - while (currentItem) + while (previousItem != firstItem) }) - xit('remembers the ordering between launches', async () => { + it('remembers the ordering between launches', async () => { + const serializedState = commandPalette.serialize(); + const newCommandPalette = new CommandPaletteView(serializedState); + + await newCommandPalette.update({initialOrderingOfItems: 'frequency'}) + await newCommandPalette.show() + await newCommandPalette.selectListView.refs.queryEditor.setText('') + await newCommandPalette.selectListView.update() + fakeCommands.forEach(command => { + const selectedItem = newCommandPalette.selectListView.getSelectedItem().name + assert.equal(selectedItem, command) + newCommandPalette.selectListView.selectNext() + }) }) }) @@ -119,6 +136,9 @@ describe('CommandPaletteView', () => { await commandPalette.selectListView.refs.queryEditor.setText('') await commandPalette.selectListView.update() + commandPalette.selectListView.selectFirst() + const firstItem = commandPalette.selectListView.getSelectedItem().name + // skip scored items for(let i=0; i { let currentItem, previousItem do { previousItem = commandPalette.selectListView.getSelectedItem().name - currentItem = commandPalette.selectListView.selectNext().name + commandPalette.selectListView.selectNext() + currentItem = commandPalette.selectListView.getSelectedItem().name + if(currentItem == firstItem) break; assert.equal(previousItem.localeCompare(currentItem), -1) } - while (currentItem) + while (previousItem != firstItem) }) it('remembers the ordering between launches', async () => { + const serializedState = commandPalette.serialize(); + const newCommandPalette = new CommandPaletteView(serializedState); + + await newCommandPalette.update({initialOrderingOfItems: 'recent'}) + await newCommandPalette.show() + await newCommandPalette.selectListView.refs.queryEditor.setText('') + await newCommandPalette.selectListView.update() + fakeCommands.reverse().forEach(command => { + const selectedItem = newCommandPalette.selectListView.getSelectedItem().name + assert.equal(selectedItem, command) + newCommandPalette.selectListView.selectNext() + }) }) }) @@ -147,18 +181,43 @@ describe('CommandPaletteView', () => { await commandPalette.selectListView.refs.queryEditor.setText('') await commandPalette.selectListView.update() + commandPalette.selectListView.selectFirst() + const firstItem = commandPalette.selectListView.getSelectedItem().name + // compare pairwise items let currentItem, previousItem do { previousItem = commandPalette.selectListView.getSelectedItem().name - currentItem = commandPalette.selectListView.selectNext().name + commandPalette.selectListView.selectNext() + currentItem = commandPalette.selectListView.getSelectedItem().name + if(currentItem == firstItem) break; assert.equal(previousItem.localeCompare(currentItem), -1) } - while (currentItem) + while (previousItem != firstItem) }) - xit('remembers the ordering between launches', async () => { + it('remembers the ordering between launches', async () => { + const serializedState = commandPalette.serialize(); + const newCommandPalette = new CommandPaletteView(serializedState); + + await newCommandPalette.update({initialOrderingOfItems: 'recent'}) + await newCommandPalette.show() + await newCommandPalette.selectListView.refs.queryEditor.setText('') + await newCommandPalette.selectListView.update() + + commandPalette.selectListView.selectFirst() + const firstItem = commandPalette.selectListView.getSelectedItem().name + // compare pairwise items + let currentItem, previousItem + do { + previousItem = commandPalette.selectListView.getSelectedItem().name + commandPalette.selectListView.selectNext() + currentItem = commandPalette.selectListView.getSelectedItem().name + if(currentItem == firstItem) break; + assert.equal(previousItem.localeCompare(currentItem), -1) + } + while (previousItem != firstItem) }) }) }) From 016f3177500b5f5088b1432c0ba71b99d5c35791 Mon Sep 17 00:00:00 2001 From: Jarle Mathiesen Date: Sat, 30 Sep 2017 16:10:00 +0200 Subject: [PATCH 9/9] fewer mock commands used in tests to avoid timeout --- test/command-palette-view.test.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/command-palette-view.test.js b/test/command-palette-view.test.js index c42ca9e..b1c36ce 100644 --- a/test/command-palette-view.test.js +++ b/test/command-palette-view.test.js @@ -25,16 +25,10 @@ describe('CommandPaletteView', () => { describe('initial sorting', () => { let commandPalette const fakeCommands = [ - "first", - "one", - "two", - "three", - "four", - "five", - "six", - "seven", - "last" - ].map(e => `command-palette:${e}`) + 'one', + 'two', + 'three', + ].map(command => `command-palette-test:${command}`) beforeEach(async () => { commandPalette = new CommandPaletteView()