1
+ import type { IBreadCrumbController } from '@nsf-open/ember-ui-foundation/constants' ;
2
+ import type { TestContext } from '@ember/test-helpers' ;
3
+
1
4
import { module , test } from 'qunit' ;
2
5
import { setupApplicationTest } from 'ember-qunit' ;
3
6
import { visit } from '@ember/test-helpers' ;
4
7
5
8
module ( 'Acceptance | Component | ui-bread-crumbs' , function ( hooks ) {
6
9
setupApplicationTest ( hooks ) ;
7
10
11
+ function lookupController ( owner : TestContext [ 'owner' ] , fullName : string ) : IBreadCrumbController {
12
+ return owner . lookup ( fullName ) as IBreadCrumbController ;
13
+ }
14
+
8
15
function nthCrumb ( idx : number , anchor = false ) {
9
16
return `.breadcrumb li:nth-child(${ idx } )${ anchor ? ' a' : '' } ` ;
10
17
}
@@ -39,13 +46,13 @@ module('Acceptance | Component | ui-bread-crumbs', function (hooks) {
39
46
} ) ;
40
47
41
48
test ( 'it does not render an empty ordered list' , async function ( assert ) {
42
- this . owner . lookup ( 'controller:application' ) . breadCrumb = undefined ;
49
+ lookupController ( this . owner , 'controller:application' ) . breadCrumb = undefined ;
43
50
await visit ( '/' ) ;
44
51
assert . dom ( '.breadcrumb' ) . doesNotExist ( ) ;
45
52
} ) ;
46
53
47
54
test ( 'it filters out breadcrumbs with no label text' , async function ( assert ) {
48
- this . owner . lookup ( 'controller:playground' ) . breadCrumb = { label : '' } ;
55
+ lookupController ( this . owner , 'controller:playground' ) . breadCrumb = { label : '' } ;
49
56
50
57
await visit ( '/playground' ) ;
51
58
@@ -54,14 +61,20 @@ module('Acceptance | Component | ui-bread-crumbs', function (hooks) {
54
61
} ) ;
55
62
56
63
test ( 'it supports a breadcrumb being able to "rewind", to remove, prior crumbs' , async function ( assert ) {
57
- this . owner . lookup ( 'controller:playground' ) . breadCrumb = { label : 'Foobar' , rewind : 1 } ;
64
+ lookupController ( this . owner , 'controller:playground' ) . breadCrumb = {
65
+ label : 'Foobar' ,
66
+ rewind : 1 ,
67
+ } ;
58
68
59
69
await visit ( '/playground' ) ;
60
70
61
71
assert . dom ( nthCrumb ( 1 ) ) . hasText ( 'Foobar' ) ;
62
72
assert . dom ( nthCrumb ( 2 ) ) . doesNotExist ( ) ;
63
73
64
- this . owner . lookup ( 'controller:artists.artist' ) . breadCrumb = { label : 'Baz' , rewind : - 1 } ;
74
+ lookupController ( this . owner , 'controller:artists.artist' ) . breadCrumb = {
75
+ label : 'Baz' ,
76
+ rewind : - 1 ,
77
+ } ;
65
78
66
79
await visit ( '/artists/queen' ) ;
67
80
@@ -70,8 +83,8 @@ module('Acceptance | Component | ui-bread-crumbs', function (hooks) {
70
83
} ) ;
71
84
72
85
test ( 'it support a breadcrumb with fully custom href and target' , async function ( assert ) {
73
- this . owner . lookup ( 'controller:playground' ) . breadCrumb = undefined ;
74
- this . owner . lookup ( 'controller:playground' ) . breadCrumbs = [
86
+ lookupController ( this . owner , 'controller:playground' ) . breadCrumb = undefined ;
87
+ lookupController ( this . owner , 'controller:playground' ) . breadCrumbs = [
75
88
{ label : 'Search' , href : 'https://www.google.com' } ,
76
89
{ label : 'Playground' } ,
77
90
] ;
@@ -83,7 +96,7 @@ module('Acceptance | Component | ui-bread-crumbs', function (hooks) {
83
96
assert . dom ( nthCrumb ( 2 , true ) ) . hasAttribute ( 'target' , '_self' ) ;
84
97
assert . dom ( nthCrumb ( 4 ) ) . doesNotExist ( ) ;
85
98
86
- this . owner . lookup ( 'controller:artists' ) . breadCrumb = {
99
+ lookupController ( this . owner , 'controller:artists' ) . breadCrumb = {
87
100
label : 'Search More' ,
88
101
href : 'https://www.bing.com' ,
89
102
target : '_blank' ,
0 commit comments