Skip to content

Commit 4527349

Browse files
author
Jens Vannerum
committed
117544: alter specs to match new logic
1 parent 43745d8 commit 4527349

19 files changed

Lines changed: 141 additions & 65 deletions

File tree

src/app/access-control/epeople-registry/epeople-registry.component.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { RequestService } from '../../core/data/request.service';
2727
import { PaginationService } from '../../core/pagination/pagination.service';
2828
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
2929
import { FindListOptions } from '../../core/data/find-list-options.model';
30+
import {DisabledDirective} from '../../shared/disabled-directive';
3031

3132
describe('EPeopleRegistryComponent', () => {
3233
let component: EPeopleRegistryComponent;
@@ -131,7 +132,7 @@ describe('EPeopleRegistryComponent', () => {
131132
}
132133
}),
133134
],
134-
declarations: [EPeopleRegistryComponent],
135+
declarations: [EPeopleRegistryComponent, DisabledDirective],
135136
providers: [
136137
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
137138
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
@@ -269,7 +270,8 @@ describe('EPeopleRegistryComponent', () => {
269270
it('should be disabled', () => {
270271
ePeopleDeleteButton = fixture.debugElement.queryAll(By.css('#epeople tr td div button.delete-button'));
271272
ePeopleDeleteButton.forEach((deleteButton: DebugElement) => {
272-
expect(deleteButton.nativeElement.disabled).toBe(true);
273+
expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('true');
274+
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeTrue();
273275
});
274276
});
275277
});

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { PaginationServiceStub } from '../../../shared/testing/pagination-servic
3131
import { FindListOptions } from '../../../core/data/find-list-options.model';
3232
import { ValidateEmailNotTaken } from './validators/email-taken.validator';
3333
import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service';
34+
import {DisabledDirective} from '../../../shared/disabled-directive';
3435

3536
describe('EPersonFormComponent', () => {
3637
let component: EPersonFormComponent;
@@ -191,7 +192,7 @@ describe('EPersonFormComponent', () => {
191192
}
192193
}),
193194
],
194-
declarations: [EPersonFormComponent],
195+
declarations: [EPersonFormComponent, DisabledDirective],
195196
providers: [
196197
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
197198
{ provide: GroupDataService, useValue: groupsDataService },
@@ -493,14 +494,16 @@ describe('EPersonFormComponent', () => {
493494

494495
it('the delete button should be active if the eperson can be deleted', () => {
495496
const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
496-
expect(deleteButton.nativeElement.disabled).toBe(false);
497+
expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('false');
498+
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeFalse();
497499
});
498500

499501
it('the delete button should be disabled if the eperson cannot be deleted', () => {
500502
component.canDelete$ = observableOf(false);
501503
fixture.detectChanges();
502504
const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
503-
expect(deleteButton.nativeElement.disabled).toBe(true);
505+
expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('true');
506+
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeTrue();
504507
});
505508

506509
it('should call the epersonFormComponent delete when clicked on the button', () => {
@@ -515,7 +518,8 @@ describe('EPersonFormComponent', () => {
515518
// ePersonDataServiceStub.activeEPerson = eperson;
516519
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(createSuccessfulRemoteDataObject$('No Content', 204));
517520
const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
518-
expect(deleteButton.nativeElement.disabled).toBe(false);
521+
expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('false');
522+
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeFalse();
519523
deleteButton.triggerEventHandler('click', null);
520524
fixture.detectChanges();
521525
expect(component.epersonService.deleteEPerson).toHaveBeenCalledWith(eperson);

src/app/access-control/group-registry/groups-registry.component.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
3434
import { NoContent } from '../../core/shared/NoContent.model';
3535
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
3636
import { DSONameServiceMock, UNDEFINED_NAME } from '../../shared/mocks/dso-name.service.mock';
37+
import {DisabledDirective} from '../../shared/disabled-directive';
3738

3839
describe('GroupsRegistryComponent', () => {
3940
let component: GroupsRegistryComponent;
@@ -171,7 +172,7 @@ describe('GroupsRegistryComponent', () => {
171172
}
172173
}),
173174
],
174-
declarations: [GroupsRegistryComponent],
175+
declarations: [GroupsRegistryComponent, DisabledDirective],
175176
providers: [GroupsRegistryComponent,
176177
{ provide: DSONameService, useValue: new DSONameServiceMock() },
177178
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
@@ -231,7 +232,8 @@ describe('GroupsRegistryComponent', () => {
231232
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
232233
expect(editButtonsFound.length).toEqual(2);
233234
editButtonsFound.forEach((editButtonFound) => {
234-
expect(editButtonFound.nativeElement.disabled).toBeFalse();
235+
expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBeNull();
236+
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeFalse();
235237
});
236238
});
237239

@@ -265,7 +267,8 @@ describe('GroupsRegistryComponent', () => {
265267
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
266268
expect(editButtonsFound.length).toEqual(2);
267269
editButtonsFound.forEach((editButtonFound) => {
268-
expect(editButtonFound.nativeElement.disabled).toBeFalse();
270+
expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBeNull();
271+
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeFalse();
269272
});
270273
});
271274
});
@@ -284,7 +287,8 @@ describe('GroupsRegistryComponent', () => {
284287
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
285288
expect(editButtonsFound.length).toEqual(2);
286289
editButtonsFound.forEach((editButtonFound) => {
287-
expect(editButtonFound.nativeElement.disabled).toBeTrue();
290+
expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBe('true');
291+
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeTrue();
288292
});
289293
});
290294
});

src/app/collection-page/edit-collection-page/collection-source/collection-source-controls/collection-source-controls.component.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { TestScheduler } from 'rxjs/testing';
2222
import { By } from '@angular/platform-browser';
2323
import { VarDirective } from '../../../../shared/utils/var.directive';
2424
import { ContentSourceSetSerializer } from '../../../../core/shared/content-source-set-serializer';
25+
import {DisabledDirective} from '../../../../shared/disabled-directive';
2526

2627
describe('CollectionSourceControlsComponent', () => {
2728
let comp: CollectionSourceControlsComponent;
@@ -100,7 +101,7 @@ describe('CollectionSourceControlsComponent', () => {
100101

101102
TestBed.configureTestingModule({
102103
imports: [TranslateModule.forRoot(), RouterTestingModule],
103-
declarations: [CollectionSourceControlsComponent, VarDirective],
104+
declarations: [CollectionSourceControlsComponent, VarDirective, DisabledDirective],
104105
providers: [
105106
{provide: ScriptDataService, useValue: scriptDataService},
106107
{provide: ProcessDataService, useValue: processDataService},
@@ -189,9 +190,11 @@ describe('CollectionSourceControlsComponent', () => {
189190

190191
const buttons = fixture.debugElement.queryAll(By.css('button'));
191192

192-
expect(buttons[0].nativeElement.disabled).toBeTrue();
193-
expect(buttons[1].nativeElement.disabled).toBeTrue();
194-
expect(buttons[2].nativeElement.disabled).toBeTrue();
193+
buttons.forEach(button => {
194+
console.log(button.nativeElement);
195+
expect(button.nativeElement.getAttribute('aria-disabled')).toBe('true');
196+
expect(button.nativeElement.classList.contains('disabled')).toBeTrue();
197+
});
195198
});
196199
it('should be enabled when isEnabled is true', () => {
197200
comp.shouldShow = true;
@@ -201,9 +204,10 @@ describe('CollectionSourceControlsComponent', () => {
201204

202205
const buttons = fixture.debugElement.queryAll(By.css('button'));
203206

204-
expect(buttons[0].nativeElement.disabled).toBeFalse();
205-
expect(buttons[1].nativeElement.disabled).toBeFalse();
206-
expect(buttons[2].nativeElement.disabled).toBeFalse();
207+
buttons.forEach(button => {
208+
expect(button.nativeElement.getAttribute('aria-disabled')).toBe('false');
209+
expect(button.nativeElement.classList.contains('disabled')).toBeFalse();
210+
});
207211
});
208212
it('should call the corresponding button when clicked', () => {
209213
spyOn(comp, 'testConfiguration');

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ItemMetadataRepresentation } from '../../../core/shared/metadata-repres
1111
import { MetadataValue, VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models';
1212
import { DsoEditMetadataChangeType, DsoEditMetadataValue } from '../dso-edit-metadata-form';
1313
import { By } from '@angular/platform-browser';
14+
import {DisabledDirective} from '../../../shared/disabled-directive';
1415

1516
const EDIT_BTN = 'edit';
1617
const CONFIRM_BTN = 'confirm';
@@ -49,7 +50,7 @@ describe('DsoEditMetadataValueComponent', () => {
4950
initServices();
5051

5152
TestBed.configureTestingModule({
52-
declarations: [DsoEditMetadataValueComponent, VarDirective],
53+
declarations: [DsoEditMetadataValueComponent, VarDirective, DisabledDirective],
5354
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
5455
providers: [
5556
{ provide: RelationshipDataService, useValue: relationshipService },
@@ -158,7 +159,14 @@ describe('DsoEditMetadataValueComponent', () => {
158159
});
159160

160161
it(`should${disabled ? ' ' : ' not '}be disabled`, () => {
161-
expect(btn.nativeElement.disabled).toBe(disabled);
162+
if (disabled) {
163+
expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
164+
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
165+
} else {
166+
// Can be null or false, depending on if button was ever disabled so just check not true
167+
expect(btn.nativeElement.getAttribute('aria-disabled')).not.toBe('true');
168+
expect(btn.nativeElement.classList.contains('disabled')).toBeFalse();
169+
}
162170
});
163171
} else {
164172
it('should not exist', () => {

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata.component.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { DATA_SERVICE_FACTORY } from '../../core/data/base/data-service.decorato
1616
import { Operation } from 'fast-json-patch';
1717
import { RemoteData } from '../../core/data/remote-data';
1818
import { Observable } from 'rxjs/internal/Observable';
19+
import {DisabledDirective} from '../../shared/disabled-directive';
1920

2021
const ADD_BTN = 'add';
2122
const REINSTATE_BTN = 'reinstate';
@@ -71,7 +72,7 @@ describe('DsoEditMetadataComponent', () => {
7172
notificationsService = jasmine.createSpyObj('notificationsService', ['error', 'success']);
7273

7374
TestBed.configureTestingModule({
74-
declarations: [DsoEditMetadataComponent, VarDirective],
75+
declarations: [DsoEditMetadataComponent, VarDirective, DisabledDirective],
7576
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
7677
providers: [
7778
TestDataService,
@@ -180,7 +181,13 @@ describe('DsoEditMetadataComponent', () => {
180181
});
181182

182183
it(`should${disabled ? ' ' : ' not '}be disabled`, () => {
183-
expect(btn.nativeElement.disabled).toBe(disabled);
184+
if (disabled) {
185+
expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
186+
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
187+
} else {
188+
expect(btn.nativeElement.getAttribute('aria-disabled')).not.toBe('true');
189+
expect(btn.nativeElement.classList.contains('disabled')).toBeFalse();
190+
}
184191
});
185192
} else {
186193
it('should not exist', () => {

src/app/info/end-user-agreement/end-user-agreement.component.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Store } from '@ngrx/store';
1111
import { By } from '@angular/platform-browser';
1212
import { LogOutAction } from '../../core/auth/auth.actions';
1313
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
14+
import {DisabledDirective} from '../../shared/disabled-directive';
1415

1516
describe('EndUserAgreementComponent', () => {
1617
let component: EndUserAgreementComponent;
@@ -49,7 +50,7 @@ describe('EndUserAgreementComponent', () => {
4950
init();
5051
TestBed.configureTestingModule({
5152
imports: [TranslateModule.forRoot()],
52-
declarations: [EndUserAgreementComponent],
53+
declarations: [EndUserAgreementComponent, DisabledDirective],
5354
providers: [
5455
{ provide: EndUserAgreementService, useValue: endUserAgreementService },
5556
{ provide: NotificationsService, useValue: notificationsService },
@@ -81,7 +82,8 @@ describe('EndUserAgreementComponent', () => {
8182

8283
it('should disable the save button', () => {
8384
const button = fixture.debugElement.query(By.css('#button-save')).nativeElement;
84-
expect(button.disabled).toBeTruthy();
85+
expect(button.getAttribute('aria-disabled')).toBe('true');
86+
expect(button.classList.contains('disabled')).toBeTrue();
8587
});
8688
});
8789

src/app/info/feedback/feedback-form/feedback-form.component.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Router } from '@angular/router';
1818
import { RouterMock } from '../../../shared/mocks/router.mock';
1919
import { NativeWindowService } from '../../../core/services/window.service';
2020
import { NativeWindowMockFactory } from '../../../shared/mocks/mock-native-window-ref';
21+
import {DisabledDirective} from '../../../shared/disabled-directive';
2122

2223

2324
describe('FeedbackFormComponent', () => {
@@ -38,7 +39,7 @@ describe('FeedbackFormComponent', () => {
3839
beforeEach(waitForAsync(() => {
3940
TestBed.configureTestingModule({
4041
imports: [TranslateModule.forRoot()],
41-
declarations: [FeedbackFormComponent],
42+
declarations: [FeedbackFormComponent, DisabledDirective],
4243
providers: [
4344
{ provide: RouteService, useValue: routeServiceStub },
4445
{ provide: UntypedFormBuilder, useValue: new UntypedFormBuilder() },
@@ -72,7 +73,8 @@ describe('FeedbackFormComponent', () => {
7273
});
7374

7475
it('should have disabled button', () => {
75-
expect(de.query(By.css('button')).nativeElement.disabled).toBeTrue();
76+
expect(de.query(By.css('button')).nativeElement.getAttribute('aria-disabled')).toBe('true');
77+
expect(de.query(By.css('button')).nativeElement.classList.contains('disabled')).toBeTrue();
7678
});
7779

7880
describe('when message is inserted', () => {
@@ -83,7 +85,8 @@ describe('FeedbackFormComponent', () => {
8385
});
8486

8587
it('should not have disabled button', () => {
86-
expect(de.query(By.css('button')).nativeElement.disabled).toBeFalse();
88+
expect(de.query(By.css('button')).nativeElement.getAttribute('aria-disabled')).toBe('false');
89+
expect(de.query(By.css('button')).nativeElement.classList.contains('disabled')).toBeFalse();
8790
});
8891

8992
it('on submit should call createFeedback of feedbackDataServiceStub service', () => {

src/app/item-page/edit-item-page/item-operation/item-operation.component.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ItemOperationComponent } from './item-operation.component';
44
import { TranslateModule } from '@ngx-translate/core';
55
import { By } from '@angular/platform-browser';
66
import { RouterTestingModule } from '@angular/router/testing';
7+
import {DisabledDirective} from '../../../shared/disabled-directive';
78

89
describe('ItemOperationComponent', () => {
910
let itemOperation: ItemOperation;
@@ -14,7 +15,7 @@ describe('ItemOperationComponent', () => {
1415
beforeEach(waitForAsync(() => {
1516
TestBed.configureTestingModule({
1617
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
17-
declarations: [ItemOperationComponent]
18+
declarations: [ItemOperationComponent, DisabledDirective]
1819
}).compileComponents();
1920
}));
2021

@@ -40,7 +41,8 @@ describe('ItemOperationComponent', () => {
4041
const span = fixture.debugElement.query(By.css('.action-label span')).nativeElement;
4142
expect(span.textContent).toContain('item.edit.tabs.status.buttons.key1.label');
4243
const button = fixture.debugElement.query(By.css('button')).nativeElement;
43-
expect(button.disabled).toBeTrue();
44+
expect(button.getAttribute('aria-disabled')).toBe('true');
45+
expect(button.classList.contains('disabled')).toBeTrue();
4446
expect(button.textContent).toContain('item.edit.tabs.status.buttons.key1.button');
4547
});
4648
});

src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ describe('EditRelationshipListComponent', () => {
335335
comp.hasChanges = observableOf(true);
336336
fixture.detectChanges();
337337
const element = de.query(By.css('.btn-success'));
338-
expect(element.nativeElement?.disabled).toBeTrue();
338+
expect(element.nativeElement?.getAttribute('aria-disabled')).toBe('true');
339+
expect(element.nativeElement?.classList.contains('disabled')).toBeTrue();
339340
});
340341
});
341342

0 commit comments

Comments
 (0)