Skip to content

Commit

Permalink
test: add more precise assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Feb 26, 2023
1 parent 720e915 commit 78d1077
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions __tests__/unit/lib/post-processor/flowTranslationProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const FlowTranslationProcessor = require('../../../../src/post-processor/flowTra
const { mockParse } = require('fast-xml-parser')
const {
FLOW_DIRECTORY_NAME,
METAFILE_SUFFIX,
TRANSLATION_EXTENSION,
TRANSLATION_TYPE,
} = require('../../../../src/utils/metadataConstants')
const {
Expand All @@ -19,6 +21,7 @@ jest.mock('../../../../src/utils/ignoreHelper')
const FR = 'fr'
const EN = 'en'
const flowFullName = 'test-flow'
const EXTENSION = `${TRANSLATION_EXTENSION}${METAFILE_SUFFIX}`

const trueAfter = (attempt = 0) => {
let count = 0
Expand Down Expand Up @@ -62,6 +65,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand All @@ -79,6 +87,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).not.toHaveBeenCalled()
})
Expand All @@ -101,6 +114,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).toHaveBeenCalled()
})
Expand Down Expand Up @@ -138,6 +156,11 @@ describe('FlowTranslationProcessor', () => {

// Assert
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -174,6 +197,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(2)
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -201,6 +229,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).toHaveBeenCalledTimes(2)
if (generateDelta) expect(copyFiles).toHaveBeenCalledTimes(2)
else expect(copyFiles).not.toHaveBeenCalled()
Expand All @@ -223,6 +256,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(forPath).toHaveBeenCalledTimes(1)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
Expand All @@ -245,6 +283,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeTruthy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(forPath).toHaveBeenCalledTimes(1)
expect(mockParse).toHaveBeenCalledTimes(1)
expect(copyFiles).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -274,6 +317,11 @@ describe('FlowTranslationProcessor', () => {
// Assert
expect(work.diffs.package.has(TRANSLATION_TYPE)).toBeFalsy()
expect(scanExtension).toHaveBeenCalledTimes(1)
expect(scanExtension).toHaveBeenCalledWith(
work.config.source,
EXTENSION,
work.config
)
expect(mockParse).not.toHaveBeenCalled()
expect(copyFiles).not.toHaveBeenCalled()
})
Expand Down

0 comments on commit 78d1077

Please sign in to comment.