Skip to content

Pu/issue709 - #710

Merged
izulin merged 4 commits into
developfrom
pu/issue709
Jun 17, 2021
Merged

izulin merged 4 commits into
developfrom
pu/issue709

Conversation

@izulin

@izulin izulin commented Jun 14, 2021

Copy link
Copy Markdown
Contributor

Context

Fixes #709

How has this been tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

Checklist:

  • My code follows the code style of this project,
  • My change requires a change to the documentation,
  • I described the modification in the CHANGELOG.md file.

@izulin
izulin requested a review from wojciechczerniak June 14, 2021 16:16
@codecov

codecov Bot commented Jun 14, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #710 (3d80202) into develop (8f02f1d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #710     +/-   ##
==========================================
  Coverage    92.27%   92.27%             
==========================================
  Files          166      166             
  Lines        39412    39412             
  Branches      5365     3575   -1790     
==========================================
  Hits         36368    36368             
- Misses        3005     3038     +33     
+ Partials        39        6     -33     
Impacted Files Coverage Δ
src/interpreter/plugin/DateTimePlugin.ts 98.74% <100.00%> (ø)
src/Cell.ts 95.54% <0.00%> (ø)
src/MatrixSize.ts 48.48% <0.00%> (ø)
src/Operations.ts 93.23% <0.00%> (ø)
src/DateTimeHelper.ts 82.62% <0.00%> (ø)
src/DateTimeDefault.ts 56.36% <0.00%> (ø)
src/AbsoluteCellRange.ts 86.65% <0.00%> (ø)
src/Lookup/AdvancedFind.ts 90.32% <0.00%> (ø)
src/parser/FormulaParser.ts 82.43% <0.00%> (ø)
src/interpreter/Criterion.ts 84.40% <0.00%> (ø)
... and 12 more

Comment on lines +16 to +20
let cnt = 20
Date.now = () => {
cnt += 1
return Date.parse(`1985-08-16T03:45:${cnt}`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more elegant way will be and it's clear its a mock:

Suggested change
let cnt = 20
Date.now = () => {
cnt += 1
return Date.parse(`1985-08-16T03:45:${cnt}`)
}
dateMock = jest.fn().mockReturnValue(new Date('1985-08-16T03:45:30Z').getTime())
Date.now = dateMock

I will get to NOW in the next comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work for the multitude of testers that we have? (jest, jasmine, karma)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, it will not, I forgot about jasmine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should fight for some hybrid jest/jasmine mock tests and just go with what we have. But of course it is up to you

Comment on lines +28 to +32
expect(t1).toBeCloseTo(31275.1565856481)
expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_DATETIME)
sleepFor(1000)
engine.setCellContents(adr('A2'), null)
const t2 = engine.getCellValue(adr('A1')) as number
const delta = (t2-t1)*(24*60*60)
expect(delta).toBeCloseTo(1)
const delta = engine.getCellValue(adr('A1')) as number - t1
expect(delta*24*60*60).toBeGreaterThanOrEqual(1) //internals of the engine are also using Date.now(), so the value should be actually 4 or even more

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have this test predictable?

dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())

const t1 = engine.getCellValue(adr('A1'))

dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())

engine.setCellContents(adr('A2'), null)
const t2 = engine.getCellValue(adr('A1'))

we will know exactly what time each NOW() returns and can make precise expectation

@wojciechczerniak wojciechczerniak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @izulin noticed correctly we can't use Jest mocks, they will fail in Jasmine

@izulin
izulin merged commit ee22e12 into develop Jun 17, 2021
@izulin
izulin deleted the pu/issue709 branch June 17, 2021 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants