Skip to content

Commit

Permalink
fix: display of n/a
Browse files Browse the repository at this point in the history
  • Loading branch information
AlitaBernachot committed Nov 25, 2024
1 parent fb0e083 commit 005f394
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion cypress/e2e/draw/draw-feat-point.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('Draw "Point"', () => {

it('displays the symbol edition tab', () => {
cy.get('[data-cy="featStyleColor"]').should('exist')
// starting with featStyleSymbol_
cy.get('[data-cy^="featStyleSymbol_"]').should('have.length', 4)
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/draw/draw-feat-polygon.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Draw "Polygon"', () => {
// - chrome and chromium browsers give different decimals in measurements
// - therefore only the int part of the surface is checked
cy.get('*[data-cy="featItemArea"]')
.should('contain.text', 'Surface: 1532.')
.should('contain.text', 'Surface:\u00A01532.')
.and('contain.text', ' km²')
})

Expand Down
6 changes: 1 addition & 5 deletions src/directives/format-measure.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ function format(
let content = binding.value
const digits = binding?.arg !== undefined ? +binding?.arg : undefined

if (content === null || isNaN(+content)) {
return
}

try {
type = <FormatMeasureType>Object.keys(binding.modifiers)[0]
} catch (e) {
// Do nothing...
}

content = formatMeasure(+content, digits, type)
content = formatMeasure(content, digits, type)

el.textContent = content
}
12 changes: 8 additions & 4 deletions src/services/common/formatting.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
formatMeasure,
} from './formatting.utils'

vi.mock('i18next', () => ({
default: { t: vi.fn(key => key) },
}))

describe('Formatting utils', () => {
describe('#formatDate', () => {
it('formats date by default in fr-FR', () => {
Expand Down Expand Up @@ -34,9 +38,9 @@ describe('Formatting utils', () => {
expect(val).toEqual('42.0006 km')
})

it('returns empty string if given value is invalid number', () => {
it('returns "N/A" string if given value is invalid number', () => {
const val = formatMeasure(<number>(<unknown>'test'), 4)
expect(val).toEqual('')
expect(val).toEqual('N/A')
})

it('formats value as elevation', () => {
Expand All @@ -54,13 +58,13 @@ describe('Formatting utils', () => {
expect(val).toEqual('11000000.56 m')
})

it('returns original value if given value is invalid number', () => {
it('returns "N/A" string if given value is invalid number', () => {
const val = formatMeasure(
<number>(<unknown>'wrong elevation'),
4,
'elevation'
)
expect(val).toEqual('wrong elevation')
expect(val).toEqual('N/A')
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/services/common/formatting.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function formatMeasure(
digits?: number,
type?: FormatMeasureType
) {
if (value === null) {
if (value == null || isNaN(value)) {
return i18next.t('N/A', { ns: 'client' })
}

Expand Down

0 comments on commit 005f394

Please sign in to comment.