Skip to content

Commit ad37415

Browse files
Merge pull request #28 from catenax-ng/fix/TRACEFOSS-1092-missing-validation
TRACEFOSS-1092: aligned validations in FE and BE
2 parents df2102b + d46bde1 commit ad37415

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

sonar-project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sonar.organization=eclipse-tractusx
55
sonar.sources=./src
66
sonar.tests=./src
77
sonar.exclusions=**/*.spec.ts, src/app/mocks/**/*, src/tests/**/*, src/mockServiceWorker.js, scripts/**/*, **/mocked.keycloak.service.ts, src/test.ts
8+
sonar.cpd.exclusions=**/*.spec.ts,src/app/mocks/**/*
89
sonar.test.inclusions=**/*.spec.ts
910
sonar.language=ts
1011

src/app/modules/shared/modules/notification/modal/accept/accept-notification-modal.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { NotificationStatus } from '@shared/model/notification.model';
2323
import { AcceptNotificationModalComponent } from '@shared/modules/notification/modal/accept/accept-notification-modal.component';
2424
import { renderAcceptModal } from '@shared/modules/notification/modal/modalTestHelper.spec';
2525
import { fireEvent, screen, waitFor } from '@testing-library/angular';
26+
import { getRandomText } from '../../../../../../mocks/services/text-generator.helper';
2627

2728
describe('AcceptNotificationModalComponent', () => {
2829
it('should create accept modal', async () => {
@@ -56,7 +57,17 @@ describe('AcceptNotificationModalComponent', () => {
5657
expect(errorMessage_1).toBeInTheDocument();
5758

5859
fireEvent.input(textArea, { target: { value: 'Some Text' } });
60+
const errorMessage_2 = await waitFor(() => screen.getByText('errorMessage.minLength'));
61+
expect(errorMessage_2).toBeInTheDocument();
62+
63+
fireEvent.input(textArea, { target: { value: getRandomText(1500) } });
64+
const errorMessage_3 = await waitFor(() => screen.getByText('errorMessage.maxLength'));
65+
expect(errorMessage_3).toBeInTheDocument();
66+
67+
fireEvent.input(textArea, { target: { value: 'Some longer text with at least 15 chars' } });
5968
expect(errorMessage_1).not.toBeInTheDocument();
69+
expect(errorMessage_2).not.toBeInTheDocument();
70+
expect(errorMessage_3).not.toBeInTheDocument();
6071
});
6172

6273
it('should call close function', async () => {

src/app/modules/shared/modules/notification/modal/accept/accept-notification-modal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class AcceptNotificationModalComponent {
4646

4747
public show(notification: Notification): void {
4848
this.notification = notification;
49-
this.textAreaControl.setValidators([Validators.required]);
49+
this.textAreaControl.setValidators([Validators.required, Validators.maxLength(1000), Validators.minLength(15)]);
5050

5151
const onConfirm = (isConfirmed: boolean) => {
5252
const reason = this.formGroup.get('reason').value;

src/app/modules/shared/modules/notification/modal/close/close-notification-modal.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { NotificationStatus } from '@shared/model/notification.model';
2323
import { CloseNotificationModalComponent } from '@shared/modules/notification/modal/close/close-notification-modal.component';
2424
import { renderCloseModal } from '@shared/modules/notification/modal/modalTestHelper.spec';
2525
import { fireEvent, screen, waitFor } from '@testing-library/angular';
26+
import { getRandomText } from '../../../../../../mocks/services/text-generator.helper';
2627

2728
describe('CloseNotificationModalComponent', () => {
2829
it('should create close modal', async () => {
@@ -54,9 +55,19 @@ describe('CloseNotificationModalComponent', () => {
5455

5556
const errorMessage_1 = await waitFor(() => screen.getByText('errorMessage.required'));
5657
expect(errorMessage_1).toBeInTheDocument();
58+
5759
fireEvent.input(textArea, { target: { value: 'Some Text' } });
60+
const errorMessage_2 = await waitFor(() => screen.getByText('errorMessage.minLength'));
61+
expect(errorMessage_2).toBeInTheDocument();
62+
63+
fireEvent.input(textArea, { target: { value: getRandomText(1500) } });
64+
const errorMessage_3 = await waitFor(() => screen.getByText('errorMessage.maxLength'));
65+
expect(errorMessage_3).toBeInTheDocument();
5866

67+
fireEvent.input(textArea, { target: { value: 'Some longer text with at least 15 chars' } });
5968
expect(errorMessage_1).not.toBeInTheDocument();
69+
expect(errorMessage_2).not.toBeInTheDocument();
70+
expect(errorMessage_3).not.toBeInTheDocument();
6071
});
6172

6273
it('should call close function', async () => {

src/app/modules/shared/modules/notification/modal/close/close-notification-modal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class CloseNotificationModalComponent {
4646

4747
public show(notification: Notification): void {
4848
this.notification = notification;
49-
this.textAreaControl.setValidators([Validators.required]);
49+
this.textAreaControl.setValidators([Validators.required, Validators.maxLength(1000), Validators.minLength(15)]);
5050

5151
const onConfirm = (isConfirmed: boolean) => {
5252
const reason = this.formGroup.get('reason').value;

src/app/modules/shared/modules/notification/modal/decline/decline-notification-modal.component.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import { NotificationStatus } from '@shared/model/notification.model';
2323
import { renderDeclineModal } from '@shared/modules/notification/modal/modalTestHelper.spec';
2424
import { fireEvent, screen, waitFor } from '@testing-library/angular';
25+
import { getRandomText } from '../../../../../../mocks/services/text-generator.helper';
2526

2627
describe('DeclineNotificationModalComponent', () => {
2728
it('should create close modal', async () => {
@@ -56,8 +57,17 @@ describe('DeclineNotificationModalComponent', () => {
5657
expect(errorMessage_1).toBeInTheDocument();
5758

5859
fireEvent.input(textArea, { target: { value: 'Some Text' } });
60+
const errorMessage_2 = await waitFor(() => screen.getByText('errorMessage.minLength'));
61+
expect(errorMessage_2).toBeInTheDocument();
5962

63+
fireEvent.input(textArea, { target: { value: getRandomText(1500) } });
64+
const errorMessage_3 = await waitFor(() => screen.getByText('errorMessage.maxLength'));
65+
expect(errorMessage_3).toBeInTheDocument();
66+
67+
fireEvent.input(textArea, { target: { value: 'Some longer text with at least 15 chars' } });
6068
expect(errorMessage_1).not.toBeInTheDocument();
69+
expect(errorMessage_2).not.toBeInTheDocument();
70+
expect(errorMessage_3).not.toBeInTheDocument();
6171
});
6272

6373
it('should call close function', async () => {

src/app/modules/shared/modules/notification/modal/decline/decline-notification-modal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class DeclineNotificationModalComponent {
4646

4747
public show(notification: Notification): void {
4848
this.notification = notification;
49-
this.textAreaControl.setValidators([Validators.required]);
49+
this.textAreaControl.setValidators([Validators.required, Validators.maxLength(1000), Validators.minLength(15)]);
5050

5151
const onConfirm = (isConfirmed: boolean) => {
5252
const reason = this.formGroup.get('reason').value;

0 commit comments

Comments
 (0)