Skip to content

Commit 8aa1a58

Browse files
authored
implement csv export: automation (stolostron#3678)
Signed-off-by: Randy Bruno Piverger <rbrunopi@redhat.com>
1 parent 74c77a7 commit 8aa1a58

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

frontend/src/routes/Infrastructure/Automations/AnsibleAutomations.test.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,34 @@ describe('Automations page - operator checking', () => {
279279
await waitForNotText('Install the operator')
280280
})
281281
})
282+
283+
describe('Export from automation table', () => {
284+
test('export button should produce a file for download', async () => {
285+
nockIgnoreOperatorCheck()
286+
render(
287+
<TestIntegrationPage
288+
providerConnections={mockProviderConnections}
289+
clusterCurators={clusterCurators}
290+
subscriptions={mockSubscription}
291+
/>
292+
)
293+
window.URL.createObjectURL = jest.fn()
294+
window.URL.revokeObjectURL = jest.fn()
295+
const documentBody = document.body.appendChild
296+
const documentCreate = document.createElement('a').dispatchEvent
297+
298+
const anchorMocked = { href: '', click: jest.fn(), download: 'table-values', style: { display: '' } } as any
299+
const createElementSpyOn = jest.spyOn(document, 'createElement').mockReturnValueOnce(anchorMocked)
300+
document.body.appendChild = jest.fn()
301+
document.createElement('a').dispatchEvent = jest.fn()
302+
303+
await clickByLabel('export-search-result')
304+
await clickByText('Export as CSV')
305+
306+
expect(createElementSpyOn).toHaveBeenCalledWith('a')
307+
expect(anchorMocked.download).toContain('table-values')
308+
309+
document.body.appendChild = documentBody
310+
document.createElement('a').dispatchEvent = documentCreate
311+
})
312+
})

frontend/src/routes/Infrastructure/Automations/AnsibleAutomations.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ function AnsibleJobTemplateTable() {
100100
</Link>
101101
</span>
102102
),
103+
exportContent: (curator) => {
104+
return curator.metadata.name!
105+
},
103106
},
104107
{
105108
header: t('table.linkedCred'),
@@ -136,12 +139,18 @@ function AnsibleJobTemplateTable() {
136139
)
137140
} else return clusterCurator.spec.install.towerAuthSecret
138141
},
142+
exportContent: (clusterCurator) => {
143+
return clusterCurator.spec?.install?.towerAuthSecret
144+
},
139145
},
140146
{
141147
header: t('table.jobTemplate'),
142148
cell: (clusterCurator) => {
143149
return getTemplateJobsNum(clusterCurator)
144150
},
151+
exportContent: (clusterCurator) => {
152+
return getTemplateJobsNum(clusterCurator)
153+
},
145154
},
146155
{
147156
header: '',
@@ -292,6 +301,8 @@ function AnsibleJobTemplateTable() {
292301
}
293302
/>
294303
}
304+
showExportButton
305+
exportFilePrefix="ansibleautomation"
295306
></AcmTable>
296307
</Fragment>
297308
)

0 commit comments

Comments
 (0)