Skip to content

Commit a462b45

Browse files
committed
Fix version selector test
1 parent f1c1d81 commit a462b45

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

addon/components/docs-header/version-selector/component.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
import Component from '@ember/component';
22
import { inject as service } from '@ember/service';
33
import layout from './template';
4-
import { sort } from '@ember/object/computed';
54
import { reads } from '@ember/object/computed';
6-
import config from 'dummy/config/environment';
7-
8-
const { latestVersionName, primaryBranch } = config['ember-cli-addon-docs'];
5+
// import config from 'dummy/config/environment';
6+
import { computed } from '@ember/object';
7+
import { A } from '@ember/array';
8+
import { getOwner } from '@ember/application';
99

10+
// const { latestVersionName, primaryBranch } = config['ember-cli-addon-docs'];
11+
//
1012
export default Component.extend({
1113
layout,
1214

13-
latestVersionName,
14-
primaryBranch,
15+
latestVersionName: computed(function() {
16+
let config = getOwner(this).resolveRegistration('config:environment')['ember-cli-addon-docs'];
17+
18+
return config.latestVersionName;
19+
}),
20+
21+
primaryBranch: computed(function() {
22+
let config = getOwner(this).resolveRegistration('config:environment')['ember-cli-addon-docs'];
23+
24+
return config.primaryBranch;
25+
}),
1526

1627
projectVersion: service(),
1728
'on-close'() {},
1829

1930
currentVersion: reads('projectVersion.currentVersion'),
2031

21-
sortedVersions: sort('projectVersion.versions', function(a, b) {
22-
if ([latestVersionName, primaryBranch].includes(a.key) || [latestVersionName, primaryBranch].includes(b.key) ) {
23-
return a.key > b.key;
24-
} else {
25-
return a.key < b.key;
26-
}
32+
sortedVersions: computed('projectVersion.versions', 'latestVersionName', 'primaryBranch', function() {
33+
let latestVersionName = this.get('latestVersionName');
34+
let primaryBranch = this.get('primaryBranch');
35+
let versions = A(this.get('projectVersion.versions'));
36+
let latest = versions.findBy('key', latestVersionName);
37+
let primary = versions.findBy('key', primaryBranch);
38+
39+
return [
40+
latest,
41+
primary,
42+
...versions.removeObjects([ latest, primary ]).sortBy('key')
43+
].filter(Boolean);
2744
}),
2845

2946
actions: {

tests/acceptance/version-selector-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ module('Acceptance | Version selector test', function(hooks) {
105105
let oldPrimaryBranch;
106106
hooks.beforeEach(function() {
107107
oldPrimaryBranch = config.primaryBranch;
108-
config.primaryBranch = 'develop';
108+
config['ember-cli-addon-docs'].primaryBranch = 'develop';
109109
});
110110

111111
hooks.afterEach(function() {
112-
config.primaryBranch = oldPrimaryBranch;
112+
config['ember-cli-addon-docs'].primaryBranch = oldPrimaryBranch;
113113
});
114114

115115
test(`the version selector honors the primary branch`, async function(assert) {

tests/dummy/app/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Application from '@ember/application';
22
import Resolver from './resolver';
33
import loadInitializers from 'ember-load-initializers';
44
import config from './config/environment';
5+
import { registerWarnHandler } from '@ember/debug';
56

67
// BEGIN-SNIPPET sample-snippet.js
78
const App = Application.extend({
@@ -13,4 +14,10 @@ const App = Application.extend({
1314

1415
loadInitializers(App, config.modulePrefix);
1516

17+
registerWarnHandler(function(message, { id }, next) {
18+
if (id !== 'ember-test-selectors.empty-tag-name') {
19+
next(...arguments);
20+
}
21+
});
22+
1623
export default App;

0 commit comments

Comments
 (0)