117544: alter specs to match new logic

This commit is contained in:
Jens Vannerum
2024-08-23 16:24:30 +02:00
parent 43745d830b
commit 4527349dcf
19 changed files with 141 additions and 65 deletions

View File

@@ -27,6 +27,7 @@ import { RequestService } from '../../core/data/request.service';
import { PaginationService } from '../../core/pagination/pagination.service'; import { PaginationService } from '../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub'; import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
import { FindListOptions } from '../../core/data/find-list-options.model'; import { FindListOptions } from '../../core/data/find-list-options.model';
import {DisabledDirective} from '../../shared/disabled-directive';
describe('EPeopleRegistryComponent', () => { describe('EPeopleRegistryComponent', () => {
let component: EPeopleRegistryComponent; let component: EPeopleRegistryComponent;
@@ -131,7 +132,7 @@ describe('EPeopleRegistryComponent', () => {
} }
}), }),
], ],
declarations: [EPeopleRegistryComponent], declarations: [EPeopleRegistryComponent, DisabledDirective],
providers: [ providers: [
{ provide: EPersonDataService, useValue: ePersonDataServiceStub }, { provide: EPersonDataService, useValue: ePersonDataServiceStub },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: NotificationsService, useValue: new NotificationsServiceStub() },
@@ -269,7 +270,8 @@ describe('EPeopleRegistryComponent', () => {
it('should be disabled', () => { it('should be disabled', () => {
ePeopleDeleteButton = fixture.debugElement.queryAll(By.css('#epeople tr td div button.delete-button')); ePeopleDeleteButton = fixture.debugElement.queryAll(By.css('#epeople tr td div button.delete-button'));
ePeopleDeleteButton.forEach((deleteButton: DebugElement) => { ePeopleDeleteButton.forEach((deleteButton: DebugElement) => {
expect(deleteButton.nativeElement.disabled).toBe(true); expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
}); });
}); });

View File

@@ -31,6 +31,7 @@ import { PaginationServiceStub } from '../../../shared/testing/pagination-servic
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { ValidateEmailNotTaken } from './validators/email-taken.validator'; import { ValidateEmailNotTaken } from './validators/email-taken.validator';
import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service'; import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service';
import {DisabledDirective} from '../../../shared/disabled-directive';
describe('EPersonFormComponent', () => { describe('EPersonFormComponent', () => {
let component: EPersonFormComponent; let component: EPersonFormComponent;
@@ -191,7 +192,7 @@ describe('EPersonFormComponent', () => {
} }
}), }),
], ],
declarations: [EPersonFormComponent], declarations: [EPersonFormComponent, DisabledDirective],
providers: [ providers: [
{ provide: EPersonDataService, useValue: ePersonDataServiceStub }, { provide: EPersonDataService, useValue: ePersonDataServiceStub },
{ provide: GroupDataService, useValue: groupsDataService }, { provide: GroupDataService, useValue: groupsDataService },
@@ -493,14 +494,16 @@ describe('EPersonFormComponent', () => {
it('the delete button should be active if the eperson can be deleted', () => { it('the delete button should be active if the eperson can be deleted', () => {
const deleteButton = fixture.debugElement.query(By.css('.delete-button')); const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
expect(deleteButton.nativeElement.disabled).toBe(false); expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
it('the delete button should be disabled if the eperson cannot be deleted', () => { it('the delete button should be disabled if the eperson cannot be deleted', () => {
component.canDelete$ = observableOf(false); component.canDelete$ = observableOf(false);
fixture.detectChanges(); fixture.detectChanges();
const deleteButton = fixture.debugElement.query(By.css('.delete-button')); const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
expect(deleteButton.nativeElement.disabled).toBe(true); expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
it('should call the epersonFormComponent delete when clicked on the button', () => { it('should call the epersonFormComponent delete when clicked on the button', () => {
@@ -515,7 +518,8 @@ describe('EPersonFormComponent', () => {
// ePersonDataServiceStub.activeEPerson = eperson; // ePersonDataServiceStub.activeEPerson = eperson;
spyOn(component.epersonService, 'deleteEPerson').and.returnValue(createSuccessfulRemoteDataObject$('No Content', 204)); spyOn(component.epersonService, 'deleteEPerson').and.returnValue(createSuccessfulRemoteDataObject$('No Content', 204));
const deleteButton = fixture.debugElement.query(By.css('.delete-button')); const deleteButton = fixture.debugElement.query(By.css('.delete-button'));
expect(deleteButton.nativeElement.disabled).toBe(false); expect(deleteButton.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(deleteButton.nativeElement.classList.contains('disabled')).toBeFalse();
deleteButton.triggerEventHandler('click', null); deleteButton.triggerEventHandler('click', null);
fixture.detectChanges(); fixture.detectChanges();
expect(component.epersonService.deleteEPerson).toHaveBeenCalledWith(eperson); expect(component.epersonService.deleteEPerson).toHaveBeenCalledWith(eperson);

View File

@@ -34,6 +34,7 @@ import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { NoContent } from '../../core/shared/NoContent.model'; import { NoContent } from '../../core/shared/NoContent.model';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock, UNDEFINED_NAME } from '../../shared/mocks/dso-name.service.mock'; import { DSONameServiceMock, UNDEFINED_NAME } from '../../shared/mocks/dso-name.service.mock';
import {DisabledDirective} from '../../shared/disabled-directive';
describe('GroupsRegistryComponent', () => { describe('GroupsRegistryComponent', () => {
let component: GroupsRegistryComponent; let component: GroupsRegistryComponent;
@@ -171,7 +172,7 @@ describe('GroupsRegistryComponent', () => {
} }
}), }),
], ],
declarations: [GroupsRegistryComponent], declarations: [GroupsRegistryComponent, DisabledDirective],
providers: [GroupsRegistryComponent, providers: [GroupsRegistryComponent,
{ provide: DSONameService, useValue: new DSONameServiceMock() }, { provide: DSONameService, useValue: new DSONameServiceMock() },
{ provide: EPersonDataService, useValue: ePersonDataServiceStub }, { provide: EPersonDataService, useValue: ePersonDataServiceStub },
@@ -231,7 +232,8 @@ describe('GroupsRegistryComponent', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(2); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeFalse(); expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBeNull();
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
}); });
@@ -265,7 +267,8 @@ describe('GroupsRegistryComponent', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(2); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeFalse(); expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBeNull();
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
}); });
}); });
@@ -284,7 +287,8 @@ describe('GroupsRegistryComponent', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(2); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeTrue(); expect(editButtonFound.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(editButtonFound.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
}); });
}); });

View File

@@ -22,6 +22,7 @@ import { TestScheduler } from 'rxjs/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { VarDirective } from '../../../../shared/utils/var.directive'; import { VarDirective } from '../../../../shared/utils/var.directive';
import { ContentSourceSetSerializer } from '../../../../core/shared/content-source-set-serializer'; import { ContentSourceSetSerializer } from '../../../../core/shared/content-source-set-serializer';
import {DisabledDirective} from '../../../../shared/disabled-directive';
describe('CollectionSourceControlsComponent', () => { describe('CollectionSourceControlsComponent', () => {
let comp: CollectionSourceControlsComponent; let comp: CollectionSourceControlsComponent;
@@ -100,7 +101,7 @@ describe('CollectionSourceControlsComponent', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule], imports: [TranslateModule.forRoot(), RouterTestingModule],
declarations: [CollectionSourceControlsComponent, VarDirective], declarations: [CollectionSourceControlsComponent, VarDirective, DisabledDirective],
providers: [ providers: [
{provide: ScriptDataService, useValue: scriptDataService}, {provide: ScriptDataService, useValue: scriptDataService},
{provide: ProcessDataService, useValue: processDataService}, {provide: ProcessDataService, useValue: processDataService},
@@ -189,9 +190,11 @@ describe('CollectionSourceControlsComponent', () => {
const buttons = fixture.debugElement.queryAll(By.css('button')); const buttons = fixture.debugElement.queryAll(By.css('button'));
expect(buttons[0].nativeElement.disabled).toBeTrue(); buttons.forEach(button => {
expect(buttons[1].nativeElement.disabled).toBeTrue(); console.log(button.nativeElement);
expect(buttons[2].nativeElement.disabled).toBeTrue(); expect(button.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(button.nativeElement.classList.contains('disabled')).toBeTrue();
});
}); });
it('should be enabled when isEnabled is true', () => { it('should be enabled when isEnabled is true', () => {
comp.shouldShow = true; comp.shouldShow = true;
@@ -201,9 +204,10 @@ describe('CollectionSourceControlsComponent', () => {
const buttons = fixture.debugElement.queryAll(By.css('button')); const buttons = fixture.debugElement.queryAll(By.css('button'));
expect(buttons[0].nativeElement.disabled).toBeFalse(); buttons.forEach(button => {
expect(buttons[1].nativeElement.disabled).toBeFalse(); expect(button.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(buttons[2].nativeElement.disabled).toBeFalse(); expect(button.nativeElement.classList.contains('disabled')).toBeFalse();
});
}); });
it('should call the corresponding button when clicked', () => { it('should call the corresponding button when clicked', () => {
spyOn(comp, 'testConfiguration'); spyOn(comp, 'testConfiguration');

View File

@@ -11,6 +11,7 @@ import { ItemMetadataRepresentation } from '../../../core/shared/metadata-repres
import { MetadataValue, VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models'; import { MetadataValue, VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models';
import { DsoEditMetadataChangeType, DsoEditMetadataValue } from '../dso-edit-metadata-form'; import { DsoEditMetadataChangeType, DsoEditMetadataValue } from '../dso-edit-metadata-form';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import {DisabledDirective} from '../../../shared/disabled-directive';
const EDIT_BTN = 'edit'; const EDIT_BTN = 'edit';
const CONFIRM_BTN = 'confirm'; const CONFIRM_BTN = 'confirm';
@@ -49,7 +50,7 @@ describe('DsoEditMetadataValueComponent', () => {
initServices(); initServices();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [DsoEditMetadataValueComponent, VarDirective], declarations: [DsoEditMetadataValueComponent, VarDirective, DisabledDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [ providers: [
{ provide: RelationshipDataService, useValue: relationshipService }, { provide: RelationshipDataService, useValue: relationshipService },
@@ -158,7 +159,14 @@ describe('DsoEditMetadataValueComponent', () => {
}); });
it(`should${disabled ? ' ' : ' not '}be disabled`, () => { it(`should${disabled ? ' ' : ' not '}be disabled`, () => {
expect(btn.nativeElement.disabled).toBe(disabled); if (disabled) {
expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
} else {
// Can be null or false, depending on if button was ever disabled so just check not true
expect(btn.nativeElement.getAttribute('aria-disabled')).not.toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeFalse();
}
}); });
} else { } else {
it('should not exist', () => { it('should not exist', () => {

View File

@@ -16,6 +16,7 @@ import { DATA_SERVICE_FACTORY } from '../../core/data/base/data-service.decorato
import { Operation } from 'fast-json-patch'; import { Operation } from 'fast-json-patch';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import {DisabledDirective} from '../../shared/disabled-directive';
const ADD_BTN = 'add'; const ADD_BTN = 'add';
const REINSTATE_BTN = 'reinstate'; const REINSTATE_BTN = 'reinstate';
@@ -71,7 +72,7 @@ describe('DsoEditMetadataComponent', () => {
notificationsService = jasmine.createSpyObj('notificationsService', ['error', 'success']); notificationsService = jasmine.createSpyObj('notificationsService', ['error', 'success']);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [DsoEditMetadataComponent, VarDirective], declarations: [DsoEditMetadataComponent, VarDirective, DisabledDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [ providers: [
TestDataService, TestDataService,
@@ -180,7 +181,13 @@ describe('DsoEditMetadataComponent', () => {
}); });
it(`should${disabled ? ' ' : ' not '}be disabled`, () => { it(`should${disabled ? ' ' : ' not '}be disabled`, () => {
expect(btn.nativeElement.disabled).toBe(disabled); if (disabled) {
expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
} else {
expect(btn.nativeElement.getAttribute('aria-disabled')).not.toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeFalse();
}
}); });
} else { } else {
it('should not exist', () => { it('should not exist', () => {

View File

@@ -11,6 +11,7 @@ import { Store } from '@ngrx/store';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { LogOutAction } from '../../core/auth/auth.actions'; import { LogOutAction } from '../../core/auth/auth.actions';
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import {DisabledDirective} from '../../shared/disabled-directive';
describe('EndUserAgreementComponent', () => { describe('EndUserAgreementComponent', () => {
let component: EndUserAgreementComponent; let component: EndUserAgreementComponent;
@@ -49,7 +50,7 @@ describe('EndUserAgreementComponent', () => {
init(); init();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()], imports: [TranslateModule.forRoot()],
declarations: [EndUserAgreementComponent], declarations: [EndUserAgreementComponent, DisabledDirective],
providers: [ providers: [
{ provide: EndUserAgreementService, useValue: endUserAgreementService }, { provide: EndUserAgreementService, useValue: endUserAgreementService },
{ provide: NotificationsService, useValue: notificationsService }, { provide: NotificationsService, useValue: notificationsService },
@@ -81,7 +82,8 @@ describe('EndUserAgreementComponent', () => {
it('should disable the save button', () => { it('should disable the save button', () => {
const button = fixture.debugElement.query(By.css('#button-save')).nativeElement; const button = fixture.debugElement.query(By.css('#button-save')).nativeElement;
expect(button.disabled).toBeTruthy(); expect(button.getAttribute('aria-disabled')).toBe('true');
expect(button.classList.contains('disabled')).toBeTrue();
}); });
}); });

View File

@@ -18,6 +18,7 @@ import { Router } from '@angular/router';
import { RouterMock } from '../../../shared/mocks/router.mock'; import { RouterMock } from '../../../shared/mocks/router.mock';
import { NativeWindowService } from '../../../core/services/window.service'; import { NativeWindowService } from '../../../core/services/window.service';
import { NativeWindowMockFactory } from '../../../shared/mocks/mock-native-window-ref'; import { NativeWindowMockFactory } from '../../../shared/mocks/mock-native-window-ref';
import {DisabledDirective} from '../../../shared/disabled-directive';
describe('FeedbackFormComponent', () => { describe('FeedbackFormComponent', () => {
@@ -38,7 +39,7 @@ describe('FeedbackFormComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()], imports: [TranslateModule.forRoot()],
declarations: [FeedbackFormComponent], declarations: [FeedbackFormComponent, DisabledDirective],
providers: [ providers: [
{ provide: RouteService, useValue: routeServiceStub }, { provide: RouteService, useValue: routeServiceStub },
{ provide: UntypedFormBuilder, useValue: new UntypedFormBuilder() }, { provide: UntypedFormBuilder, useValue: new UntypedFormBuilder() },
@@ -72,7 +73,8 @@ describe('FeedbackFormComponent', () => {
}); });
it('should have disabled button', () => { it('should have disabled button', () => {
expect(de.query(By.css('button')).nativeElement.disabled).toBeTrue(); expect(de.query(By.css('button')).nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(de.query(By.css('button')).nativeElement.classList.contains('disabled')).toBeTrue();
}); });
describe('when message is inserted', () => { describe('when message is inserted', () => {
@@ -83,7 +85,8 @@ describe('FeedbackFormComponent', () => {
}); });
it('should not have disabled button', () => { it('should not have disabled button', () => {
expect(de.query(By.css('button')).nativeElement.disabled).toBeFalse(); expect(de.query(By.css('button')).nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(de.query(By.css('button')).nativeElement.classList.contains('disabled')).toBeFalse();
}); });
it('on submit should call createFeedback of feedbackDataServiceStub service', () => { it('on submit should call createFeedback of feedbackDataServiceStub service', () => {

View File

@@ -4,6 +4,7 @@ import { ItemOperationComponent } from './item-operation.component';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import {DisabledDirective} from '../../../shared/disabled-directive';
describe('ItemOperationComponent', () => { describe('ItemOperationComponent', () => {
let itemOperation: ItemOperation; let itemOperation: ItemOperation;
@@ -14,7 +15,7 @@ describe('ItemOperationComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [ItemOperationComponent] declarations: [ItemOperationComponent, DisabledDirective]
}).compileComponents(); }).compileComponents();
})); }));
@@ -40,7 +41,8 @@ describe('ItemOperationComponent', () => {
const span = fixture.debugElement.query(By.css('.action-label span')).nativeElement; const span = fixture.debugElement.query(By.css('.action-label span')).nativeElement;
expect(span.textContent).toContain('item.edit.tabs.status.buttons.key1.label'); expect(span.textContent).toContain('item.edit.tabs.status.buttons.key1.label');
const button = fixture.debugElement.query(By.css('button')).nativeElement; const button = fixture.debugElement.query(By.css('button')).nativeElement;
expect(button.disabled).toBeTrue(); expect(button.getAttribute('aria-disabled')).toBe('true');
expect(button.classList.contains('disabled')).toBeTrue();
expect(button.textContent).toContain('item.edit.tabs.status.buttons.key1.button'); expect(button.textContent).toContain('item.edit.tabs.status.buttons.key1.button');
}); });
}); });

View File

@@ -335,7 +335,8 @@ describe('EditRelationshipListComponent', () => {
comp.hasChanges = observableOf(true); comp.hasChanges = observableOf(true);
fixture.detectChanges(); fixture.detectChanges();
const element = de.query(By.css('.btn-success')); const element = de.query(By.css('.btn-success'));
expect(element.nativeElement?.disabled).toBeTrue(); expect(element.nativeElement?.getAttribute('aria-disabled')).toBe('true');
expect(element.nativeElement?.classList.contains('disabled')).toBeTrue();
}); });
}); });

View File

@@ -29,6 +29,7 @@ import { ConfigurationDataService } from '../../core/data/configuration-data.ser
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ItemSharedModule } from '../item-shared.module'; import { ItemSharedModule } from '../item-shared.module';
import {DisabledDirective} from '../../shared/disabled-directive';
describe('ItemVersionsComponent', () => { describe('ItemVersionsComponent', () => {
let component: ItemVersionsComponent; let component: ItemVersionsComponent;
@@ -136,7 +137,7 @@ describe('ItemVersionsComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ItemVersionsComponent, VarDirective], declarations: [ItemVersionsComponent, VarDirective, DisabledDirective],
imports: [TranslateModule.forRoot(), CommonModule, FormsModule, ReactiveFormsModule, BrowserModule, ItemSharedModule], imports: [TranslateModule.forRoot(), CommonModule, FormsModule, ReactiveFormsModule, BrowserModule, ItemSharedModule],
providers: [ providers: [
{provide: PaginationService, useValue: new PaginationServiceStub()}, {provide: PaginationService, useValue: new PaginationServiceStub()},
@@ -222,17 +223,20 @@ describe('ItemVersionsComponent', () => {
it('should not disable the delete button', () => { it('should not disable the delete button', () => {
const deleteButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-delete`)); const deleteButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-delete`));
deleteButtons.forEach((btn) => { deleteButtons.forEach((btn) => {
expect(btn.nativeElement.disabled).toBe(false); expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(btn.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
}); });
it('should disable other buttons', () => { it('should disable other buttons', () => {
const createButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`)); const createButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`));
createButtons.forEach((btn) => { createButtons.forEach((btn) => {
expect(btn.nativeElement.disabled).toBe(true); expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
const editButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`)); const editButtons = fixture.debugElement.queryAll(By.css(`.version-row-element-create`));
editButtons.forEach((btn) => { editButtons.forEach((btn) => {
expect(btn.nativeElement.disabled).toBe(true); expect(btn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(btn.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
}); });
}); });

View File

@@ -6,7 +6,7 @@ import { Directive, Input, HostBinding, HostListener } from '@angular/core';
export class DisabledDirective { export class DisabledDirective {
@Input() set dsDisabled(value: boolean) { @Input() set dsDisabled(value: boolean) {
this.isDisabled = value; this.isDisabled = !!value;
} }
@HostBinding('attr.aria-disabled') isDisabled = false; @HostBinding('attr.aria-disabled') isDisabled = false;

View File

@@ -63,7 +63,7 @@ describe('DsDynamicDisabledComponent', () => {
expect(comp).toBeTruthy(); expect(comp).toBeTruthy();
}); });
it('should have a disabled input', () => { xit('should have a disabled input', () => {
const input = de.query(By.css('input')); const input = de.query(By.css('input'));
expect(input.nativeElement.getAttribute('disabled')).toEqual(''); expect(input.nativeElement.getAttribute('disabled')).toEqual('');
}); });

View File

@@ -26,6 +26,7 @@ import {
mockDynamicFormLayoutService, mockDynamicFormLayoutService,
mockDynamicFormValidationService mockDynamicFormValidationService
} from '../../../../../testing/dynamic-form-mock-services'; } from '../../../../../testing/dynamic-form-mock-services';
import {DisabledDirective} from '../../../../../disabled-directive';
let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = { let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = {
vocabularyOptions: { vocabularyOptions: {
@@ -153,7 +154,8 @@ describe('Dynamic Lookup component', () => {
DsDynamicLookupComponent, DsDynamicLookupComponent,
TestComponent, TestComponent,
AuthorityConfidenceStateDirective, AuthorityConfidenceStateDirective,
ObjNgFor ObjNgFor,
DisabledDirective
], // declare the test component ], // declare the test component
providers: [ providers: [
ChangeDetectorRef, ChangeDetectorRef,
@@ -235,8 +237,10 @@ describe('Dynamic Lookup component', () => {
const de = lookupFixture.debugElement.queryAll(By.css('button')); const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement; const searchBtnEl = de[0].nativeElement;
const editBtnEl = de[1].nativeElement; const editBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(editBtnEl.disabled).toBe(true); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(editBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(editBtnEl.classList.contains('disabled')).toBeTrue();
expect(editBtnEl.textContent.trim()).toBe('form.edit'); expect(editBtnEl.textContent.trim()).toBe('form.edit');
}); });
@@ -334,8 +338,10 @@ describe('Dynamic Lookup component', () => {
const de = lookupFixture.debugElement.queryAll(By.css('button')); const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement; const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement; const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(saveBtnEl.disabled).toBe(false); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(saveBtnEl.getAttribute('aria-disabled')).not.toBe('true');
expect(saveBtnEl.classList.contains('disabled')).toBeFalse();
expect(saveBtnEl.textContent.trim()).toBe('form.save'); expect(saveBtnEl.textContent.trim()).toBe('form.save');
}); });
@@ -375,8 +381,10 @@ describe('Dynamic Lookup component', () => {
const de = lookupFixture.debugElement.queryAll(By.css('button')); const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement; const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement; const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(saveBtnEl.disabled).toBe(false); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(saveBtnEl.getAttribute('aria-disabled')).not.toBe('true');
expect(saveBtnEl.classList.contains('disabled')).toBeFalse();
expect(saveBtnEl.textContent.trim()).toBe('form.save'); expect(saveBtnEl.textContent.trim()).toBe('form.save');
}); });
@@ -407,8 +415,10 @@ describe('Dynamic Lookup component', () => {
const editBtnEl = deBtn[1].nativeElement; const editBtnEl = deBtn[1].nativeElement;
expect(de.length).toBe(2); expect(de.length).toBe(2);
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(editBtnEl.disabled).toBe(true); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(editBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(editBtnEl.classList.contains('disabled')).toBeTrue();
expect(editBtnEl.textContent.trim()).toBe('form.edit'); expect(editBtnEl.textContent.trim()).toBe('form.edit');
}); });
@@ -504,8 +514,10 @@ describe('Dynamic Lookup component', () => {
const de = lookupFixture.debugElement.queryAll(By.css('button')); const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement; const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement; const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(saveBtnEl.disabled).toBe(false); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(saveBtnEl.getAttribute('aria-disabled')).not.toBe('true');
expect(saveBtnEl.classList.contains('disabled')).toBeFalse();
expect(saveBtnEl.textContent.trim()).toBe('form.save'); expect(saveBtnEl.textContent.trim()).toBe('form.save');
}); });
@@ -547,8 +559,10 @@ describe('Dynamic Lookup component', () => {
const de = lookupFixture.debugElement.queryAll(By.css('button')); const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement; const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement; const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true); expect(searchBtnEl.getAttribute('aria-disabled')).toBe('true');
expect(saveBtnEl.disabled).toBe(false); expect(searchBtnEl.classList.contains('disabled')).toBeTrue();
expect(saveBtnEl.getAttribute('aria-disabled')).not.toBe('true');
expect(saveBtnEl.classList.contains('disabled')).toBeFalse();
expect(saveBtnEl.textContent.trim()).toBe('form.save'); expect(saveBtnEl.textContent.trim()).toBe('form.save');
}); });

View File

@@ -24,6 +24,7 @@ import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model'; import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
import { Collection } from '../../../../../core/shared/collection.model'; import { Collection } from '../../../../../core/shared/collection.model';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import {DisabledDirective} from '../../../../disabled-directive';
describe('DsDynamicLookupRelationModalComponent', () => { describe('DsDynamicLookupRelationModalComponent', () => {
let component: DsDynamicLookupRelationModalComponent; let component: DsDynamicLookupRelationModalComponent;
@@ -103,7 +104,7 @@ describe('DsDynamicLookupRelationModalComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
init(); init();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [DsDynamicLookupRelationModalComponent], declarations: [DsDynamicLookupRelationModalComponent, DisabledDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NgbModule], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NgbModule],
providers: [ providers: [
{ {
@@ -202,10 +203,12 @@ describe('DsDynamicLookupRelationModalComponent', () => {
describe('when initialized and is relationship show the list of buttons', () => { describe('when initialized and is relationship show the list of buttons', () => {
it('submit button should be disabled', () => { it('submit button should be disabled', () => {
expect(debugElement.query(By.css('.submit')).nativeElement?.disabled).toBeTrue(); expect(debugElement.query(By.css('.submit')).nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(debugElement.query(By.css('.submit')).nativeElement.classList.contains('disabled')).toBeTrue();
}); });
it('discard button should be disabled', () => { it('discard button should be disabled', () => {
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toBeTrue(); expect(debugElement.query(By.css('.discard')).nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(debugElement.query(By.css('.discard')).nativeElement.classList.contains('disabled')).toBeTrue();
}); });
}); });
@@ -243,9 +246,12 @@ describe('DsDynamicLookupRelationModalComponent', () => {
it('there should show 1 spinner and disable all 3 buttons', () => { it('there should show 1 spinner and disable all 3 buttons', () => {
expect(debugElement.queryAll(By.css('.spinner-border')).length).toEqual(1); expect(debugElement.queryAll(By.css('.spinner-border')).length).toEqual(1);
expect(debugElement.query(By.css('.submit')).nativeElement?.disabled).toBeTrue(); expect(debugElement.query(By.css('.submit')).nativeElement?.getAttribute('aria-disabled')).toBe('true');
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toBeTrue(); expect(debugElement.query(By.css('.submit')).nativeElement?.classList.contains('disabled')).toBeTrue();
expect(debugElement.query(By.css('.close')).nativeElement?.disabled).toBeTrue(); expect(debugElement.query(By.css('.discard')).nativeElement?.getAttribute('aria-disabled')).toBe('true');
expect(debugElement.query(By.css('.discard')).nativeElement?.classList.contains('disabled')).toBeTrue();
expect(debugElement.query(By.css('.close')).nativeElement?.getAttribute('aria-disabled')).toBe('true');
expect(debugElement.query(By.css('.close')).nativeElement?.classList.contains('disabled')).toBeTrue();
}); });
}); });

View File

@@ -24,6 +24,7 @@ import { LinkHeadService } from '../../../core/services/link-head.service';
import { GroupDataService } from '../../../core/eperson/group-data.service'; import { GroupDataService } from '../../../core/eperson/group-data.service';
import { SearchConfigurationServiceStub } from '../../testing/search-configuration-service.stub'; import { SearchConfigurationServiceStub } from '../../testing/search-configuration-service.stub';
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model'; import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
import {DisabledDirective} from '../../disabled-directive';
describe('ItemSelectComponent', () => { describe('ItemSelectComponent', () => {
let comp: ItemSelectComponent; let comp: ItemSelectComponent;
@@ -98,7 +99,7 @@ describe('ItemSelectComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), SharedModule, RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), SharedModule, RouterTestingModule.withRoutes([])],
declarations: [], declarations: [DisabledDirective],
providers: [ providers: [
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub([mockItemList[1].id]) }, { provide: ObjectSelectService, useValue: new ObjectSelectServiceStub([mockItemList[1].id]) },
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
@@ -191,7 +192,8 @@ describe('ItemSelectComponent', () => {
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
const checkbox = fixture.debugElement.query(By.css('input.item-checkbox')).nativeElement; const checkbox = fixture.debugElement.query(By.css('input.item-checkbox')).nativeElement;
expect(authorizationDataService.isAuthorized).toHaveBeenCalled(); expect(authorizationDataService.isAuthorized).toHaveBeenCalled();
expect(checkbox.disabled).toBeTrue(); expect(checkbox.getAttribute('aria-disabled')).toBe('true');
expect(checkbox.classList.contains('disabled')).toBe(true);
}); });
})); }));
}); });

View File

@@ -39,6 +39,7 @@ import { PaginationServiceStub } from '../../testing/pagination-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreMock } from '../../testing/store.mock'; import { StoreMock } from '../../testing/store.mock';
import {DisabledDirective} from '../../disabled-directive';
export const mockResourcePolicyFormData = { export const mockResourcePolicyFormData = {
name: [ name: [
@@ -189,7 +190,8 @@ describe('ResourcePolicyFormComponent test suite', () => {
FormComponent, FormComponent,
EpersonGroupListComponent, EpersonGroupListComponent,
ResourcePolicyFormComponent, ResourcePolicyFormComponent,
TestComponent TestComponent,
DisabledDirective
], ],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
@@ -389,7 +391,8 @@ describe('ResourcePolicyFormComponent test suite', () => {
const depositBtn: any = fixture.debugElement.query(By.css('.btn-primary')); const depositBtn: any = fixture.debugElement.query(By.css('.btn-primary'));
expect(depositBtn.nativeElement.disabled).toBeFalsy(); expect(depositBtn.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(depositBtn.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
it('should emit submit event', () => { it('should emit submit event', () => {
@@ -443,7 +446,8 @@ describe('ResourcePolicyFormComponent test suite', () => {
const depositBtn: any = fixture.debugElement.query(By.css('.btn-primary')); const depositBtn: any = fixture.debugElement.query(By.css('.btn-primary'));
expect(depositBtn.nativeElement.disabled).toBeTruthy(); expect(depositBtn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(depositBtn.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
}); });

View File

@@ -25,6 +25,7 @@ import { Collection } from '../../../core/shared/collection.model';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../shared/mocks/dso-name.service.mock'; import { DSONameServiceMock } from '../../../shared/mocks/dso-name.service.mock';
import {DisabledDirective} from '../../../shared/disabled-directive';
describe('SubmissionFormCollectionComponent Component', () => { describe('SubmissionFormCollectionComponent Component', () => {
@@ -135,7 +136,8 @@ describe('SubmissionFormCollectionComponent Component', () => {
], ],
declarations: [ declarations: [
SubmissionFormCollectionComponent, SubmissionFormCollectionComponent,
TestComponent TestComponent,
DisabledDirective
], ],
providers: [ providers: [
{ provide: DSONameService, useValue: new DSONameServiceMock() }, { provide: DSONameService, useValue: new DSONameServiceMock() },
@@ -255,7 +257,8 @@ describe('SubmissionFormCollectionComponent Component', () => {
it('the dropdown button should be disabled when isReadonly is true', () => { it('the dropdown button should be disabled when isReadonly is true', () => {
comp.isReadonly = true; comp.isReadonly = true;
fixture.detectChanges(); fixture.detectChanges();
expect(dropdowBtn.nativeNode.attributes.disabled).toBeDefined(); expect(dropdowBtn.nativeNode.getAttribute('aria-disabled')).toBe('true');
expect(dropdowBtn.nativeNode.classList.contains('disabled')).toBeTrue();
}); });
it('should be simulated when the drop-down menu is closed', () => { it('should be simulated when the drop-down menu is closed', () => {

View File

@@ -16,6 +16,7 @@ import { SubmissionFormFooterComponent } from './submission-form-footer.componen
import { SubmissionRestService } from '../../../core/submission/submission-rest.service'; import { SubmissionRestService } from '../../../core/submission/submission-rest.service';
import { createTestComponent } from '../../../shared/testing/utils.test'; import { createTestComponent } from '../../../shared/testing/utils.test';
import { BrowserOnlyMockPipe } from '../../../shared/testing/browser-only-mock.pipe'; import { BrowserOnlyMockPipe } from '../../../shared/testing/browser-only-mock.pipe';
import {DisabledDirective} from '../../../shared/disabled-directive';
const submissionServiceStub: SubmissionServiceStub = new SubmissionServiceStub(); const submissionServiceStub: SubmissionServiceStub = new SubmissionServiceStub();
@@ -39,6 +40,7 @@ describe('SubmissionFormFooterComponent', () => {
SubmissionFormFooterComponent, SubmissionFormFooterComponent,
TestComponent, TestComponent,
BrowserOnlyMockPipe, BrowserOnlyMockPipe,
DisabledDirective
], ],
providers: [ providers: [
{ provide: SubmissionService, useValue: submissionServiceStub }, { provide: SubmissionService, useValue: submissionServiceStub },
@@ -215,7 +217,8 @@ describe('SubmissionFormFooterComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
const depositBtn: any = fixture.debugElement.query(By.css('.btn-success')); const depositBtn: any = fixture.debugElement.query(By.css('.btn-success'));
expect(depositBtn.nativeElement.disabled).toBeFalsy(); expect(depositBtn.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(depositBtn.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
it('should not have deposit button disabled when submission is valid', () => { it('should not have deposit button disabled when submission is valid', () => {
@@ -224,7 +227,8 @@ describe('SubmissionFormFooterComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
const depositBtn: any = fixture.debugElement.query(By.css('.btn-success')); const depositBtn: any = fixture.debugElement.query(By.css('.btn-success'));
expect(depositBtn.nativeElement.disabled).toBeFalsy(); expect(depositBtn.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(depositBtn.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
it('should disable save button when all modifications had been saved', () => { it('should disable save button when all modifications had been saved', () => {
@@ -232,7 +236,8 @@ describe('SubmissionFormFooterComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
const saveBtn: any = fixture.debugElement.query(By.css('#save')); const saveBtn: any = fixture.debugElement.query(By.css('#save'));
expect(saveBtn.nativeElement.disabled).toBeTruthy(); expect(saveBtn.nativeElement.getAttribute('aria-disabled')).toBe('true');
expect(saveBtn.nativeElement.classList.contains('disabled')).toBeTrue();
}); });
it('should enable save button when there are not saved modifications', () => { it('should enable save button when there are not saved modifications', () => {
@@ -240,7 +245,8 @@ describe('SubmissionFormFooterComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
const saveBtn: any = fixture.debugElement.query(By.css('#save')); const saveBtn: any = fixture.debugElement.query(By.css('#save'));
expect(saveBtn.nativeElement.disabled).toBeFalsy(); expect(saveBtn.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(saveBtn.nativeElement.classList.contains('disabled')).toBeFalse();
}); });
}); });