Skip to content

Commit

Permalink
code review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Caplier committed Jul 23, 2024
1 parent 24df228 commit 3ab0175
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
: 'bg-gray-200'
"
>
{{ index }}
{{ index + 1 }}
</div>
<div
class="ms-4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TranslateModule } from '@ngx-translate/core'
import { PageSelectorComponent } from './page-selector.component'
import { EDITOR_CONFIG } from '@geonetwork-ui/feature/editor'
import { EDITOR_CONFIG } from '@geonetwork-ui/common/fixtures'
import { BehaviorSubject } from 'rxjs'
import { EditorFacade } from '@geonetwork-ui/feature/editor'

describe('BreadcrumbsComponent', () => {
class EditorFacadeMock {
editorConfig$ = new BehaviorSubject(EDITOR_CONFIG())
setCurrentPage = jest.fn()
}

describe('PageSelectorComponent', () => {
let component: PageSelectorComponent
let fixture: ComponentFixture<PageSelectorComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
providers: [],
providers: [
{
provide: EditorFacade,
useClass: EditorFacadeMock,
},
],
}).compileComponents()

fixture = TestBed.createComponent(PageSelectorComponent)
component = fixture.componentInstance
component.pages = EDITOR_CONFIG().pages
component.selectedPage = 0
fixture.detectChanges()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export class PageSelectorComponent {
constructor(public facade: EditorFacade) {}

pageSectionClickHandler(index: number) {
this.facade.setCurrentPage(index) // TODO
this.facade.setCurrentPage(index)
}
}
10 changes: 4 additions & 6 deletions apps/metadata-editor/src/app/edit/edit-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { EditPageComponent } from './edit-page.component'
import { ActivatedRoute, Router } from '@angular/router'
import { EDITOR_CONFIG, EditorFacade } from '@geonetwork-ui/feature/editor'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { DATASET_RECORDS, EDITOR_CONFIG } from '@geonetwork-ui/common/fixtures'
import { BehaviorSubject, Subject } from 'rxjs'
import { NotificationsService } from '@geonetwork-ui/feature/notifications'
import { TranslateModule } from '@ngx-translate/core'
import { FindPipe } from '../pipes/filter.pipe'
import { PageSelectorComponent } from './components/breadcrumbs/page-selector.component'
import { PageSelectorComponent } from './components/page-selector/page-selector.component'
import { EditorFacade } from '@geonetwork-ui/feature/editor'

const getRoute = () => ({
snapshot: {
Expand All @@ -27,11 +26,11 @@ class RouterMock {

class EditorFacadeMock {
record$ = new BehaviorSubject(DATASET_RECORDS[0])
recordFields$ = new BehaviorSubject(EDITOR_CONFIG())
openRecord = jest.fn()
saveError$ = new Subject<string>()
saveSuccess$ = new Subject()
draftSaveSuccess$ = new Subject()
editorConfig$ = new BehaviorSubject(EDITOR_CONFIG())
}
class NotificationsServiceMock {
showNotification = jest.fn()
Expand All @@ -48,7 +47,6 @@ describe('EditPageComponent', () => {
imports: [
EditPageComponent,
TranslateModule.forRoot(),
FindPipe,
PageSelectorComponent,
],
schemas: [NO_ERRORS_SCHEMA],
Expand Down
4 changes: 2 additions & 2 deletions apps/metadata-editor/src/app/edit/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@geonetwork-ui/feature/notifications'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { filter, firstValueFrom, Subscription, take } from 'rxjs'
import { PageSelectorComponent } from './components/breadcrumbs/page-selector.component'
import { PageSelectorComponent } from './components/page-selector/page-selector.component'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import { map } from 'rxjs/operators'

Expand Down Expand Up @@ -130,7 +130,7 @@ export class EditPageComponent implements OnInit, OnDestroy {
if (currentPage === 0) {
this.router.navigate(['catalog', 'search'])
} else {
this.facade.setCurrentPage(currentPage - 1) // TODO
this.facade.setCurrentPage(currentPage - 1)
}
}

Expand Down
3 changes: 1 addition & 2 deletions apps/metadata-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"target": "es2020",
"lib": ["dom", "es2020", "dom.iterable"],
"downlevelIteration": true
"lib": ["dom", "es2020", "dom.iterable"]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
Expand Down
8 changes: 0 additions & 8 deletions assets-common/css/default-fonts.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/* Petrona */
@font-face {
font-family: 'Petrona';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(../fonts/Petrona-Regular.woff2) format('woff2');
}
/* arabic */
@font-face {
font-family: 'Readex Pro';
Expand Down
2 changes: 2 additions & 0 deletions libs/common/fixtures/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export * from './lib/records.fixtures'
export * from './lib/repository.fixtures'
export * from './lib/user.fixtures'
export * from './lib/user-feedbacks.fixtures'

export * from './lib/editor'
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { EditorConfig, EditorField, EditorSection } from '../models'
import {
EditorConfig,
EditorField,
EditorSection,
} from '@geonetwork-ui/feature/editor'

export const EDITOR_CONFIG = (): EditorConfig => ({
pages: [
Expand Down
1 change: 0 additions & 1 deletion libs/feature/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ export * from './lib/components/record-form/record-form.component'
export * from './lib/components/wizard/wizard.component'
export * from './lib/components/wizard-field/wizard-field.component'
export * from './lib/components/wizard-summarize/wizard-summarize.component'
export * from './lib/fixtures'
3 changes: 2 additions & 1 deletion libs/feature/editor/src/lib/+state/editor.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const initialEditorState = {
saveError: null,
changedSinceSave: false,
alreadySavedOnce: true,
fieldsConfig: [],
editorConfig: [],
currentPage: 0,
}

describe('EditorEffects', () => {
Expand Down
50 changes: 31 additions & 19 deletions libs/feature/editor/src/lib/+state/editor.selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { EditorPartialState, initialEditorState } from './editor.reducer'
import {
EDITOR_FEATURE_KEY,
EditorPartialState,
initialEditorState,
} from './editor.reducer'
import * as EditorSelectors from './editor.selectors'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { DEFAULT_FIELDS } from '../fields.config'
import { EditorSectionWithValues } from '@geonetwork-ui/feature/editor'

describe('Editor Selectors', () => {
let state: EditorPartialState
Expand Down Expand Up @@ -56,22 +61,27 @@ describe('Editor Selectors', () => {
})

describe('selectRecordFields', () => {
it('should return the config and value for each field', () => {
const result = EditorSelectors.selectRecordSections(state)

const actualSections = result.pages.map((page) => page.sections).flat()

const expectedSections = DEFAULT_FIELDS.pages
.map((page) => page.sections)
.flat()

expect(actualSections).toEqual(expectedSections)

const actualFields = actualSections
it('should return the config and value for specified page', () => {
const recordSections = EditorSelectors.selectRecordSections(state)

const expectedResult = DEFAULT_FIELDS.pages[0].sections.map(
(section) => ({
...section,
fieldsWithValues: section.fields.map((fieldConfig) => ({
config: fieldConfig,
value:
state[EDITOR_FEATURE_KEY].record?.[fieldConfig.model] ?? null,
})),
})
) as EditorSectionWithValues[]

expect(recordSections).toEqual(expectedResult)

const actualFields = recordSections
.map((section) => section.fields)
.flat()

const expectedFields = expectedSections
const expectedFields = expectedResult
.map((section) => section.fields)
.flat()

Expand All @@ -91,15 +101,17 @@ describe('Editor Selectors', () => {
},
})

const resultFields = result.pages
.flatMap((page) => page.sections)
.flatMap((section) => section.fields)
const resultFields = result.flatMap(
(section) => section.fieldsWithValues
)

const abstractField = resultFields.find(
(field) => field.model === 'abstract'
(field) => field.config.model === 'abstract'
)

const titleField = resultFields.find((field) => field.model === 'title')
const titleField = resultFields.find(
(field) => field.config.model === 'title'
)

expect(abstractField.value).toEqual('')
expect(titleField.value).toEqual('')
Expand Down
3 changes: 1 addition & 2 deletions libs/feature/editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"target": "es2020",
"lib": ["dom", "es2020", "dom.iterable"],
"downlevelIteration": true
"lib": ["dom", "es2020", "dom.iterable"]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
Expand Down
3 changes: 1 addition & 2 deletions libs/feature/editor/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2020", "dom.iterable"],
"downlevelIteration": true
"lib": ["dom", "es2020", "dom.iterable"]
},
"exclude": [
"src/test-setup.ts",
Expand Down
1 change: 0 additions & 1 deletion tailwind.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module.exports = {
title:
'var(--font-family-title, ui-serif, Georgia, Cambria, "Times New Roman", Times, serif)', // alias for serif
mono: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
petrona: ['Petrona', 'serif'],
},
fontSize: {
13: '13px',
Expand Down

0 comments on commit 3ab0175

Please sign in to comment.