Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alert, Alert Group, Alert Service]: New components and service #427

Merged
merged 28 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ba7252f
DS-269: Expose Alert and AlertGroup components to public API
RiinaKuu Sep 5, 2024
381693f
DS-269: Expose AlertGroup inside Dialog template
RiinaKuu Sep 5, 2024
baea710
DS-269: Change Body Text variant logic when used inside Dialog to avo…
RiinaKuu Sep 5, 2024
1c301b5
DS-269: Refactor Alert message to Observable, add Output for clicking…
RiinaKuu Sep 6, 2024
053e02d
DS-269: Refactor all Alert Service Signals to Observables
RiinaKuu Sep 6, 2024
2cd9823
DS-269: Add exception stylings for Link and Body Text inside Alert
RiinaKuu Sep 6, 2024
9dc641e
DS-269: Update Alert Group docs and Story
RiinaKuu Sep 6, 2024
64db67f
DS-269: Update Alert Service unit tests
RiinaKuu Sep 9, 2024
42a2575
DS-269: Create Playwright tests and base images for Alert Group
RiinaKuu Sep 9, 2024
30a13e3
DS-269: Update Alert Component unit tests, remove tests that are cove…
RiinaKuu Sep 9, 2024
f37d4ca
DS-269: Update Alert Group unit tests, force change detection in Afte…
RiinaKuu Sep 9, 2024
b98fc03
DS-269: Add comment to Alert Group docs that the component is not com…
RiinaKuu Sep 9, 2024
14e115b
Merge branch 'main' into DS-269-alert
RiinaKuu Sep 9, 2024
2eb68e8
DS-269: Fix Playwright test and add missing base images
RiinaKuu Sep 9, 2024
f81f6fb
DS-269: Add focus and blur event unit test back to Alert Component
RiinaKuu Sep 10, 2024
2ce8ccb
DS-269: Fix Alert Group story control
RiinaKuu Sep 10, 2024
ea2aaed
DS-269: Change Dialog Service Signals to Observables
RiinaKuu Sep 11, 2024
49e95f8
DS-269: Remove link feature from Alert, remove string option from Ale…
RiinaKuu Sep 11, 2024
70e962a
DS-269: Change AlertGroup life cycle, add OnPush change detection, re…
RiinaKuu Sep 11, 2024
62f9e50
DS-269: Add Alert Group example to sandbox
RiinaKuu Sep 11, 2024
62a3032
DS-269: Remove unnecessary link-theme file since links are not suppor…
RiinaKuu Sep 11, 2024
eca71d3
DS-269: Remove Link Component styleUrl since its stylesheet is import…
RiinaKuu Sep 11, 2024
27adec2
DS-269: Update Playwright tests and base images after link feature wa…
RiinaKuu Sep 11, 2024
dafa1c6
DS-269: Fix failing test, remove unused property, small addition to docs
RiinaKuu Sep 12, 2024
3958fef
Merge branch 'main' into DS-269-alert
RiinaKuu Sep 13, 2024
1e5588f
DS-269: unit test adjust
videoeero Sep 19, 2024
365944d
DS-289: doc and comment tweaks
videoeero Sep 19, 2024
64931cf
Merge branch 'main' into DS-269-alert
videoeero Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<section
*ngIf="_visible"
*ngIf="(_visible | async) && (_alertList | async) as alerts"
class="fudis-alert-group fudis-alert-group__{{ position }}"
[attr.aria-label]="_alertList().length > 0 ? _alertGroupLabel + ': ' + _alertList().length : null"
[attr.aria-label]="alerts.length > 0 ? (_alertGroupLabel | async) + ': ' + alerts.length : null"
>
<ng-container *ngFor="let alert of _alertList()">
<ng-container *ngFor="let alert of alerts">
<fudis-alert
[initialFocus]="alert.initialFocus"
[variant]="alert.type"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MockComponent } from 'ng-mocks';
import { AlertGroupComponent } from './alert-group.component';
import { FudisDialogService } from '../../../services/dialog/dialog.service';
import { BodyTextComponent } from '../../typography/body-text/body-text.component';
import { FudisAlertService } from '../../../services/alert/alert.service';
import { FudisAlert } from '../../../types/miscellaneous';
import { FudisAlert, fudisAlertPositionArray } from '../../../types/miscellaneous';
import { AlertComponent } from '../alert/alert.component';
import { IconComponent } from '../../icon/icon.component';
import { getElement, sortClasses } from '../../../utilities/tests/utilities';
import { BehaviorSubject } from 'rxjs';

// TODO: fix & refactor when these are again published

