-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1097 from dhis2/v40-backport/fix-back-slash
fix: remove extra slash in download links (v40)
- Loading branch information
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,10 @@ | |
}, | ||
"resolutions": { | ||
"@dhis2/ui": "^8.12.2" | ||
}, | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"src/**/*.js" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import useHrefs from './use-hrefs.js' | ||
|
||
jest.mock('@dhis2/app-runtime', () => ({ | ||
useConfig: () => ({ | ||
baseUrl: 'https://debug.dhis2.org/dev', | ||
apiVersion: '41', | ||
}), | ||
})) | ||
|
||
describe('use-hrefs', () => { | ||
const mockDate = 1694516945008 | ||
|
||
beforeEach(() => { | ||
jest.spyOn(Date, 'now').mockReturnValueOnce(mockDate) | ||
}) | ||
|
||
it('should generate correct urls', () => { | ||
const result = useHrefs({ | ||
endpoint: '/dataAnalysis/validationRules/report', | ||
fileTypes: ['pdf', 'xls', 'csv'], | ||
queryStr: undefined, | ||
}) | ||
expect(result.csv).toMatch( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.csv?t=${mockDate}` | ||
) | ||
expect(result.pdf).toEqual( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.pdf?t=${mockDate}` | ||
) | ||
expect(result.xls).toEqual( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.xls?t=${mockDate}` | ||
) | ||
}) | ||
it('should generate correct urls even if endpoint does not start with slash', () => { | ||
const result = useHrefs({ | ||
endpoint: 'dataAnalysis/validationRules/report', | ||
fileTypes: ['pdf', 'xls', 'csv'], | ||
queryStr: undefined, | ||
}) | ||
expect(result.csv).toMatch( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.csv?t=${mockDate}` | ||
) | ||
expect(result.pdf).toEqual( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.pdf?t=${mockDate}` | ||
) | ||
expect(result.xls).toEqual( | ||
`https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.xls?t=${mockDate}` | ||
) | ||
}) | ||
it('should generate correct urls even when passed query string', () => { | ||
const result = useHrefs({ | ||
endpoint: 'dataAnalysis/validationRules/report', | ||
fileTypes: ['pdf', 'xls', 'csv'], | ||
queryStr: 'locale=fr', | ||
}) | ||
expect(result.csv).toMatch( | ||
'https://debug.dhis2.org/dev/api/41/dataAnalysis/validationRules/report.csv?locale=fr' | ||
) | ||
}) | ||
}) |