|
1 | 1 | import { CommonModule } from '@angular/common'; |
2 | 2 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
3 | 3 | import { |
4 | | - async, |
5 | 4 | ComponentFixture, |
6 | 5 | TestBed, |
| 6 | + waitForAsync, |
7 | 7 | } from '@angular/core/testing'; |
8 | 8 | import { |
9 | 9 | FormsModule, |
@@ -46,7 +46,7 @@ describe('ComcolPageBrowseByComponent', () => { |
46 | 46 | let configurationServiceStub: any; |
47 | 47 | let collectionServiceStub: any; |
48 | 48 |
|
49 | | - beforeEach(async(() => { |
| 49 | + beforeEach(waitForAsync(() => { |
50 | 50 |
|
51 | 51 | collectionServiceStub = { |
52 | 52 | findById(id: string, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<Collection>> { |
@@ -100,95 +100,95 @@ describe('ComcolPageBrowseByComponent', () => { |
100 | 100 |
|
101 | 101 | })); |
102 | 102 |
|
103 | | - it('should create ComcolPageBrowseByComponent for a community with only one option', () => { |
104 | | - fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
105 | | - component = fixture.componentInstance; |
106 | | - component.id = communityId; |
107 | | - component.contentType = 'community'; |
108 | | - |
109 | | - fixture.detectChanges(); |
110 | | - |
111 | | - expect(component.allOptions.length).toEqual(1); |
112 | | - const firstOption = component.allOptions[0]; |
113 | | - expect(firstOption.id).toEqual(communityId); |
114 | | - expect(firstOption.label).toEqual('community.all-lists.head'); |
115 | | - expect(firstOption.routerLink).toEqual('/communities/' + communityId); |
| 103 | + describe('when object is a community', () => { |
| 104 | + beforeEach(() => { |
| 105 | + fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
| 106 | + component = fixture.componentInstance; |
| 107 | + component.id = communityId; |
| 108 | + component.contentType = 'community'; |
| 109 | + |
| 110 | + fixture.detectChanges(); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should have only two option', () => { |
| 114 | + const navElements = fixture.debugElement.queryAll(By.css('.list-group-item')); |
| 115 | + expect(navElements).toHaveSize(2); |
| 116 | + |
| 117 | + expect(component.allOptions.length).toEqual(2); |
| 118 | + const firstOption = component.allOptions[0]; |
| 119 | + expect(firstOption.id).toEqual('search'); |
| 120 | + expect(firstOption.label).toEqual('community.page.browse.search.head'); |
| 121 | + expect(firstOption.routerLink).toEqual('/communities/' + communityId); |
| 122 | + |
| 123 | + const secondOption = component.allOptions[1]; |
| 124 | + expect(secondOption.id).toEqual('comcols'); |
| 125 | + expect(secondOption.label).toEqual('community.all-lists.head'); |
| 126 | + expect(secondOption.routerLink).toEqual('/communities/' + communityId + '/subcoms-cols'); |
| 127 | + }); |
116 | 128 | }); |
117 | 129 |
|
118 | | - it('should create ComcolPageBrowseByComponent for the publication\'s collection with three option', () => { |
119 | | - fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
120 | | - component = fixture.componentInstance; |
121 | | - component.id = publicationId; |
122 | | - component.contentType = 'collection'; |
123 | | - |
124 | | - fixture.detectChanges(); |
125 | | - |
126 | | - expect(component.allOptions.length).toEqual(3); |
127 | | - const firstOption = component.allOptions[0]; |
128 | | - expect(firstOption.id).toEqual(publicationId); |
129 | | - expect(firstOption.label).toEqual('collection.page.browse.recent.head'); |
130 | | - expect(firstOption.routerLink).toEqual('/collections/' + publicationId); |
131 | | - const secondOption = component.allOptions[1]; |
132 | | - expect(secondOption.id).toEqual('author'); |
133 | | - expect(secondOption.label).toEqual('browse.comcol.by.author'); |
134 | | - expect(secondOption.routerLink).toEqual('/browse/author'); |
135 | | - expect(secondOption.params).toEqual({ scope: publicationId }); |
136 | | - const thirdOption = component.allOptions[2]; |
137 | | - expect(thirdOption.id).toEqual('title'); |
138 | | - expect(thirdOption.label).toEqual('browse.comcol.by.title'); |
139 | | - expect(thirdOption.routerLink).toEqual('/browse/title'); |
140 | | - expect(thirdOption.params).toEqual({ scope: publicationId }); |
| 130 | + describe('when object is a collection', () => { |
| 131 | + beforeEach(() => { |
| 132 | + fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
| 133 | + component = fixture.componentInstance; |
| 134 | + component.contentType = 'collection'; |
| 135 | + }); |
| 136 | + |
| 137 | + it('should have three options for the publication\'s collection', () => { |
| 138 | + component.id = publicationId; |
| 139 | + fixture.detectChanges(); |
| 140 | + |
| 141 | + const navElements = fixture.debugElement.queryAll(By.css('.list-group-item')); |
| 142 | + expect(navElements).toHaveSize(3); |
| 143 | + |
| 144 | + expect(component.allOptions.length).toEqual(3); |
| 145 | + const firstOption = component.allOptions[0]; |
| 146 | + expect(firstOption.id).toEqual('search'); |
| 147 | + expect(firstOption.label).toEqual('collection.page.browse.search.head'); |
| 148 | + expect(firstOption.routerLink).toEqual('/collections/' + publicationId); |
| 149 | + const secondOption = component.allOptions[1]; |
| 150 | + expect(secondOption.id).toEqual('author'); |
| 151 | + expect(secondOption.label).toEqual('browse.comcol.by.author'); |
| 152 | + expect(secondOption.routerLink).toEqual('/collections/' + publicationId + '/browse/author'); |
| 153 | + const thirdOption = component.allOptions[2]; |
| 154 | + expect(thirdOption.id).toEqual('title'); |
| 155 | + expect(thirdOption.label).toEqual('browse.comcol.by.title'); |
| 156 | + expect(thirdOption.routerLink).toEqual('/collections/' + publicationId + '/browse/title'); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should have two options for the orgUnit\'s collection', () => { |
| 160 | + component.id = orgUnitId; |
| 161 | + fixture.detectChanges(); |
| 162 | + |
| 163 | + const navElements = fixture.debugElement.queryAll(By.css('.list-group-item')); |
| 164 | + expect(navElements).toHaveSize(2); |
| 165 | + |
| 166 | + expect(component.allOptions.length).toEqual(2); |
| 167 | + const firstOption = component.allOptions[0]; |
| 168 | + expect(firstOption.id).toEqual('search'); |
| 169 | + expect(firstOption.label).toEqual('collection.page.browse.search.head'); |
| 170 | + expect(firstOption.routerLink).toEqual('/collections/' + orgUnitId); |
| 171 | + const secondOption = component.allOptions[1]; |
| 172 | + expect(secondOption.id).toEqual('ouname'); |
| 173 | + expect(secondOption.label).toEqual('browse.comcol.by.ouname'); |
| 174 | + expect(secondOption.routerLink).toEqual('/collections/' + orgUnitId + '/browse/ouname'); |
| 175 | + }); |
| 176 | + |
| 177 | + it('should display browse options when options are more then one', () => { |
| 178 | + |
| 179 | + fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
| 180 | + component = fixture.componentInstance; |
| 181 | + component.id = publicationId; |
| 182 | + component.contentType = 'collection'; |
| 183 | + |
| 184 | + fixture.detectChanges(); |
| 185 | + |
| 186 | + expect(component.allOptions.length).toEqual(3); |
| 187 | + |
| 188 | + const navElement = fixture.debugElement.query(By.css('nav')); |
| 189 | + expect(navElement).toBeTruthy(); |
| 190 | + |
| 191 | + }); |
141 | 192 | }); |
142 | 193 |
|
143 | | - it('should create ComcolPageBrowseByComponent for the orgUnit\'s collection with two option', () => { |
144 | | - fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
145 | | - component = fixture.componentInstance; |
146 | | - component.id = orgUnitId; |
147 | | - component.contentType = 'collection'; |
148 | | - |
149 | | - fixture.detectChanges(); |
150 | | - |
151 | | - expect(component.allOptions.length).toEqual(2); |
152 | | - const firstOption = component.allOptions[0]; |
153 | | - expect(firstOption.id).toEqual(orgUnitId); |
154 | | - expect(firstOption.label).toEqual('collection.page.browse.recent.head'); |
155 | | - expect(firstOption.routerLink).toEqual('/collections/' + orgUnitId); |
156 | | - const secondOption = component.allOptions[1]; |
157 | | - expect(secondOption.id).toEqual('ouname'); |
158 | | - expect(secondOption.label).toEqual('browse.comcol.by.ouname'); |
159 | | - expect(secondOption.routerLink).toEqual('/browse/ouname'); |
160 | | - expect(secondOption.params).toEqual({ scope: orgUnitId }); |
161 | | - }); |
162 | | - |
163 | | - it('should display browse options when options are more then one', () => { |
164 | | - |
165 | | - fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
166 | | - component = fixture.componentInstance; |
167 | | - component.id = publicationId; |
168 | | - component.contentType = 'collection'; |
169 | | - |
170 | | - fixture.detectChanges(); |
171 | | - |
172 | | - expect(component.allOptions.length).toEqual(3); |
173 | | - |
174 | | - const navElement = fixture.debugElement.query(By.css('nav')); |
175 | | - expect(navElement).toBeTruthy(); |
176 | | - |
177 | | - }); |
178 | | - |
179 | | - it('should not display browse options when options aren\'t more then one', () => { |
180 | | - |
181 | | - fixture = TestBed.createComponent(ComcolPageBrowseByComponent); |
182 | | - component = fixture.componentInstance; |
183 | | - component.id = communityId; |
184 | | - component.contentType = 'community'; |
185 | | - |
186 | | - fixture.detectChanges(); |
187 | | - |
188 | | - expect(component.allOptions.length).toEqual(1); |
189 | | - |
190 | | - const navElement = fixture.debugElement.query(By.css('nav')); |
191 | | - expect(navElement).toBeNull(); |
192 | | - |
193 | | - }); |
194 | 194 | }); |
0 commit comments