diff --git a/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/ChangeHistory.test.tsx b/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/ChangeHistory.test.tsx index 60665bc14df..194acbea0a6 100644 --- a/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/ChangeHistory.test.tsx +++ b/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/ChangeHistory.test.tsx @@ -5,10 +5,9 @@ import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router-dom'; import i18n from 'ReactI18'; import store from 'store'; -import { Pipeline } from 'types/api/pipeline/def'; -import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse'; import ChangeHistory from '../index'; +import { pipelineData, pipelineDataHistory } from './testUtils'; const queryClient = new QueryClient({ defaultOptions: { @@ -20,194 +19,69 @@ const queryClient = new QueryClient({ describe('ChangeHistory test', () => { it('should render changeHistory correctly', () => { - // const pipelinedata: Pipeline = { - // active: true, - // createdBy: 'admin', - // deployResult: 'random_data', - // deployStatus: 'random_data', - // disabled: false, - // elementType: 'random_data', - // history: [], - // id: v4(), - // isValid: true, - // lastConf: 'random_data', - // lastHash: 'random_data', - // pipelines: [], - // version: 1, - // }; - const pipelinedata: Pipeline = { - id: '8e196a3c-8737-46d2-8b62-264353b7b9aa', - version: 24, - elementType: 'log_pipelines', - active: false, - is_valid: false, - disabled: false, - deployStatus: 'DEPLOYED', - deployResult: 'Deployment was successful', - lastHash: 'log_pipelines:24', - lastConf: - '[{"id":"1917badc-580c-42fe-a959-cdf895d4f27b","orderId":1,"name":"hotrod logs parser","alias":"hotrodlogsparser","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"container_name","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"hotrod","op":"="}]},"config":[{"type":"regex_parser","id":"parsetext(regex)","output":"parseattribsjson","on_error":"send","orderId":1,"enabled":true,"name":"parse text (regex)","parse_to":"attributes","regex":".+\\\\t+(?P\\u003clog_level\\u003e.+)\\\\t+(?P\\u003clocation\\u003e.+)\\\\t+(?P\\u003cmessage\\u003e.+)\\\\t+(?P\\u003cattribs_json\\u003e.+)","parse_from":"body"},{"type":"json_parser","id":"parseattribsjson","output":"removetempattribs_json","orderId":2,"enabled":true,"name":"parse attribs json","parse_to":"attributes","parse_from":"attributes.attribs_json"},{"type":"remove","id":"removetempattribs_json","output":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":3,"enabled":true,"name":"remove temp attribs_json","field":"attributes.attribs_json"},{"type":"add","id":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":4,"enabled":true,"name":"test add ","field":"resource[\\"container.name\\"]","value":"hotrod"}],"createdBy":"prashant@signoz.io","createdAt":"2024-01-02T13:56:02.858300964Z"},{"id":"6aea8303-4a62-4c62-ba07-f16ff8f2174a","orderId":2,"name":"Logs Parser - Pranay - Customer Service","alias":"LogsParser-Pranay-CustomerService","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"service","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"customer","op":"="}]},"config":[{"type":"grok_parser","id":"TestPranay","on_error":"send","orderId":1,"enabled":true,"name":"Test Pranay","parse_to":"attributes","pattern":"^%{DATE:date}Z INFO customer/database.go:73 Loading customer {\\"service\\": \\"customer\\", \\"component\\": \\"mysql\\", \\"trace_id\\": \\"227e184cb1263724\\", \\"span_id\\": \\"1427a3fcad8b1514\\", \\"customer_id\\": \\"567\\"}","parse_from":"body"}],"createdBy":"prashant@signoz.io","createdAt":"2024-01-02T13:56:02.863764227Z"}]', - createdBy: '5e9681b1-16c9-4f7a-9a62-48904d73d9c9', - pipelines: [ - { - id: '1917badc-580c-42fe-a959-cdf895d4f27b', - orderId: 1, - name: 'hotrod logs parser', - alias: 'hotrodlogsparser', - description: 'Trying to test Logs Pipeline feature', - enabled: true, - filter: { - op: 'AND', - items: [ - { - key: { - key: 'container_name', - dataType: DataTypes.String, - type: 'tag', - isColumn: false, - isJSON: false, - }, - id: 'sampleid', - value: 'hotrod', - op: '=', - }, - ], - }, - config: [ - { - type: 'regex_parser', - id: 'parsetext(regex)', - output: 'parseattribsjson', - on_error: 'send', - orderId: 1, - enabled: true, - name: 'parse text (regex)', - parse_to: 'attributes', - regex: - '.+\\t+(?P.+)\\t+(?P.+)\\t+(?P.+)\\t+(?P.+)', - parse_from: 'body', - }, - { - type: 'json_parser', - id: 'parseattribsjson', - output: 'removetempattribs_json', - orderId: 2, - enabled: true, - name: 'parse attribs json', - parse_to: 'attributes', - parse_from: 'attributes.attribs_json', - }, - { - type: 'remove', - id: 'removetempattribs_json', - output: 'c2062723-895e-4614-ba38-29c5d5ee5927', - orderId: 3, - enabled: true, - name: 'remove temp attribs_json', - field: 'attributes.attribs_json', - }, - { - type: 'add', - id: 'c2062723-895e-4614-ba38-29c5d5ee5927', - orderId: 4, - enabled: true, - name: 'test add ', - field: 'resource["container.name"]', - value: 'hotrod', - }, - ], - createdBy: 'prashant@signoz.io', - createdAt: '2024-01-02T13:56:02.858300964Z', - }, - { - id: '6aea8303-4a62-4c62-ba07-f16ff8f2174a', - orderId: 2, - name: 'Logs Parser - Pranay - Customer Service', - alias: 'LogsParser-Pranay-CustomerService', - description: 'Trying to test Logs Pipeline feature', - enabled: true, - filter: { - op: 'AND', - items: [ - { - key: { - key: 'service', - dataType: DataTypes.String, - type: 'tag', - isColumn: false, - isJSON: false, - }, - id: 'sample-test-1', - value: 'customer', - op: '=', - }, - ], - }, - config: [ - { - type: 'grok_parser', - id: 'TestPranay', - on_error: 'send', - orderId: 1, - enabled: true, - name: 'Test Pranay', - parse_to: 'attributes', - pattern: - '^%{DATE:date}Z INFO customer/database.go:73 Loading customer {"service": "customer", "component": "mysql", "trace_id": "227e184cb1263724", "span_id": "1427a3fcad8b1514", "customer_id": "567"}', - parse_from: 'body', - }, - ], - createdBy: 'prashant@signoz.io', - createdAt: '2024-01-02T13:56:02.863764227Z', - }, - ], - history: [ - { - id: '8e196a3c-8737-46d2-8b62-264353b7b9aa', - version: 24, - elementType: 'log_pipelines', - active: false, - isValid: false, - disabled: false, - deployStatus: 'DEPLOYED', - deployResult: 'Deployment was successful', - lastHash: 'log_pipelines:24', - lastConf: - '[{"id":"1917badc-580c-42fe-a959-cdf895d4f27b","orderId":1,"name":"hotrod logs parser","alias":"hotrodlogsparser","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"container_name","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"hotrod","op":"="}]},"config":[{"type":"regex_parser","id":"parsetext(regex)","output":"parseattribsjson","on_error":"send","orderId":1,"enabled":true,"name":"parse text (regex)","parse_to":"attributes","regex":".+\\\\t+(?P\\u003clog_level\\u003e.+)\\\\t+(?P\\u003clocation\\u003e.+)\\\\t+(?P\\u003cmessage\\u003e.+)\\\\t+(?P\\u003cattribs_json\\u003e.+)","parse_from":"body"},{"type":"json_parser","id":"parseattribsjson","output":"removetempattribs_json","orderId":2,"enabled":true,"name":"parse attribs json","parse_to":"attributes","parse_from":"attributes.attribs_json"},{"type":"remove","id":"removetempattribs_json","output":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":3,"enabled":true,"name":"remove temp attribs_json","field":"attributes.attribs_json"},{"type":"add","id":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":4,"enabled":true,"name":"test add ","field":"resource[\\"container.name\\"]","value":"hotrod"}],"createdBy":"prashant@signoz.io","createdAt":"2024-01-02T13:56:02.858300964Z"},{"id":"6aea8303-4a62-4c62-ba07-f16ff8f2174a","orderId":2,"name":"Logs Parser - Pranay - Customer Service","alias":"LogsParser-Pranay-CustomerService","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"service","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"customer","op":"="}]},"config":[{"type":"grok_parser","id":"TestPranay","on_error":"send","orderId":1,"enabled":true,"name":"Test Pranay","parse_to":"attributes","pattern":"^%{DATE:date}Z INFO customer/database.go:73 Loading customer {\\"service\\": \\"customer\\", \\"component\\": \\"mysql\\", \\"trace_id\\": \\"227e184cb1263724\\", \\"span_id\\": \\"1427a3fcad8b1514\\", \\"customer_id\\": \\"567\\"}","parse_from":"body"}],"createdBy":"prashant@signoz.io","createdAt":"2024-01-02T13:56:02.863764227Z"}]', - createdBy: '5e9681b1-16c9-4f7a-9a62-48904d73d9c9', - createdByName: 'Prashant 🙎‍♂️', - createdAt: '2024-01-02T13:56:02Z', - }, - { - id: '0b934310-0aea-4806-94b9-7750e3c6935e', - version: 23, - elementType: 'log_pipelines', - active: false, - isValid: false, - disabled: false, - deployStatus: 'DEPLOYED', - deployResult: 'Deployment was successful', - lastHash: 'log_pipelines:23', - lastConf: - '[{"id":"82051f9e-22f8-4d9d-bca7-35bd32715697","orderId":1,"name":"hotrod logs parser","alias":"hotrodlogsparser","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"container_name","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"hotrod","op":"="}]},"config":[{"type":"regex_parser","id":"parsetext(regex)","output":"parseattribsjson","on_error":"send","orderId":1,"enabled":true,"name":"parse text (regex)","parse_to":"attributes","regex":".+\\\\t+(?P\\u003clog_level\\u003e.+)\\\\t+(?P\\u003clocation\\u003e.+)\\\\t+(?P\\u003cmessage\\u003e.+)\\\\t+(?P\\u003cattribs_json\\u003e.+)","parse_from":"body"},{"type":"json_parser","id":"parseattribsjson","output":"removetempattribs_json","orderId":2,"enabled":true,"name":"parse attribs json","parse_to":"attributes","parse_from":"attributes.attribs_json"},{"type":"remove","id":"removetempattribs_json","output":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":3,"enabled":true,"name":"remove temp attribs_json","field":"attributes.attribs_json"},{"type":"add","id":"c2062723-895e-4614-ba38-29c5d5ee5927","orderId":4,"enabled":true,"name":"test add ","field":"attributes.test","value":"EXPR((attributes.temp?.request_context?.scraper ?? [nil])[0])"}],"createdBy":"prashant@signoz.io","createdAt":"2023-12-29T12:59:20.628696628Z"},{"id":"c9076864-788a-4c5d-bc91-0ab44bbf0b87","orderId":2,"name":"Logs Parser - Pranay - Customer Service","alias":"LogsParser-Pranay-CustomerService","description":"Trying to test Logs Pipeline feature","enabled":true,"filter":{"op":"AND","items":[{"key":{"key":"service","dataType":"string","type":"tag","isColumn":false,"isJSON":false},"value":"customer","op":"="}]},"config":[{"type":"grok_parser","id":"TestPranay","on_error":"send","orderId":1,"enabled":true,"name":"Test Pranay","parse_to":"attributes","pattern":"^%{DATE:date}Z INFO customer/database.go:73 Loading customer {\\"service\\": \\"customer\\", \\"component\\": \\"mysql\\", \\"trace_id\\": \\"227e184cb1263724\\", \\"span_id\\": \\"1427a3fcad8b1514\\", \\"customer_id\\": \\"567\\"}","parse_from":"body"}],"createdBy":"prashant@signoz.io","createdAt":"2023-12-29T12:59:20.635863965Z"}]', - createdBy: '5e9681b1-16c9-4f7a-9a62-48904d73d9c9', - createdByName: 'Prashant 🙎‍♂️', - createdAt: '2023-12-29T12:59:20Z', - }, - ], - }; + const { getAllByText, getByText } = render( + + + + + + + + + , + ); - const { asFragment } = render( + // change History table headers + [ + 'Version', + 'Deployment Stage', + 'Last Deploy Message', + 'Last Deployed Time', + 'Edited by', + ].forEach((text) => expect(getByText(text)).toBeInTheDocument()); + + // table content + expect(getAllByText('test-user').length).toBe(2); + expect(getAllByText('Deployment was successful').length).toBe(2); + }); + + it('test deployment stage and icon based on history data', () => { + const { getByText, container } = render( - + , ); - expect(asFragment()).toMatchSnapshot(); + + // assertion for different deployment stages + expect(container.querySelector('[data-icon="loading"]')).toBeInTheDocument(); + expect(getByText('In Progress')).toBeInTheDocument(); + + expect( + container.querySelector('[data-icon="exclamation-circle"]'), + ).toBeInTheDocument(); + expect(getByText('Dirty')).toBeInTheDocument(); + + expect( + container.querySelector('[data-icon="close-circle"]'), + ).toBeInTheDocument(); + expect(getByText('Failed')).toBeInTheDocument(); + + expect( + container.querySelector('[data-icon="minus-circle"]'), + ).toBeInTheDocument(); + expect(getByText('Unknown')).toBeInTheDocument(); + + expect(container.querySelectorAll('.ant-table-row').length).toBe(5); }); }); diff --git a/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/__snapshots__/ChangeHistory.test.tsx.snap b/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/__snapshots__/ChangeHistory.test.tsx.snap deleted file mode 100644 index 84a715d91ef..00000000000 --- a/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/__snapshots__/ChangeHistory.test.tsx.snap +++ /dev/null @@ -1,279 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ChangeHistory test should render changeHistory correctly 1`] = ` - - .c0 { - margin-top: 3rem; -} - -.c1 { - padding: 0.625rem; -} - -
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Version - - Deployment Stage - - Last Deploy Message - - Last Deployed Time - - Edited by -
- 24 - - - - - - Deployed - - - Deployment was successful - - - January 02, 2024 07:26 PM - - - Prashant 🙎‍♂️ -
- 23 - - - - - - Deployed - - - Deployment was successful - - - December 29, 2023 06:29 PM - - - Prashant 🙎‍♂️ -
-
-
-
-
    -
  • - -
  • -
  • - - 1 - -
  • -
  • - -
  • -
-
-
-
-
-
-`; diff --git a/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/testUtils.ts b/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/testUtils.ts new file mode 100644 index 00000000000..900cb4f12d5 --- /dev/null +++ b/frontend/src/container/PipelinePage/Layouts/ChangeHistory/tests/testUtils.ts @@ -0,0 +1,240 @@ +/* eslint-disable sonarjs/no-duplicate-string */ +import { Pipeline } from 'types/api/pipeline/def'; +import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse'; + +export const pipelineData: Pipeline = { + id: 'test-id-1', + version: 24, + elementType: 'log_pipelines', + active: false, + is_valid: false, + disabled: false, + deployStatus: 'DEPLOYED', + deployResult: 'Deployment was successful', + lastHash: 'log_pipelines:24', + lastConf: 'oiwernveroi', + createdBy: 'test-created-by', + pipelines: [ + { + id: 'test-id-2', + orderId: 1, + name: 'hotrod logs parser', + alias: 'hotrodlogsparser', + description: 'Trying to test Logs Pipeline feature', + enabled: true, + filter: { + op: 'AND', + items: [ + { + key: { + key: 'container_name', + dataType: DataTypes.String, + type: 'tag', + isColumn: false, + isJSON: false, + }, + id: 'sampleid', + value: 'hotrod', + op: '=', + }, + ], + }, + config: [ + { + type: 'regex_parser', + id: 'parsetext(regex)', + output: 'parseattribsjson', + on_error: 'send', + orderId: 1, + enabled: true, + name: 'parse text (regex)', + parse_to: 'attributes', + regex: + '.+\\t+(?P.+)\\t+(?P.+)\\t+(?P.+)\\t+(?P.+)', + parse_from: 'body', + }, + { + type: 'json_parser', + id: 'parseattribsjson', + output: 'removetempattribs_json', + orderId: 2, + enabled: true, + name: 'parse attribs json', + parse_to: 'attributes', + parse_from: 'attributes.attribs_json', + }, + { + type: 'remove', + id: 'removetempattribs_json', + output: 'c2062723-895e-4614-ba38-29c5d5ee5927', + orderId: 3, + enabled: true, + name: 'remove temp attribs_json', + field: 'attributes.attribs_json', + }, + { + type: 'add', + id: 'c2062723-895e-4614-ba38-29c5d5ee5927', + orderId: 4, + enabled: true, + name: 'test add ', + field: 'resource["container.name"]', + value: 'hotrod', + }, + ], + createdBy: 'test@email', + createdAt: '2024-01-02T13:56:02.858300964Z', + }, + { + id: 'tes-id-1', + orderId: 2, + name: 'Logs Parser - test - Customer Service', + alias: 'LogsParser-test-CustomerService', + description: 'Trying to test Logs Pipeline feature', + enabled: true, + filter: { + op: 'AND', + items: [ + { + key: { + key: 'service', + dataType: DataTypes.String, + type: 'tag', + isColumn: false, + isJSON: false, + }, + id: 'sample-test-1', + value: 'customer', + op: '=', + }, + ], + }, + config: [ + { + type: 'grok_parser', + id: 'Testtest', + on_error: 'send', + orderId: 1, + enabled: true, + name: 'Test test', + parse_to: 'attributes', + pattern: + '^%{DATE:date}Z INFO customer/database.go:73 Loading customer {"service": "customer", "component": "mysql", "trace_id": "test-id", "span_id": "1427a3fcad8b1514", "customer_id": "567"}', + parse_from: 'body', + }, + ], + createdBy: 'test@email', + createdAt: '2024-01-02T13:56:02.863764227Z', + }, + ], + history: [ + { + id: 'test-id-4', + version: 24, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'DEPLOYED', + deployResult: 'Deployment was successful', + lastHash: 'log_pipelines:24', + lastConf: 'eovineroiv', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2024-01-02T13:56:02Z', + }, + { + id: 'test-4', + version: 23, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'DEPLOYED', + deployResult: 'Deployment was successful', + lastHash: 'log_pipelines:23', + lastConf: 'eivrounreovi', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2023-12-29T12:59:20Z', + }, + ], +}; + +export const pipelineDataHistory: Pipeline['history'] = [ + { + id: 'test-id-4', + version: 24, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'DEPLOYED', + deployResult: 'Deployment was successful', + lastHash: 'log_pipelines:24', + lastConf: 'eovineroiv', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2024-01-02T13:56:02Z', + }, + { + id: 'test-4', + version: 23, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'IN_PROGRESS', + deployResult: 'Deployment is in progress', + lastHash: 'log_pipelines:23', + lastConf: 'eivrounreovi', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2023-12-29T12:59:20Z', + }, + { + id: 'test-4-1', + version: 25, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'DIRTY', + deployResult: 'Deployment is dirty', + lastHash: 'log_pipelines:23', + lastConf: 'eivrounreovi', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2023-12-29T12:59:20Z', + }, + { + id: 'test-4-2', + version: 26, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'FAILED', + deployResult: 'Deployment failed', + lastHash: 'log_pipelines:23', + lastConf: 'eivrounreovi', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2023-12-29T12:59:20Z', + }, + { + id: 'test-4-3', + version: 27, + elementType: 'log_pipelines', + active: false, + isValid: false, + disabled: false, + deployStatus: 'UNKNOWN', + deployResult: '', + lastHash: 'log_pipelines:23', + lastConf: 'eivrounreovi', + createdBy: 'test-created-by', + createdByName: 'test-user', + createdAt: '2023-12-29T12:59:20Z', + }, +];