ui: Some trivial test additions, support env var passing of port numbers (#4728)

1. Unskip some trivial tests that were being tested higher up
2. Istanbul ignore some code for coverage.
  1. Things that I didn't write and need to 100% follow
  2. The source code checking test that has Istanbul code injected into
  it
3. Add a few simple test cases
4. Support passing port numbers through to `ember serve` and `ember
test` for use cases that would benefit from being able to configure the
ports things are served over but still use `yarn run` thus reusing the
`yarn run` config in `package.json`
This commit is contained in:
John Cowen 2018-10-26 17:50:43 +01:00 committed by GitHub
parent 14aa90e309
commit f1246801b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 936 additions and 156 deletions

View File

@ -1,6 +1,8 @@
import { helper } from '@ember/component/helper';
export function last([obj = ''], hash) {
// TODO: Another candidate for a reusable type checking
// util for helpers
switch (true) {
case typeof obj === 'string':
return obj.substr(-1);

View File

@ -1,7 +1,7 @@
import { helper } from '@ember/component/helper';
export function split([array = [], separator = ','], hash) {
return array.split(separator);
export function split([str = '', separator = ','], hash) {
return str.split(separator);
}
export default helper(split);

View File

@ -1,5 +1,7 @@
export default function(a, b)
{
// TODO: Istanbul is ignored for the moment as it's not mine,
// once I come here properly and 100% follow unignore
/* istanbul ignore file */
export default function(a, b) {
a = a.Coord;
b = b.Coord;
let sum = 0;

View File

@ -1,4 +1,5 @@
// prettier-ignore
/* istanbul ignore file */
export default function(JSON) {
// Has to be a property on an object so babel knocks the indentation in
return {

View File

@ -1,3 +1,6 @@
// TODO: Istanbul is ignored for the moment as it's not mine,
// once I come here properly and 100% follow unignore
/* istanbul ignore file */
export default function(distance) {
return function(name, coordinates) {
var min = 999999999;

View File

@ -13,10 +13,12 @@
"lint:dev:js": "eslint -c .dev.eslintrc.js --fix ./*.js ./.*.js app config lib server tests",
"lint:js": "eslint -c .eslintrc.js --fix ./*.js ./.*.js app config lib server tests",
"format:js": "prettier --write \"{app,config,lib,server,tests}/**/*.js\" ./*.js ./.*.js",
"start": "ember serve",
"start": "ember serve --port=${EMBER_SERVE_PORT:-4200} --live-reload-port=${EMBER_LIVE_RELOAD_PORT:-7020}",
"start:api": "api-double --dir ./node_modules/@hashicorp/consul-api-double",
"test": "ember test",
"test:view": "ember test --server"
"test": "ember test --test-port=${EMBER_TEST_PORT:-7357}",
"test:view": "ember test --server --test-port=${EMBER_TEST_PORT:-7357}",
"test:coverage": "COVERAGE=true ember test --test-port=${EMBER_TEST_PORT:-7357}",
"test:view:coverage": "COVERAGE=true ember test --server --test-port=${EMBER_TEST_PORT:-7357}"
},
"husky": {
"hooks": {

View File

@ -10,14 +10,14 @@ test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// this.render(hbs`{{feedback-dialog}}`);
this.render(hbs`{{feedback-dialog}}`);
// assert.equal(
// this.$()
// .text()
// .trim(),
// ''
// );
assert.equal(
this.$()
.text()
.trim(),
''
);
// Template block usage:
this.render(hbs`

View File

@ -1,4 +1,4 @@
import { moduleForComponent, skip } from 'ember-qunit';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('env', 'helper:env', {
@ -6,8 +6,8 @@ moduleForComponent('env', 'helper:env', {
});
// Replace this with your real tests.
skip('it renders', function(assert) {
this.set('inputValue', '1234');
test('it renders', function(assert) {
this.set('inputValue', 'CONSUL_COPYRIGHT_URL');
this.render(hbs`{{env inputValue}}`);
@ -15,6 +15,6 @@ skip('it renders', function(assert) {
this.$()
.text()
.trim(),
'1234'
'https://www.hashicorp.com'
);
});

View File

@ -1,4 +1,4 @@
import { moduleForComponent, skip } from 'ember-qunit';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('last', 'helper:last', {
@ -6,8 +6,8 @@ moduleForComponent('last', 'helper:last', {
});
// Replace this with your real tests.
skip('it renders', function(assert) {
this.set('inputValue', '1234');
test('it renders', function(assert) {
this.set('inputValue', 'get-the-last-character/');
this.render(hbs`{{last inputValue}}`);
@ -15,6 +15,6 @@ skip('it renders', function(assert) {
this.$()
.text()
.trim(),
'1234'
'/'
);
});

View File

@ -1,4 +1,4 @@
import { moduleForComponent, skip } from 'ember-qunit';
import { moduleForComponent, test, skip } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('slugify', 'helper:slugify', {
@ -6,8 +6,8 @@ moduleForComponent('slugify', 'helper:slugify', {
});
// Replace this with your real tests.
skip('it renders', function(assert) {
this.set('inputValue', '1234');
test('it renders', function(assert) {
this.set('inputValue', 'Hi There');
this.render(hbs`{{slugify inputValue}}`);
@ -15,6 +15,7 @@ skip('it renders', function(assert) {
this.$()
.text()
.trim(),
'1234'
'hi-there'
);
});
skip("it copes with more values such as ' etc");

View File

@ -1,4 +1,4 @@
import { moduleForComponent, skip } from 'ember-qunit';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('split', 'helper:split', {
@ -6,8 +6,8 @@ moduleForComponent('split', 'helper:split', {
});
// Replace this with your real tests.
skip('it renders', function(assert) {
this.set('inputValue', '1234');
test('it renders', function(assert) {
this.set('inputValue', 'a,string,split,by,a,comma');
this.render(hbs`{{split inputValue}}`);
@ -15,6 +15,6 @@ skip('it renders', function(assert) {
this.$()
.text()
.trim(),
'1234'
'a,string,split,by,a,comma'
);
});

View File

@ -0,0 +1,20 @@
import { module } from 'ember-qunit';
import test from 'ember-sinon-qunit/test-support/test';
import btoa from 'consul-ui/utils/btoa';
module('Unit | Utils | btoa', {});
test('it encodes strings properly', function(assert) {
[
{
test: '',
expected: '',
},
{
test: '1234',
expected: 'MTIzNA==',
},
].forEach(function(item) {
const actual = btoa(item.test);
assert.equal(actual, item.expected);
});
});

View File

@ -8,3 +8,10 @@ test('returns a function returning the string', function(assert) {
const actual = callableType(expected)();
assert.equal(actual, expected);
});
test('returns the same function if you pass it a function', function(assert) {
const expected = 'hi';
const actual = callableType(function() {
return 'hi';
})();
assert.equal(actual, expected);
});

View File

@ -39,3 +39,14 @@ test('it adds a query string key without an `=` if the query value is `null`', f
assert.equal(actual, item.expected);
});
});
test("it returns a string with no query string if you don't pass a query string object", function(assert) {
[
{
args: [['/v1/url'], ['raw', 'values', 'to', 'encode']],
expected: '/v1/url/raw/values/to/encode',
},
].forEach(function(item) {
const actual = createURL(...item.args);
assert.equal(actual, item.expected);
});
});

View File

@ -21,6 +21,10 @@ test('it detects if a string ends in a slash', function(assert) {
test: '//',
expected: true,
},
{
test: undefined,
expected: false,
},
].forEach(function(item) {
const actual = isFolder(item.test);
assert.equal(actual, item.expected);

File diff suppressed because it is too large Load Diff