+
Lorem ipsum dolor sit amet
@@ -27,10 +27,10 @@ describe('MaxLinesComponent', () => {
fixture = TestBed.createComponent(TestHostComponent)
hostComponent = fixture.componentInstance
maxLinesComponent = fixture.debugElement.children[0].componentInstance
- fixture.detectChanges()
})
it('should create', () => {
+ fixture.detectChanges()
expect(maxLinesComponent).toBeTruthy()
})
@@ -38,36 +38,79 @@ describe('MaxLinesComponent', () => {
hostComponent.maxLines = 10
fixture.detectChanges()
- const contentElement: HTMLElement =
- fixture.nativeElement.querySelector('.test-content')
- expect(contentElement.childNodes[0].textContent).toBe(
+ const maxLinesElement: HTMLElement =
+ fixture.nativeElement.querySelector('.max-lines')
+ expect(maxLinesElement.childNodes[0].textContent).toBe(
'Lorem ipsum dolor sit amet'
)
})
- it('should adjust maxHeight based on content height', () => {
- let contentElement: HTMLElement =
- fixture.nativeElement.querySelector('.test-content')
+ describe('should adjust maxHeight based on content height', () => {
+ const contentHeight = 120
+ beforeEach(() => {
+ jest
+ .spyOn(
+ fixture.nativeElement.querySelector('.test-content'),
+ 'getBoundingClientRect'
+ )
+ .mockReturnValueOnce({
+ left: 100,
+ top: 50,
+ right: 20,
+ bottom: 10,
+ x: 30,
+ y: 40,
+ widht: 150,
+ height: contentHeight,
+ })
+ })
+ it('use content height if content height is smaller than max space', () => {
+ hostComponent.maxLines = 10
+
+ fixture.detectChanges()
- contentElement = fixture.nativeElement.querySelector('.test-content')
+ expect(maxLinesComponent.maxHeight).toBe(`${contentHeight}px`)
+ })
- const expectedHeight = `${
- maxLinesComponent.getLineHeight(contentElement) *
- maxLinesComponent.maxLines
- }px`
+ it('use max space height if content height is bigger than max space', () => {
+ hostComponent.maxLines = 2
- expect(maxLinesComponent.maxHeight).toBe(expectedHeight)
- })
+ const contentElement =
+ fixture.nativeElement.querySelector('.test-content')
+ fixture.detectChanges()
- it('should show "Show More" button for long content', () => {
- expect(maxLinesComponent.showToggleButton).toBeTruthy()
- })
+ const maxSpace =
+ maxLinesComponent.getLineHeight(contentElement) *
+ maxLinesComponent.maxLines
+
+ expect(maxLinesComponent.maxHeight).toBe(`${maxSpace}px`)
+ })
+
+ it('should show "Show More" button for long content', () => {
+ hostComponent.maxLines = 2
+
+ fixture.detectChanges()
+
+ expect(maxLinesComponent.showToggleButton).toBeTruthy()
+ })
+
+ it('should toggle display when "Show More" button is clicked', () => {
+ hostComponent.maxLines = 2
- it('should toggle display when "Show More" button is clicked', () => {
- maxLinesComponent.toggleDisplay()
+ const contentElement =
+ fixture.nativeElement.querySelector('.test-content')
+ fixture.detectChanges()
- expect(maxLinesComponent.isExpanded).toBeTruthy()
- expect(maxLinesComponent.maxHeight).toBe('')
+ maxLinesComponent.toggleDisplay()
+
+ expect(maxLinesComponent.isExpanded).toBeTruthy()
+ expect(maxLinesComponent.maxHeight).toBe(
+ `${
+ maxLinesComponent.maxLines *
+ maxLinesComponent.getLineHeight(contentElement)
+ }px`
+ )
+ })
})
afterEach(() => {
From b4d4d1628b079f0898433f95fac39f4120184d39 Mon Sep 17 00:00:00 2001
From: Angelika Kinas
Date: Tue, 19 Dec 2023 15:45:24 +0100
Subject: [PATCH 5/9] fix(e2e): Fix e2e test about description
---
apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
index 0fd48c48db..3e65952974 100644
--- a/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
+++ b/apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
@@ -106,6 +106,8 @@ describe('dataset pages', () => {
.find('[id="about"]')
.find('gn-ui-metadata-info')
.find('gn-ui-content-ghost')
+ .find('gn-ui-max-lines')
+ .children('div')
.children('p')
.should(($element) => {
const text = $element.text().trim()
From eef415df1c1865b558f3350e90d26220577819e0 Mon Sep 17 00:00:00 2001
From: Angelika Kinas
Date: Tue, 19 Dec 2023 16:32:50 +0100
Subject: [PATCH 6/9] feat(ui): Add translations for read more, read less
---
libs/ui/elements/src/lib/max-lines/max-lines.component.html | 2 +-
libs/ui/elements/src/lib/ui-elements.module.ts | 2 +-
translations/de.json | 2 ++
translations/en.json | 2 ++
translations/es.json | 2 ++
translations/fr.json | 2 ++
translations/it.json | 2 ++
translations/nl.json | 2 ++
translations/pt.json | 2 ++
translations/sk.json | 2 ++
10 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libs/ui/elements/src/lib/max-lines/max-lines.component.html b/libs/ui/elements/src/lib/max-lines/max-lines.component.html
index ca94208cde..040a870e84 100644
--- a/libs/ui/elements/src/lib/max-lines/max-lines.component.html
+++ b/libs/ui/elements/src/lib/max-lines/max-lines.component.html
@@ -11,5 +11,5 @@
(click)="toggleDisplay()"
class="text-primary cursor-pointer pt-2.5"
>
- {{ isExpanded ? 'Show Less' : 'Read More' }}
+ {{ (isExpanded ? 'ui.readLess' : 'ui.readMore') | translate }}
diff --git a/libs/ui/elements/src/lib/ui-elements.module.ts b/libs/ui/elements/src/lib/ui-elements.module.ts
index de219197c5..377675c95f 100644
--- a/libs/ui/elements/src/lib/ui-elements.module.ts
+++ b/libs/ui/elements/src/lib/ui-elements.module.ts
@@ -26,7 +26,7 @@ import { FormsModule } from '@angular/forms'
import { AvatarComponent } from './avatar/avatar.component'
import { UserPreviewComponent } from './user-preview/user-preview.component'
import { GnUiLinkifyDirective } from './metadata-info/linkify.directive'
-import { PaginationButtonsComponent } from './pagination-buttons/pagination-buttons.component';
+import { PaginationButtonsComponent } from './pagination-buttons/pagination-buttons.component'
import { MaxLinesComponent } from './max-lines/max-lines.component'
@NgModule({
diff --git a/translations/de.json b/translations/de.json
index 6ecb5d6d4a..53e9c81a52 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "HTML kopieren",
"tooltip.url.copy": "URL kopieren",
"tooltip.url.open": "URL öffnen",
+ "ui.readLess": "Weniger lesen",
+ "ui.readMore": "Weiterlesen",
"wfs.featuretype.notfound": "Kein passender Feature-Typ wurde im Dienst gefunden",
"wfs.geojsongml.notsupported": "Dieser Dienst unterstützt das GeoJSON- oder GML-Format nicht",
"wfs.unreachable.cors": "Der Dienst konnte aufgrund von CORS-Beschränkungen nicht erreicht werden",
diff --git a/translations/en.json b/translations/en.json
index cce6353f66..26a9cf9506 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "Copy HTML",
"tooltip.url.copy": "Copy URL",
"tooltip.url.open": "Open URL",
+ "ui.readLess": "Read less",
+ "ui.readMore": "Read more",
"wfs.featuretype.notfound": "No matching feature type was found in the service",
"wfs.geojsongml.notsupported": "This service does not support the GeoJSON or GML format",
"wfs.unreachable.cors": "The service could not be reached because of CORS limitations",
diff --git a/translations/es.json b/translations/es.json
index 9e4bd02a79..daf3244485 100644
--- a/translations/es.json
+++ b/translations/es.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "",
"tooltip.url.copy": "",
"tooltip.url.open": "",
+ "ui.readLess": "",
+ "ui.readMore": "",
"wfs.featuretype.notfound": "",
"wfs.geojsongml.notsupported": "",
"wfs.unreachable.cors": "",
diff --git a/translations/fr.json b/translations/fr.json
index 795fff860d..96ccb278b4 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "Copier le HTML",
"tooltip.url.copy": "Copier l'URL",
"tooltip.url.open": "Ouvrir l'URL",
+ "ui.readLess": "Réduire",
+ "ui.readMore": "Lire la suite",
"wfs.featuretype.notfound": "La classe d'objet n'a pas été trouvée dans le service",
"wfs.geojsongml.notsupported": "Le service ne supporte pas le format GeoJSON ou GML",
"wfs.unreachable.cors": "Le service n'est pas accessible en raison de limitations CORS",
diff --git a/translations/it.json b/translations/it.json
index b5c7f49092..5a8638635c 100644
--- a/translations/it.json
+++ b/translations/it.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "",
"tooltip.url.copy": "",
"tooltip.url.open": "",
+ "ui.readLess": "",
+ "ui.readMore": "",
"wfs.featuretype.notfound": "",
"wfs.geojsongml.notsupported": "",
"wfs.unreachable.cors": "",
diff --git a/translations/nl.json b/translations/nl.json
index 2176b77624..e0dffaca5e 100644
--- a/translations/nl.json
+++ b/translations/nl.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "",
"tooltip.url.copy": "",
"tooltip.url.open": "",
+ "ui.readLess": "",
+ "ui.readMore": "",
"wfs.featuretype.notfound": "",
"wfs.geojsongml.notsupported": "",
"wfs.unreachable.cors": "",
diff --git a/translations/pt.json b/translations/pt.json
index 4a2bdba25c..232c3f7051 100644
--- a/translations/pt.json
+++ b/translations/pt.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "",
"tooltip.url.copy": "",
"tooltip.url.open": "",
+ "ui.readLess": "",
+ "ui.readMore": "",
"wfs.featuretype.notfound": "",
"wfs.geojsongml.notsupported": "",
"wfs.unreachable.cors": "",
diff --git a/translations/sk.json b/translations/sk.json
index c43cce6973..107da7447d 100644
--- a/translations/sk.json
+++ b/translations/sk.json
@@ -294,6 +294,8 @@
"tooltip.html.copy": "",
"tooltip.url.copy": "",
"tooltip.url.open": "",
+ "ui.readLess": "",
+ "ui.readMore": "",
"wfs.featuretype.notfound": "",
"wfs.geojsongml.notsupported": "",
"wfs.unreachable.cors": "",
From 8622d11debcedec9de4e1a9c70b30287a2755ddd Mon Sep 17 00:00:00 2001
From: Angelika Kinas