Skip to content

Commit 842fd70

Browse files
fix 5310 : show social links bar on non-scrollable item pages (DSpace#5315)
* fix 5310 : show social links bar on non-scrollable item pages * fix 5310 : restore floating behavior on scrollable pages and prevent footer overlap * fix 5310 : restore floating style on all pages, only skip scroll-show when page is not scrollable * Fix DSpace#5310: use IntersectionObserver to hide bar when footer is visible * Fix DSpace#5310: adjustments based on feedback * Fix DSpace#5310: adjustments spec * Fix DSpace#5310: adjustments spec * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments spec re-run CI * Fix DSpace#5310: adjustments Floating Share Buttons
1 parent be3c3a2 commit 842fd70

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

src/app/social/social.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
<div id="dspace-a2a" [class.d-none]="(showOnCurrentRoute$ | async) !== true" data-a2a-scroll-show="0,60"
2-
class="a2a_kit a2a_kit_size_32 a2a_floating_style a2a_default_style" [attr.data-a2a-title]="title" [attr.data-a2a-url]="url">
1+
<div id="dspace-a2a"
2+
[class.d-none]="(showOnCurrentRoute$ | async) !== true"
3+
class="a2a_kit a2a_kit_size_32 a2a_floating_style a2a_vertical_style"
4+
[attr.data-a2a-title]="title"
5+
[attr.data-a2a-url]="url">
36
@for (button of buttonList; track button) {
47
<a [class]="'a2a_button_' + button" [class.a2a_counter]="showCounters && button !== 'facebook'"></a>
58
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
::ng-deep {
2-
div#dspace-a2a {
3-
bottom: 0;
4-
right: 0;
2+
#dspace-a2a {
53
z-index: 998;
4+
right: 0px !important;
5+
top: 150px !important;
6+
7+
@media screen and (max-width: 980px) {
8+
display: none !important;
9+
}
610
}
711
}

src/app/social/social.component.spec.ts

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { DOCUMENT } from '@angular/common';
22
import {
33
ComponentFixture,
4+
fakeAsync,
45
TestBed,
6+
tick,
57
} from '@angular/core/testing';
68
import { ActivatedRoute } from '@angular/router';
79
import { StoreModule } from '@ngrx/store';
10+
import { BehaviorSubject } from 'rxjs';
811

912
import { SocialComponent } from './social.component';
1013
import { SocialService } from './social.service';
1114

1215
describe('SocialComponent', () => {
1316
let component: SocialComponent;
1417
let fixture: ComponentFixture<SocialComponent>;
15-
let document: Document;
1618

1719
const socialServiceStub = {};
18-
1920
const activatedRouteStub = {} as ActivatedRoute;
2021

2122
beforeEach(async () => {
@@ -28,12 +29,77 @@ describe('SocialComponent', () => {
2829
}).compileComponents();
2930
fixture = TestBed.createComponent(SocialComponent);
3031
component = fixture.componentInstance;
31-
document = TestBed.inject(DOCUMENT) as any;
3232
fixture.detectChanges();
3333
});
3434

3535
it('should create socialComponent', () => {
3636
expect(component).toBeTruthy();
3737
});
3838

39+
it('should initialize properties from socialService configuration on ngOnInit', () => {
40+
const config = {
41+
buttons: ['facebook', 'twitter'],
42+
showPlusButton: true,
43+
showCounters: true,
44+
title: 'Test Title',
45+
};
46+
47+
(component as any).socialService = {
48+
enabled: true,
49+
configuration: config,
50+
initializeAddToAnyScript: () => {},
51+
showOnCurrentRoute$: null,
52+
};
53+
54+
component.ngOnInit();
55+
56+
expect(component.buttonList).toEqual(config.buttons);
57+
expect(component.showPlusButton).toBeTrue();
58+
expect(component.showCounters).toBeTrue();
59+
expect(component.title).toBe('Test Title');
60+
});
61+
62+
describe('toggle d-none', () => {
63+
let toggleFixture: ComponentFixture<SocialComponent>;
64+
let showOnCurrentRoute$: BehaviorSubject<boolean>;
65+
66+
beforeEach(async () => {
67+
showOnCurrentRoute$ = new BehaviorSubject<boolean>(false);
68+
69+
TestBed.resetTestingModule();
70+
await TestBed.configureTestingModule({
71+
imports: [StoreModule.forRoot({}), SocialComponent],
72+
providers: [
73+
{ provide: ActivatedRoute, useValue: activatedRouteStub },
74+
{
75+
provide: SocialService,
76+
useValue: {
77+
enabled: true,
78+
configuration: { buttons: [], showPlusButton: false, showCounters: false, title: '' },
79+
initializeAddToAnyScript: () => {},
80+
showOnCurrentRoute$: showOnCurrentRoute$,
81+
},
82+
},
83+
],
84+
}).compileComponents();
85+
86+
toggleFixture = TestBed.createComponent(SocialComponent);
87+
toggleFixture.detectChanges();
88+
});
89+
90+
it('should toggle d-none class based on showOnCurrentRoute$', fakeAsync(() => {
91+
const doc = TestBed.inject(DOCUMENT);
92+
93+
const bar = doc.getElementById('dspace-a2a');
94+
expect(bar).toBeTruthy();
95+
expect(bar.classList.contains('d-none')).toBeTrue();
96+
97+
showOnCurrentRoute$.next(true);
98+
tick();
99+
toggleFixture.detectChanges();
100+
101+
expect(bar.classList.contains('d-none')).toBeFalse();
102+
}));
103+
});
104+
39105
});

src/app/social/social.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import { SocialService } from './social.service';
2222
*/
2323
export class SocialComponent implements OnInit {
2424

25+
2526
/**
2627
* The script containing the profile ID
2728
*/
2829
script: HTMLScriptElement;
2930

3031
showOnCurrentRoute$: Observable<boolean>;
31-
3232
buttonList: string[];
3333
showPlusButton: boolean;
3434
title: string;

0 commit comments

Comments
 (0)