mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
[CST-7757] subscription modal tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
@@ -24,11 +24,11 @@ describe('SubscriptionModalComponent', () => {
|
|||||||
let de: DebugElement;
|
let de: DebugElement;
|
||||||
|
|
||||||
let subscriptionServiceStub;
|
let subscriptionServiceStub;
|
||||||
const notificationServiceStub = {
|
|
||||||
notificationWithAnchor() {
|
const notificationServiceStub = jasmine.createSpyObj('authService', {
|
||||||
return true;
|
notificationWithAnchor: true,
|
||||||
}
|
success: undefined,
|
||||||
};
|
});
|
||||||
|
|
||||||
const emptyPageInfo = Object.assign(new PageInfo(), {
|
const emptyPageInfo = Object.assign(new PageInfo(), {
|
||||||
'elementsPerPage': 0,
|
'elementsPerPage': 0,
|
||||||
@@ -101,6 +101,72 @@ describe('SubscriptionModalComponent', () => {
|
|||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('when submitting subscriptions', () => {
|
||||||
|
|
||||||
|
const testSubscriptionId = 'test-subscription-id';
|
||||||
|
const testTypes = ['test1', 'test2'];
|
||||||
|
const testFrequencies = ['f', 'g'];
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SubscriptionModalComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
component.dso = mockItem;
|
||||||
|
(component as any).subscriptionDefaultTypes = testTypes;
|
||||||
|
(component as any).frequencyDefaultValues = testFrequencies;
|
||||||
|
de = fixture.debugElement;
|
||||||
|
subscriptionServiceStub.createSubscription.calls.reset();
|
||||||
|
subscriptionServiceStub.updateSubscription.calls.reset();
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should edit an existing subscription', () => {
|
||||||
|
component.subscriptionForm = new FormGroup({});
|
||||||
|
for (let t of testTypes) {
|
||||||
|
const formGroup = new FormGroup({
|
||||||
|
subscriptionId: new FormControl(testSubscriptionId),
|
||||||
|
frequencies: new FormGroup({
|
||||||
|
f: new FormControl(false),
|
||||||
|
g: new FormControl(true),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
component.subscriptionForm.addControl(t, formGroup);
|
||||||
|
component.subscriptionForm.get('test1').markAsDirty();
|
||||||
|
component.subscriptionForm.get('test1').markAsTouched();
|
||||||
|
}
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.submit();
|
||||||
|
|
||||||
|
expect(subscriptionServiceStub.createSubscription).not.toHaveBeenCalled();
|
||||||
|
expect(subscriptionServiceStub.updateSubscription).toHaveBeenCalled();
|
||||||
|
expect(component.subscriptionForm.controls).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new subscription', () => {
|
||||||
|
component.subscriptionForm = new FormGroup({});
|
||||||
|
for (let t of testTypes) {
|
||||||
|
const formGroup = new FormGroup({
|
||||||
|
subscriptionId: new FormControl(undefined),
|
||||||
|
frequencies: new FormGroup({
|
||||||
|
f: new FormControl(false),
|
||||||
|
g: new FormControl(true),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
component.subscriptionForm.addControl(t, formGroup);
|
||||||
|
component.subscriptionForm.get('test1').markAsDirty();
|
||||||
|
component.subscriptionForm.get('test1').markAsTouched();
|
||||||
|
}
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.submit();
|
||||||
|
|
||||||
|
expect(subscriptionServiceStub.createSubscription).toHaveBeenCalled();
|
||||||
|
expect(subscriptionServiceStub.updateSubscription).not.toHaveBeenCalled();
|
||||||
|
expect(component.subscriptionForm.controls).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('when no subscription is given', () => {
|
describe('when no subscription is given', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(SubscriptionModalComponent);
|
fixture = TestBed.createComponent(SubscriptionModalComponent);
|
||||||
|
@@ -62,12 +62,12 @@ export class SubscriptionModalComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* Types of subscription to be shown on select
|
* Types of subscription to be shown on select
|
||||||
*/
|
*/
|
||||||
private subscriptionDefaultTypes = ['content'];
|
subscriptionDefaultTypes = ['content'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frequencies to be shown as checkboxes
|
* Frequencies to be shown as checkboxes
|
||||||
*/
|
*/
|
||||||
private frequencyDefaultValues = ['D', 'W', 'M'];
|
frequencyDefaultValues = ['D', 'W', 'M'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if form status has changed and at least one frequency is checked
|
* True if form status has changed and at least one frequency is checked
|
||||||
@@ -115,7 +115,7 @@ export class SubscriptionModalComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private initFormByAllSubscriptions(): void {
|
initFormByAllSubscriptions(): void {
|
||||||
this.subscriptionForm = new FormGroup({});
|
this.subscriptionForm = new FormGroup({});
|
||||||
for (let t of this.subscriptionDefaultTypes) {
|
for (let t of this.subscriptionDefaultTypes) {
|
||||||
const formGroup = new FormGroup({});
|
const formGroup = new FormGroup({});
|
||||||
|
Reference in New Issue
Block a user