This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
349 additions
and
20 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
121 changes: 121 additions & 0 deletions
121
kibana-reports/public/components/main/__tests__/__utils__/main_utils_test_utils.tsx
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,121 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
export const reportTableMockResponse = [ | ||
{ | ||
_id: "123456", | ||
_index: "test", | ||
_score: 1, | ||
_source: { | ||
last_updated: 123456789, | ||
query_url: "test_query_url_value.com", | ||
report_definition: { | ||
delivery: { | ||
delivery_type: "Kibana user", | ||
delivery_params: { | ||
kibana_recipients: [] | ||
} | ||
}, | ||
report_params: { | ||
report_name: "Test report table response", | ||
description: "description", | ||
report_source: "Dashboard", | ||
core_params: { | ||
base_url: "test_base_url.com", | ||
header: "", | ||
footer: "", | ||
report_format: "pdf", | ||
time_duration: "PT30M", | ||
window_height: 800, | ||
window_width: 1200 | ||
} | ||
}, | ||
trigger: { | ||
trigger_type: "On demand" | ||
}, | ||
state: "Created", | ||
time_created: 123456780, | ||
time_from: 123456780, | ||
time_to: 123456799, | ||
} | ||
}, | ||
_type: "doc" | ||
} | ||
]; | ||
|
||
export const mockReportsTableItems = [ | ||
{ | ||
id: '123456', | ||
reportName: 'Test report table response', | ||
type: 'On demand', | ||
sender: '—', | ||
kibanaRecipients: '—', | ||
emailRecipients: '—', | ||
reportSource: 'Dashboard', | ||
timeCreated: undefined, | ||
state: undefined, | ||
url: 'test_query_url_value.com', | ||
format: 'pdf' | ||
} | ||
]; | ||
|
||
export const reportDefinitionsTableMockResponse = [ | ||
{ | ||
_index: 'report_definition', | ||
_type: '_doc', | ||
_id: '42MmKXUBDW-VXnk7pa6d', | ||
_score: 1, | ||
_source: { | ||
report_definition: { report_params: | ||
{ report_name: 'schedule definition', | ||
report_source: 'Dashboard', | ||
description: 'description', | ||
core_params: | ||
{ base_url: 'test_base_url.com', | ||
report_format: 'pdf', | ||
header: '', | ||
footer: '', | ||
time_duration: 'PT30M', | ||
window_width: 1200, | ||
window_height: 800 } }, | ||
delivery: | ||
{ delivery_type: 'Kibana user', | ||
delivery_params: { kibana_recipients: [] } }, | ||
trigger: | ||
{ trigger_type: 'Schedule', | ||
trigger_params: | ||
{ enabled_time: 1602713178321, | ||
schedule: { | ||
period: 1, | ||
interval: 'DAYS' | ||
}, | ||
schedule_type: 'Recurring', | ||
enabled: false } }, | ||
time_created: 1602713199604, | ||
last_updated: 1602713211007, | ||
status: 'Disabled' } | ||
} | ||
} | ||
]; | ||
|
||
export const reportDefinitionsTableMockContent = [ { id: '42MmKXUBDW-VXnk7pa6d', | ||
reportName: 'schedule definition', | ||
type: 'Schedule', | ||
owner: '—', | ||
source: 'Dashboard', | ||
baseUrl: 'test_base_url.com', | ||
lastUpdated: 1602713211007, | ||
details: 'Recurring', | ||
status: 'Disabled' } ] |
132 changes: 132 additions & 0 deletions
132
kibana-reports/public/components/main/__tests__/main_utils.test.tsx
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,132 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import { | ||
humanReadableDate, | ||
extractFilename, | ||
extractFileFormat, | ||
getFileFormatPrefix, | ||
addReportsTableContent, | ||
addReportDefinitionsTableContent, | ||
removeDuplicatePdfFileFormat, | ||
readStreamToFile, | ||
generateReport, | ||
generateReportById, | ||
} from '../main_utils'; | ||
import { | ||
reportDefinitionsTableMockResponse, | ||
mockReportsTableItems, | ||
reportTableMockResponse, | ||
reportDefinitionsTableMockContent, | ||
} from './__utils__/main_utils_test_utils'; | ||
import sinon from 'sinon'; | ||
import httpClientMock from '../../../../test/httpMockClient'; | ||
|
||
describe('main_utils tests', () => { | ||
global.URL.createObjectURL = jest.fn(); | ||
let mockElement = document.createElement('a'); | ||
mockElement.download = 'string'; | ||
mockElement.click = function name() {}; | ||
sinon.stub(document, 'createElement').returns(mockElement); | ||
|
||
test('test humanReadableDate', () => { | ||
const readableDate = new Date(2018, 11, 24, 10, 33, 30); | ||
const humanReadable = humanReadableDate(readableDate); | ||
|
||
expect(humanReadable).toBe('Mon Dec 24 2018 @ 10:33:30 AM'); | ||
}); | ||
|
||
test('test extractFileName', () => { | ||
const fullFile = 'test_file_name_extracted_correctly.pdf'; | ||
const fileName = extractFilename(fullFile); | ||
|
||
expect(fileName).toBe('test_file_name_extracted_correctly'); | ||
}); | ||
|
||
test('test extractFileFormat', () => { | ||
const fullFile = 'test_file_format_extracted_correctly.png'; | ||
const fileFormat = extractFileFormat(fullFile); | ||
|
||
expect(fileFormat).toBe('png'); | ||
}); | ||
|
||
test('test getFileFormatPrefix', () => { | ||
const fileFormat = 'pdf'; | ||
const fileFormatPrefix = getFileFormatPrefix(fileFormat); | ||
|
||
expect(fileFormatPrefix).toBe('data:pdf;base64,'); | ||
}); | ||
|
||
test('test addReportsTableContent', () => { | ||
const reportsTableItems = addReportsTableContent(reportTableMockResponse); | ||
|
||
expect(reportsTableItems).toStrictEqual(mockReportsTableItems); | ||
}); | ||
|
||
test('test addReportDefinitionsTableContent', () => { | ||
const reportDefinitionsTableItems = addReportDefinitionsTableContent( | ||
reportDefinitionsTableMockResponse | ||
); | ||
|
||
expect(reportDefinitionsTableItems).toStrictEqual( | ||
reportDefinitionsTableMockContent | ||
); | ||
}); | ||
|
||
test('test removeDuplicatePdfFileFormat', () => { | ||
const duplicateFormat = 'test_duplicate_remove.pdf.pdf'; | ||
const duplicateRemoved = removeDuplicatePdfFileFormat(duplicateFormat); | ||
|
||
expect(duplicateRemoved).toBe('test_duplicate_remove.pdf'); | ||
}); | ||
|
||
test('test readStreamToFile csv compile', () => { | ||
const stream = | ||
'category,customer_gender\n' + | ||
'c1,Male\n' + | ||
'c2,Male\n' + | ||
'c3,Male\n' + | ||
'c4,Male\n' + | ||
'c5,Male'; | ||
|
||
const fileFormat = 'csv'; | ||
const fileName = 'test_data_report.csv'; | ||
readStreamToFile(stream, fileFormat, fileName); | ||
}); | ||
|
||
test('test readStreamToFile pdf compile', () => { | ||
const stream = 'data:pdf;base64,zxvniaorbguw40absdoanlsdf'; | ||
const fileFormat = 'pdf'; | ||
const fileName = 'test_pdf_report.pdf'; | ||
readStreamToFile(stream, fileFormat, fileName); | ||
}); | ||
|
||
test('test generateReport compile', () => { | ||
const metadata = {}; | ||
generateReport(metadata, httpClientMock); | ||
}); | ||
|
||
test('test generateReportById compile', () => { | ||
const reportId = '1'; | ||
const handleSuccessToast = jest.fn(); | ||
const handleErrorToast = jest.fn(); | ||
generateReportById( | ||
reportId, | ||
httpClientMock, | ||
handleSuccessToast, | ||
handleErrorToast | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.