|
| 1 | +import { formatTopicString } from '@/components/MQTT/topic-utils.ts' |
| 2 | +import { drop } from '@mswjs/data' |
| 3 | + |
| 4 | +import { loginPage, homePage, assetsPage, workspacePage, rjsf } from 'cypress/pages' |
| 5 | +import { cy_interceptCoreE2E } from 'cypress/utils/intercept.utils.ts' |
| 6 | +import { |
| 7 | + cy_interceptPulseWithMockDB, |
| 8 | + getPulseFactory, |
| 9 | + MOCK_MAIN_ASSET_MAPPER_ID, |
| 10 | +} from 'cypress/utils/intercept-pulse.utils.ts' |
| 11 | +import { assetMappingWizard } from 'cypress/pages/Pulse/AssetMappingWizardForm.ts' |
| 12 | +import { ONBOARDING } from 'cypress/utils/constants.utils.ts' |
| 13 | +import { assetMapperForm } from '../../pages/Workspace/AssetMapperFormPage.ts' |
| 14 | + |
| 15 | +describe('Pulse Assets', () => { |
| 16 | + const mswDB = getPulseFactory() |
| 17 | + |
| 18 | + beforeEach(() => { |
| 19 | + drop(mswDB) |
| 20 | + |
| 21 | + cy_interceptCoreE2E() |
| 22 | + cy_interceptPulseWithMockDB(mswDB, true, true) |
| 23 | + |
| 24 | + loginPage.visit('/app/workspace') |
| 25 | + loginPage.loginButton.click() |
| 26 | + homePage.navLink.click() |
| 27 | + }) |
| 28 | + |
| 29 | + describe('Assets Management', () => { |
| 30 | + it('should render assets', () => { |
| 31 | + homePage.taskSectionTitle(ONBOARDING.TASK_PULSE, 0).should('contain.text', 'Pulse is currently active.') |
| 32 | + |
| 33 | + homePage.pulseOnboarding.title.should('contain.text', 'Stay up-to-date with your asset mappings') |
| 34 | + |
| 35 | + const expectedTodoSummary = [2, 0, 0] |
| 36 | + homePage.pulseOnboarding.todos.should('have.length', expectedTodoSummary.length) |
| 37 | + homePage.pulseOnboarding.todosSummary.each(($element, idx) => { |
| 38 | + cy.wrap($element).should('contain.text', expectedTodoSummary[idx]) |
| 39 | + }) |
| 40 | + homePage.pulseOnboarding.todos.eq(0).find('a').click() |
| 41 | + |
| 42 | + assetsPage.location.should('equal', '/app/pulse-assets') |
| 43 | + assetsPage.table.rows.should('have.length', 2) |
| 44 | + |
| 45 | + assetsPage.search.input.type('1234') |
| 46 | + assetsPage.search.clear.click() |
| 47 | + |
| 48 | + assetsPage.search.filter(0).should('not.exist') |
| 49 | + assetsPage.search.filter('topic').type('topic{enter}') |
| 50 | + assetsPage.search.clearFilter('status').click() |
| 51 | + assetsPage.search.clearAll.click() |
| 52 | + |
| 53 | + assetsPage.table.actions(0).should('have.attr', 'aria-haspopup', 'menu') |
| 54 | + assetsPage.table.action(0, 'map').click() |
| 55 | + }) |
| 56 | + it.skip('should relate assets to asset mappers', () => {}) |
| 57 | + }) |
| 58 | + |
| 59 | + describe('Asset Mapping', () => { |
| 60 | + it('should create a new asset mapper', () => { |
| 61 | + homePage.taskSectionTitle(ONBOARDING.TASK_PULSE, 0).should('contain.text', 'Pulse is currently active.') |
| 62 | + homePage.pulseOnboarding.todos.eq(0).find('a').click() |
| 63 | + assetsPage.location.should('equal', '/app/pulse-assets') |
| 64 | + assetsPage.table.action(0, 'map').click() |
| 65 | + |
| 66 | + assetMappingWizard.form.should('be.visible').and('have.css', 'opacity', '1') |
| 67 | + assetMappingWizard.selectMapper.root.should('be.visible') |
| 68 | + assetMappingWizard.selectSources.root.should('not.exist') |
| 69 | + |
| 70 | + assetMappingWizard.selectMapper.label.should('have.text', 'Asset mapper') |
| 71 | + assetMappingWizard.selectMapper.moreInfo.should('have.attr', 'aria-label', 'More information') |
| 72 | + assetMappingWizard.selectMapper.select.should('be.visible') |
| 73 | + assetMappingWizard.selectMapper.value.should('not.exist') |
| 74 | + assetMappingWizard.selectMapper.placeholder.should('have.text', 'Type or select ...') |
| 75 | + assetMappingWizard.selectMapper.helperText.should('have.text', 'The asset mapper to use for the new mapping') |
| 76 | + |
| 77 | + assetMappingWizard.selectMapper.select.type('Non-existing mapper{enter}') |
| 78 | + assetMappingWizard.selectMapper.helperText.should( |
| 79 | + 'have.text', |
| 80 | + 'A new asset mapper will be created in the Workspace, with a predefined mapping for this asset' |
| 81 | + ) |
| 82 | + |
| 83 | + assetMappingWizard.selectSources.root.should('be.visible') |
| 84 | + assetMappingWizard.selectSources.label.should('have.text', 'Data Sources') |
| 85 | + assetMappingWizard.selectSources.moreInfo.should('have.attr', 'aria-label', 'More information') |
| 86 | + assetMappingWizard.selectSources.select.should('be.visible') |
| 87 | + assetMappingWizard.selectSources.values.should('have.length', 2) |
| 88 | + assetMappingWizard.selectSources.helperText.should( |
| 89 | + 'have.text', |
| 90 | + 'The data sources this new mapper will be initially connected to' |
| 91 | + ) |
| 92 | + assetMappingWizard.selectSources.select.type('my-adapter{enter}') |
| 93 | + assetMappingWizard.submit.click() |
| 94 | + assetsPage.toast.error.should('be.visible') |
| 95 | + }) |
| 96 | + |
| 97 | + it('should add an asset to an existing mapper', () => { |
| 98 | + assetsPage.navLink.click() |
| 99 | + assetsPage.location.should('equal', '/app/pulse-assets') |
| 100 | + |
| 101 | + // create the first default mapper |
| 102 | + assetsPage.table.action(0, 'map').click() |
| 103 | + assetMappingWizard.selectMapper.select.type('Non-existing mapper{enter}') |
| 104 | + assetMappingWizard.selectSources.select.type('my-adapter{enter}') |
| 105 | + assetMappingWizard.submit.click() |
| 106 | + |
| 107 | + assetsPage.toast.success.should('be.visible') |
| 108 | + assetsPage.toast.close() |
| 109 | + |
| 110 | + // TODO Check that the mapper has been created in the workspace |
| 111 | + workspacePage.location.should('equal', '/app/workspace') |
| 112 | + workspacePage.canvas.should('be.visible') |
| 113 | + workspacePage.toolbox.fit.click() |
| 114 | + |
| 115 | + workspacePage |
| 116 | + .combinerNodeContent(MOCK_MAIN_ASSET_MAPPER_ID) |
| 117 | + .title.should('have.text', 'Non-existing mapper (new)') |
| 118 | + workspacePage |
| 119 | + .combinerNodeContent(MOCK_MAIN_ASSET_MAPPER_ID) |
| 120 | + .topic.should('have.text', formatTopicString('test/topic')) |
| 121 | + workspacePage.combinerNode(MOCK_MAIN_ASSET_MAPPER_ID).click() |
| 122 | + workspacePage.combinerNode(MOCK_MAIN_ASSET_MAPPER_ID).dblclick() |
| 123 | + assetMapperForm.formTab(2).click() |
| 124 | + |
| 125 | + // delete the mapping, to allow editing of the name |
| 126 | + assetMapperForm.assetMappings.action(0, 'delete').click() |
| 127 | + assetMapperForm.field('mappings').table.noDataMessage.should('have.text', 'No data received yet.') |
| 128 | + |
| 129 | + assetMapperForm.formTab(0).click() |
| 130 | + assetMapperForm.field('name').input.clear().type('my mapper') |
| 131 | + assetMapperForm.submit.click() |
| 132 | + |
| 133 | + workspacePage.combinerNodeContent(MOCK_MAIN_ASSET_MAPPER_ID).title.should('have.text', 'my mapper') |
| 134 | + workspacePage.combinerNodeContent(MOCK_MAIN_ASSET_MAPPER_ID).topic.should('not.exist') |
| 135 | + }) |
| 136 | + |
| 137 | + it.skip('should remove an existing mapping', () => {}) |
| 138 | + it.skip('should change an existing mapping', () => {}) |
| 139 | + }) |
| 140 | +}) |
0 commit comments