describe.skip('AlertGroupComponent', () => {
describe('AlertGroupComponent', () => {
let component: AlertGroupComponent;
let fixture: ComponentFixture<AlertGroupComponent>;
let alertService: FudisAlertService;
let dialogService: FudisDialogService;

beforeEach(() => {
TestBed.configureTestingModule({
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatDialogModule],
declarations: [
AlertGroupComponent,
BodyTextComponent,
AlertComponent,
BodyTextComponent,
MockComponent(IconComponent),
],
providers: [
Expand All @@ -39,7 +37,10 @@ describe.skip('AlertGroupComponent', () => {
useValue: [],
},
],
});
}).compileComponents();

alertService = TestBed.inject(FudisAlertService);
dialogService = TestBed.inject(FudisDialogService);
fixture = TestBed.createComponent(AlertGroupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand All @@ -50,55 +51,33 @@ describe.skip('AlertGroupComponent', () => {
});

describe('Basic inputs', () => {
it('should have default CSS classes', () => {
const element = getElement(fixture, 'section');

expect(sortClasses(element.className)).toEqual(
sortClasses('fudis-alert-group fudis-alert-group__fixed'),
);
});

it('should have absolute position', () => {
component.position = 'absolute';
fixture.detectChanges();

const element = getElement(fixture, 'section');

expect(sortClasses(element.className)).toEqual(
sortClasses('fudis-alert-group fudis-alert-group__absolute'),
);
});

it('should have static position', () => {
component.position = 'static';
fixture.detectChanges();

const element = getElement(fixture, 'section');

expect(sortClasses(element.className)).toEqual(
sortClasses('fudis-alert-group fudis-alert-group__static'),
);
it('should update CSS class according to position input', () => {
fudisAlertPositionArray.forEach((position) => {
const element = getElement(fixture, '.fudis-alert-group');
fixture.componentRef.setInput('position', `${position}`);
fixture.detectChanges();

expect(sortClasses(element.className)).toEqual(
sortClasses(`fudis-alert-group fudis-alert-group__${position}`),
);
});
});
});

describe('Functionality with services', () => {
beforeEach(() => {
alertService = TestBed.inject(FudisAlertService);
dialogService = TestBed.inject(FudisDialogService);

jest.spyOn(alertService, 'getAlertsSignal').mockImplementation();

const firstAlert: FudisAlert = {
message: 'Test message',
message: new BehaviorSubject<string>('Test message'),
id: 'my-test-id-1',
type: 'info',
};

const secondAlert: FudisAlert = {
message: 'Second test message',
message: new BehaviorSubject<string>('Second test message'),
id: 'my-test-id-2',
type: 'warning',
};

alertService.addAlert(firstAlert);
alertService.addAlert(secondAlert);
});
Expand All @@ -111,7 +90,7 @@ describe.skip('AlertGroupComponent', () => {
expect(childAlerts.length).toEqual(2);
});

it('should have one alert as children after one is dismissed', () => {
it('should have one alert as child after one is dismissed', () => {
alertService.dismissAlert('my-test-id-1');
fixture.detectChanges();

Expand Down Expand Up @@ -142,7 +121,6 @@ describe.skip('AlertGroupComponent', () => {

it('should not be visible, if Dialog is not open and Alert Group is inside dialog', () => {
component.insideDialog = true;

component.ngAfterViewInit();

fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeDetectorRef, Component, Input, AfterViewInit, Signal, effect } from '@angular/core';

import { FudisAlertElement } from '../../../types/miscellaneous';
import { Component, Input, AfterViewInit, effect, ChangeDetectorRef } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FudisAlertElement, FudisAlertPosition } from '../../../types/miscellaneous';
import { FudisTranslationService } from '../../../services/translation/translation.service';
import { FudisAlertService } from '../../../services/alert/alert.service';
import { FudisDialogService } from '../../../services/dialog/dialog.service';
Expand All @@ -14,13 +15,18 @@ export class AlertGroupComponent implements AfterViewInit {
constructor(
private _alertService: FudisAlertService,
private _translationService: FudisTranslationService,
private readonly _changeDetectorRef: ChangeDetectorRef,
private _dialogService: FudisDialogService,
private _cdRef: ChangeDetectorRef,
) {
/**
* Subscribe to current visible alerts
*/
_alertService.allAlertsObservable.pipe(takeUntilDestroyed()).subscribe((value) => {
this._alertList.next(value);
RiinaKuu marked this conversation as resolved.
Show resolved Hide resolved
});

effect(() => {
this._alertList = this._alertService.getAlertsSignal();
// TODO: To Observable
this._alertGroupLabel = this._translationService.getTranslations()().ALERT.HEADING_LABEL;
this._alertGroupLabel.next(this._translationService.getTranslations()().ALERT.HEADING_LABEL);

this._dialogStatus = this._dialogService.getDialogOpenSignal()();

Expand All @@ -29,54 +35,55 @@ export class AlertGroupComponent implements AfterViewInit {
}

/**
* CSS position of alerts. Defaults to fixed.
* CSS position of alerts
*/
@Input() position: 'fixed' | 'absolute' | 'static' = 'fixed';
@Input() position: FudisAlertPosition = 'fixed';

/**
* Boolean to determine if Alert Group is used as child in Fudis Dialog.
* Boolean to determine if Alert Group is used inside Fudis Dialog Component
*/
@Input() insideDialog: boolean = false;

/**
* List of Alerts fetched from service
* List of Alerts fetched from Alert Service
*/
protected _alertList: Signal<FudisAlertElement[]>;
protected _alertList = new BehaviorSubject<FudisAlertElement[]>([]);

/**
* Label for section element containing alerts
*/
protected _alertGroupLabel: string;
protected _alertGroupLabel = new BehaviorSubject<string>('');

/**
* Boolean to determine if Alert group is visible. Used with _dialogStatus boolean.
* Boolean to determine if Alert group is visible. Used with _dialogStatus boolean
*/
protected _visible: boolean = false;
protected _visible = new BehaviorSubject<boolean>(false);

/**
* Boolean from service to determine if Fudis Dialog is open.
* Boolean from Dialog Service to determine if Fudis Dialog is open
*/
private _dialogStatus: boolean;

ngAfterViewInit(): void {
this._setVisibility();
this._cdRef.detectChanges();
}

/**
* Getter for visible status
*/
public getVisibleStatus(): boolean {
return this._visible;
return this._visible.value;
}

/**
* Set visibility when Fudis Dialog is opened and closed.
* Set visibility when Fudis Dialog is opened and closed
*/
private _setVisibility(): void {
if ((this._dialogStatus && this.insideDialog) || (!this._dialogStatus && !this.insideDialog)) {
this._visible = true;
this._visible.next(true);
} else {
this._visible = false;
this._visible.next(false);
}
}
}
Loading
Loading