2019-05-01 18:19:43 +00:00
|
|
|
import { moduleForComponent, test } from 'ember-qunit';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
|
|
|
moduleForComponent('templated-anchor', 'Integration | Component | templated anchor', {
|
|
|
|
integration: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders', function(assert) {
|
|
|
|
[
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{Name}}/{{ID}}',
|
|
|
|
vars: {
|
|
|
|
Name: 'name',
|
|
|
|
ID: 'id',
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=name/id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{Name}}/{{ID}}',
|
|
|
|
vars: {
|
|
|
|
Name: '{{Name}}',
|
|
|
|
ID: '{{ID}}',
|
|
|
|
},
|
2019-05-02 11:07:18 +00:00
|
|
|
result: 'http://localhost/?=%7B%7BName%7D%7D/%7B%7BID%7D%7D',
|
2019-05-01 18:19:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{deep.Name}}/{{deep.ID}}',
|
|
|
|
vars: {
|
|
|
|
deep: {
|
|
|
|
Name: '{{Name}}',
|
|
|
|
ID: '{{ID}}',
|
|
|
|
},
|
|
|
|
},
|
2019-05-02 11:07:18 +00:00
|
|
|
result: 'http://localhost/?=%7B%7BName%7D%7D/%7B%7BID%7D%7D',
|
2019-05-01 18:19:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{}}/{{}}',
|
|
|
|
vars: {
|
|
|
|
Name: 'name',
|
|
|
|
ID: 'id',
|
|
|
|
},
|
2019-05-02 11:07:18 +00:00
|
|
|
// If you don't pass actual variables then nothing
|
|
|
|
// gets replaced and nothing is URL encoded
|
2019-05-01 18:19:43 +00:00
|
|
|
result: 'http://localhost/?={{}}/{{}}',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{Service_Name}}/{{Meta-Key}}',
|
|
|
|
vars: {
|
|
|
|
Service_Name: 'name',
|
|
|
|
['Meta-Key']: 'id',
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=name/id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{Service_Name}}/{{Meta-Key}}',
|
|
|
|
vars: {
|
|
|
|
WrongPropertyName: 'name',
|
|
|
|
['Meta-Key']: 'id',
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=/id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{.Name}}',
|
|
|
|
vars: {
|
|
|
|
['.Name']: 'name',
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{.}}',
|
|
|
|
vars: {
|
|
|
|
['.']: 'name',
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{deep..Name}}',
|
|
|
|
vars: {
|
|
|
|
deep: {
|
|
|
|
Name: 'Name',
|
|
|
|
ID: 'ID',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=',
|
|
|
|
},
|
2019-05-02 11:07:18 +00:00
|
|
|
{
|
|
|
|
href: 'http://localhost/?={{deep.Name}}',
|
|
|
|
vars: {
|
|
|
|
deep: {
|
|
|
|
Name: '#Na/me',
|
|
|
|
ID: 'ID',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
result: 'http://localhost/?=%23Na%2Fme',
|
|
|
|
},
|
2019-05-01 18:19:43 +00:00
|
|
|
].forEach(item => {
|
|
|
|
this.set('item', item);
|
|
|
|
this.render(hbs`
|
|
|
|
{{#templated-anchor href=item.href vars=item.vars}}
|
|
|
|
Dashboard link
|
|
|
|
{{/templated-anchor}}
|
|
|
|
`);
|
|
|
|
assert.equal(
|
|
|
|
this.$()
|
|
|
|
.find('a')
|
|
|
|
.attr('href'),
|
|
|
|
item.result
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|