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 5995a95
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 69 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,6 +1,4 @@
import { EditorConfig, EditorField, EditorSection } from '../models'

export const EDITOR_CONFIG = (): EditorConfig => ({
export const EDITOR_CONFIG = () => ({
pages: [
{
labelKey: 'Resource description',
Expand All @@ -20,7 +18,7 @@ export const EDITOR_CONFIG = (): EditorConfig => ({
],
})

export const EDITOR_SECTION_ABOUT = (): EditorSection => ({
export const EDITOR_SECTION_ABOUT = () => ({
labelKey: 'About the resource',
descriptionKey: 'This section describes the resource.',
hidden: false,
Expand All @@ -34,28 +32,28 @@ export const EDITOR_SECTION_ABOUT = (): EditorSection => ({
],
})

export const EDITOR_SECTION_DATA_MANAGER = (): EditorSection => ({
export const EDITOR_SECTION_DATA_MANAGER = () => ({
labelKey: 'Data manager',
descriptionKey: '',
hidden: false,
fields: [],
})

export const EDITOR_SECTION_USE_AND_ACCESS_CONDITIONS = (): EditorSection => ({
export const EDITOR_SECTION_USE_AND_ACCESS_CONDITIONS = () => ({
labelKey: 'Data manager',
descriptionKey: '',
hidden: false,
fields: [EDITOR_FIELD_LICENSE()],
})

export const EDITOR_SECTION_CLASSIFICATION = (): EditorSection => ({
export const EDITOR_SECTION_CLASSIFICATION = () => ({
labelKey: 'Classification',
descriptionKey: 'The classification has an impact on the access to the data.',
hidden: false,
fields: [EDITOR_FIELD_KEYWORDS(), EDITOR_FIELD_UNIQUE_IDENTIFIER()],
})

export const EDITOR_FIELD_TITLE = (): EditorField => ({
export const EDITOR_FIELD_TITLE = () => ({
model: 'title',
hidden: false,
value: 'Accroches vélos MEL',
Expand All @@ -64,7 +62,7 @@ export const EDITOR_FIELD_TITLE = (): EditorField => ({
},
})

export const EDITOR_FIELD_ABSTRACT = (): EditorField => ({
export const EDITOR_FIELD_ABSTRACT = () => ({
model: 'abstract',
hidden: false,
value: 'Abstract',
Expand All @@ -73,15 +71,15 @@ export const EDITOR_FIELD_ABSTRACT = (): EditorField => ({
},
})

export const EDITOR_FIELD_RESOURCE_UPDATED = (): EditorField => ({
export const EDITOR_FIELD_RESOURCE_UPDATED = () => ({
model: 'resourceUpdated',
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.resourceUpdated',
},
})

export const EDITOR_FIELD_RECORD_UPDATED = (): EditorField => ({
export const EDITOR_FIELD_RECORD_UPDATED = () => ({
model: 'recordUpdated',
hidden: false,
formFieldConfig: {
Expand All @@ -92,7 +90,7 @@ export const EDITOR_FIELD_RECORD_UPDATED = (): EditorField => ({
onSaveProcess: '${dateNow()}',
})

export const EDITOR_FIELD_UPDATE_FREQUENCY = (): EditorField => ({
export const EDITOR_FIELD_UPDATE_FREQUENCY = () => ({
model: 'updateFrequency',
hidden: false,
formFieldConfig: {
Expand All @@ -101,7 +99,7 @@ export const EDITOR_FIELD_UPDATE_FREQUENCY = (): EditorField => ({
value: 'unknown',
})

export const EDITOR_FIELD_TEMPORAL_EXTENTS = (): EditorField => ({
export const EDITOR_FIELD_TEMPORAL_EXTENTS = () => ({
model: 'temporalExtents',
hidden: false,
formFieldConfig: {
Expand All @@ -110,23 +108,23 @@ export const EDITOR_FIELD_TEMPORAL_EXTENTS = (): EditorField => ({
value: [],
})

export const EDITOR_FIELD_SPATIAL_EXTENTS = (): EditorField => ({
export const EDITOR_FIELD_SPATIAL_EXTENTS = () => ({
model: 'spatialExtents',
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.spatialExtents',
},
})

export const EDITOR_FIELD_KEYWORDS = (): EditorField => ({
export const EDITOR_FIELD_KEYWORDS = () => ({
model: 'keywords',
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.keywords',
},
})

export const EDITOR_FIELD_UNIQUE_IDENTIFIER = (): EditorField => ({
export const EDITOR_FIELD_UNIQUE_IDENTIFIER = () => ({
model: 'uniqueIdentifier',
hidden: false,
formFieldConfig: {
Expand All @@ -136,7 +134,7 @@ export const EDITOR_FIELD_UNIQUE_IDENTIFIER = (): EditorField => ({
value: 'accroche_velos',
})

export const EDITOR_FIELD_LICENSE = (): EditorField => ({
export const EDITOR_FIELD_LICENSE = () => ({
model: 'licenses',
hidden: false,
formFieldConfig: {
Expand All @@ -145,7 +143,7 @@ export const EDITOR_FIELD_LICENSE = (): EditorField => ({
},
})

export const EDITOR_FIELDS = (): EditorField[] => [
export const EDITOR_FIELDS = () => [
EDITOR_FIELD_TITLE(),
EDITOR_FIELD_ABSTRACT(),
EDITOR_FIELD_RESOURCE_UPDATED(),
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'

Check failure on line 9 in libs/feature/editor/src/lib/+state/editor.selectors.spec.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import 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
Loading

0 comments on commit 5995a95

Please sign in to comment.