-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KMS-532: Create CSV output for schemes #17
Changes from 10 commits
c0963c7
a781118
665f0ab
b4b244a
ec4c489
37aed2d
25696aa
26caf80
8245798
3bbcbf1
6b1baca
9cc964d
93a49af
a4ce0c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { | ||
describe, | ||
expect, | ||
vi | ||
} from 'vitest' | ||
|
||
import { buildHierarchicalCsvPaths } from '../buildHierarchicalCsvPaths' | ||
import { formatCsvPath } from '../formatCsvPath' | ||
import { getNarrowers } from '../getNarrowers' | ||
import { isCsvLongNameFlag } from '../isCsvLongNameFlag' | ||
import { isCsvProviderUrlFlag } from '../isCsvProviderUrlFlag' | ||
|
||
// Mock the imported functions | ||
vi.mock('../getNarrowers') | ||
vi.mock('../formatCsvPath') | ||
vi.mock('../isCsvLongNameFlag') | ||
vi.mock('../isCsvProviderUrlFlag') | ||
|
||
describe('buildHierarchicalCsvPaths', () => { | ||
test('should traverse the graph and return paths', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should have describe('when.....) test('should....) structure for all our tests for consistency with MMT. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
const csvHeadersCount = 3 | ||
const providerUrlsMap = { | ||
'http://example.com/1': ['http://provider.com/1'], | ||
'http://example.com/2': ['http://provider.com/2'] | ||
} | ||
const longNamesMap = { | ||
'http://example.com/1': ['Long Name 1'], | ||
'http://example.com/2': ['Long Name 2'] | ||
} | ||
const scheme = 'testScheme' | ||
const rootNode = { | ||
narrowerPrefLabel: 'Root', | ||
uri: 'http://example.com/root' | ||
} | ||
const map = new Map() | ||
|
||
getNarrowers.mockReturnValueOnce([ | ||
{ | ||
narrowerPrefLabel: 'Child1', | ||
uri: 'http://example.com/1' | ||
}, | ||
{ | ||
narrowerPrefLabel: 'Child2', | ||
uri: 'http://example.com/2' | ||
} | ||
]) | ||
|
||
getNarrowers.mockReturnValue([]) | ||
|
||
isCsvLongNameFlag.mockReturnValue(true) | ||
isCsvProviderUrlFlag.mockReturnValue(true) | ||
|
||
const paths = [] | ||
// eslint-disable-next-line max-len | ||
await buildHierarchicalCsvPaths(csvHeadersCount, providerUrlsMap, longNamesMap, scheme, rootNode, map, [], paths) | ||
|
||
expect(paths).toHaveLength(2) | ||
expect(paths[0]).toEqual(['Child1', 'Long Name 1', 'http://provider.com/1', '1']) | ||
expect(paths[1]).toEqual(['Child2', 'Long Name 2', 'http://provider.com/2', '2']) | ||
}) | ||
|
||
test('should handle nodes without long names or provider URLs', async () => { | ||
const csvHeadersCount = 3 | ||
const providerUrlsMap = {} | ||
const longNamesMap = {} | ||
const scheme = 'testScheme' | ||
const rootNode = { | ||
narrowerPrefLabel: 'Root', | ||
uri: 'http://example.com/root' | ||
} | ||
const map = new Map() | ||
|
||
getNarrowers.mockReturnValueOnce([ | ||
{ | ||
narrowerPrefLabel: 'Child', | ||
uri: 'http://example.com/child' | ||
} | ||
]) | ||
|
||
getNarrowers.mockReturnValue([]) | ||
|
||
isCsvLongNameFlag.mockReturnValue(true) | ||
isCsvProviderUrlFlag.mockReturnValue(true) | ||
|
||
const paths = [] | ||
// eslint-disable-next-line max-len | ||
await buildHierarchicalCsvPaths(csvHeadersCount, providerUrlsMap, longNamesMap, scheme, rootNode, map, [], paths) | ||
|
||
expect(paths).toHaveLength(1) | ||
expect(paths[0]).toEqual(['Child', ' ', ' ', 'child']) | ||
}) | ||
|
||
test('should not include paths with only one node', async () => { | ||
const csvHeadersCount = 3 | ||
const providerUrlsMap = {} | ||
const longNamesMap = {} | ||
const scheme = 'testScheme' | ||
const rootNode = { | ||
narrowerPrefLabel: 'Root', | ||
uri: 'http://example.com/root' | ||
} | ||
const map = new Map() | ||
|
||
getNarrowers.mockReturnValue([]) | ||
|
||
const paths = [] | ||
// eslint-disable-next-line max-len | ||
await buildHierarchicalCsvPaths(csvHeadersCount, providerUrlsMap, longNamesMap, scheme, rootNode, map, [], paths) | ||
|
||
expect(paths).toHaveLength(0) | ||
}) | ||
|
||
test('should format CSV path for leaf nodes', async () => { | ||
const csvHeadersCount = 3 | ||
const providerUrlsMap = {} | ||
const longNamesMap = {} | ||
const scheme = 'testScheme' | ||
const rootNode = { | ||
narrowerPrefLabel: 'Root', | ||
uri: 'http://example.com/root' | ||
} | ||
const map = new Map() | ||
|
||
getNarrowers.mockReturnValueOnce([ | ||
{ | ||
narrowerPrefLabel: 'Child', | ||
uri: 'http://example.com/child' | ||
} | ||
]) | ||
|
||
getNarrowers.mockReturnValue([]) | ||
|
||
isCsvLongNameFlag.mockReturnValue(false) | ||
isCsvProviderUrlFlag.mockReturnValue(false) | ||
|
||
const paths = [] | ||
// eslint-disable-next-line max-len | ||
await buildHierarchicalCsvPaths(csvHeadersCount, providerUrlsMap, longNamesMap, scheme, rootNode, map, [], paths) | ||
|
||
expect(formatCsvPath).toHaveBeenCalledWith(scheme, csvHeadersCount, ['Child', 'child'], true) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is up with the tests, says this line through 134 are no longer covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might have issue with local branch KMS-532