88
99import { ComponentFixture , TestBed } from '@angular/core/testing' ;
1010
11- import ApiReferenceList , { ALL_TYPES_KEY } from './api-reference-list.component' ;
11+ import ApiReferenceList , {
12+ ALL_TYPES_KEY ,
13+ DEFAULT_STATUS ,
14+ STATUSES ,
15+ } from './api-reference-list.component' ;
1216import { ApiReferenceManager } from './api-reference-manager.service' ;
1317import { signal } from '@angular/core' ;
1418import { ApiItemType } from '../interfaces/api-item-type' ;
@@ -26,24 +30,52 @@ describe('ApiReferenceList', () => {
2630 'url' : 'api/animations/fakeItem1' ,
2731 'itemType' : ApiItemType . FUNCTION ,
2832 'isDeprecated' : false ,
33+ 'isDeveloperPreview' : false ,
34+ 'isExperimental' : false ,
2935 } ;
3036 let fakeItem2 = {
3137 'title' : 'fakeItem2' ,
3238 'url' : 'api/animations/fakeItem2' ,
3339 'itemType' : ApiItemType . CLASS ,
3440 'isDeprecated' : false ,
41+ 'isDeveloperPreview' : false ,
42+ 'isExperimental' : false ,
3543 } ;
3644 let fakeDeprecatedFeaturedItem = {
3745 'title' : 'fakeItemDeprecated' ,
3846 'url' : 'api/animations/fakeItemDeprecated' ,
3947 'itemType' : ApiItemType . INTERFACE ,
4048 'isDeprecated' : true ,
49+ 'isDeveloperPreview' : false ,
50+ 'isExperimental' : false ,
51+ } ;
52+ let fakeDeveloperPreviewItem = {
53+ 'title' : 'fakeItemDeveloperPreview' ,
54+ 'url' : 'api/animations/fakeItemDeveloperPreview' ,
55+ 'itemType' : ApiItemType . INTERFACE ,
56+ 'isDeprecated' : false ,
57+ 'isDeveloperPreview' : true ,
58+ 'isExperimental' : false ,
59+ } ;
60+ let fakeExperimentalItem = {
61+ 'title' : 'fakeItemExperimental' ,
62+ 'url' : 'api/animations/fakeItemExperimental' ,
63+ 'itemType' : ApiItemType . INTERFACE ,
64+ 'isDeprecated' : false ,
65+ 'isDeveloperPreview' : false ,
66+ 'isExperimental' : true ,
4167 } ;
4268 const fakeApiReferenceManager = {
4369 apiGroups : signal ( [
4470 {
4571 title : 'Fake Group' ,
46- items : [ fakeItem1 , fakeItem2 , fakeDeprecatedFeaturedItem ] ,
72+ items : [
73+ fakeItem1 ,
74+ fakeItem2 ,
75+ fakeDeprecatedFeaturedItem ,
76+ fakeDeveloperPreviewItem ,
77+ fakeExperimentalItem ,
78+ ] ,
4779 isFeatured : false ,
4880 } ,
4981 ] ) ,
@@ -71,33 +103,15 @@ describe('ApiReferenceList', () => {
71103 expect ( component ) . toBeTruthy ( ) ;
72104 } ) ;
73105
74- it ( 'should display both Deprecated and Non-deprecated APIs when includeDeprecated toggle is set to true' , ( ) => {
75- component . includeDeprecated . set ( true ) ;
76- fixture . detectChanges ( ) ;
77-
78- expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [
79- fakeItem1 ,
80- fakeItem2 ,
81- fakeDeprecatedFeaturedItem ,
82- ] ) ;
83- } ) ;
84-
85- it ( 'should display both Non-deprecated APIs when includeDeprecated toggle is set to false' , ( ) => {
86- component . includeDeprecated . set ( false ) ;
87- fixture . detectChanges ( ) ;
88-
89- expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeItem1 , fakeItem2 ] ) ;
90- } ) ;
91-
92106 it ( 'should display only items which contains provided query when query is not empty' , ( ) => {
93- component . query . set ( 'Item1' ) ;
107+ fixture . componentRef . setInput ( 'query' , 'Item1' ) ;
94108 fixture . detectChanges ( ) ;
95109
96110 expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeItem1 ] ) ;
97111 } ) ;
98112
99113 it ( 'should display only class items when user selects Class in the Type select' , ( ) => {
100- fixture . componentInstance . type . set ( ApiItemType . CLASS ) ;
114+ fixture . componentRef . setInput ( 'type' , ApiItemType . CLASS ) ;
101115 fixture . detectChanges ( ) ;
102116
103117 expect ( component . type ( ) ) . toEqual ( ApiItemType . CLASS ) ;
@@ -106,17 +120,17 @@ describe('ApiReferenceList', () => {
106120
107121 it ( 'should set selected type when provided type is different than selected' , async ( ) => {
108122 expect ( component . type ( ) ) . toBe ( ALL_TYPES_KEY ) ;
109- component . filterByItemType ( ApiItemType . BLOCK ) ;
123+ component . setItemType ( ApiItemType . BLOCK ) ;
110124 await RouterTestingHarness . create ( `/api?type=${ ApiItemType . BLOCK } ` ) ;
111125 expect ( component . type ( ) ) . toBe ( ApiItemType . BLOCK ) ;
112126 } ) ;
113127
114128 it ( 'should reset selected type when provided type is equal to selected' , async ( ) => {
115- component . filterByItemType ( ApiItemType . BLOCK ) ;
129+ component . setItemType ( ApiItemType . BLOCK ) ;
116130 const harness = await RouterTestingHarness . create ( `/api?type=${ ApiItemType . BLOCK } ` ) ;
117131 expect ( component . type ( ) ) . toBe ( ApiItemType . BLOCK ) ;
118132
119- component . filterByItemType ( ApiItemType . BLOCK ) ;
133+ component . setItemType ( ApiItemType . BLOCK ) ;
120134 harness . navigateByUrl ( `/api` ) ;
121135 expect ( component . type ( ) ) . toBe ( ALL_TYPES_KEY ) ;
122136 } ) ;
@@ -126,28 +140,67 @@ describe('ApiReferenceList', () => {
126140
127141 const textField = fixture . debugElement . query ( By . directive ( TextField ) ) ;
128142 ( textField . componentInstance as TextField ) . setValue ( 'item1' ) ;
129-
130143 await fixture . whenStable ( ) ;
131- expect ( location . path ( ) ) . toBe ( `?query=item1&type=All ` ) ;
144+ expect ( location . path ( ) ) . toBe ( `?query=item1` ) ;
132145 } ) ;
133146
134- it ( 'should keep the values of existing queryParams and set new queryParam equal to the type ' , async ( ) => {
147+ it ( 'should keep the values of existing queryParams and set new queryParam equal to given value ' , async ( ) => {
135148 const location = TestBed . inject ( Location ) ;
136149
137150 const textField = fixture . debugElement . query ( By . directive ( TextField ) ) ;
138151 ( textField . componentInstance as TextField ) . setValue ( 'item1' ) ;
139152 await fixture . whenStable ( ) ;
140- expect ( location . path ( ) ) . toBe ( `?query=item1&type=All ` ) ;
153+ expect ( location . path ( ) ) . toBe ( `?query=item1` ) ;
141154
142- component . filterByItemType ( ApiItemType . BLOCK ) ;
155+ component . setItemType ( ApiItemType . BLOCK ) ;
143156 await fixture . whenStable ( ) ;
144157 expect ( location . path ( ) ) . toBe ( `?query=item1&type=${ ApiItemType . BLOCK } ` ) ;
158+
159+ fixture . componentRef . setInput ( 'status' , STATUSES . experimental ) ;
160+ await fixture . whenStable ( ) ;
161+ expect ( location . path ( ) ) . toBe (
162+ `?query=item1&type=${ ApiItemType . BLOCK } &status=${ STATUSES . experimental } ` ,
163+ ) ;
145164 } ) ;
146165
147- it ( 'should display all items when query and type are undefined' , async ( ) => {
148- component . query . set ( undefined ) ;
149- component . type . set ( undefined ) ;
166+ it ( 'should display all items when query and type and status are undefined' , async ( ) => {
167+ fixture . componentRef . setInput ( 'query' , undefined ) ;
168+ fixture . componentRef . setInput ( 'type' , undefined ) ;
169+ fixture . componentRef . setInput ( 'status' , undefined ) ;
150170 await fixture . whenStable ( ) ;
171+ expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [
172+ fakeItem1 ,
173+ fakeItem2 ,
174+ fakeDeveloperPreviewItem ,
175+ fakeExperimentalItem ,
176+ ] ) ;
177+ } ) ;
178+
179+ it ( 'should not display deprecated and developer-preview and experimental items when status is set to stable' , ( ) => {
180+ fixture . componentRef . setInput ( 'status' , STATUSES . stable ) ;
181+ fixture . detectChanges ( ) ;
182+
151183 expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeItem1 , fakeItem2 ] ) ;
152184 } ) ;
185+
186+ it ( 'should only display deprecated items when status is set to deprecated' , ( ) => {
187+ fixture . componentRef . setInput ( 'status' , STATUSES . deprecated ) ;
188+ fixture . detectChanges ( ) ;
189+
190+ expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeDeprecatedFeaturedItem ] ) ;
191+ } ) ;
192+
193+ it ( 'should only display developer-preview items when status is set to developer-preview' , ( ) => {
194+ fixture . componentRef . setInput ( 'status' , STATUSES . developerPreview ) ;
195+ fixture . detectChanges ( ) ;
196+
197+ expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeDeveloperPreviewItem ] ) ;
198+ } ) ;
199+
200+ it ( 'should only display experimental items when status is set to experimental' , ( ) => {
201+ fixture . componentRef . setInput ( 'status' , STATUSES . experimental ) ;
202+ fixture . detectChanges ( ) ;
203+
204+ expect ( component . filteredGroups ( ) ! [ 0 ] . items ) . toEqual ( [ fakeExperimentalItem ] ) ;
205+ } ) ;
153206} ) ;
0 commit comments