|
| 1 | +import { drop, factory, primaryKey } from '@mswjs/data' |
| 2 | + |
| 3 | +import type { Bridge } from '@/api/__generated__' |
| 4 | +import { cy_interceptCoreE2E } from 'cypress/utils/intercept.utils.ts' |
| 5 | +import { bridgePage, loginPage, rjsf } from 'cypress/pages' |
| 6 | + |
| 7 | +describe('Bridges', () => { |
| 8 | + // Creating a mock storage for the Bridges |
| 9 | + const mswDB = factory({ |
| 10 | + bridge: { |
| 11 | + id: primaryKey(String), |
| 12 | + json: String, |
| 13 | + }, |
| 14 | + }) |
| 15 | + |
| 16 | + beforeEach(() => { |
| 17 | + drop(mswDB) |
| 18 | + |
| 19 | + cy_interceptCoreE2E() |
| 20 | + |
| 21 | + // TODO[NVL] Add support for the Event Log |
| 22 | + cy.intercept('GET', '/api/v1/management/bridges', (req) => { |
| 23 | + const allBridgeData = mswDB.bridge.getAll() |
| 24 | + const allBridges = allBridgeData.map<Bridge>((data) => ({ ...JSON.parse(data.json) })) |
| 25 | + req.reply(200, { items: allBridges }) |
| 26 | + }) |
| 27 | + |
| 28 | + cy.intercept<Bridge>('POST', '/api/v1/management/bridges', (req) => { |
| 29 | + const bridge = req.body |
| 30 | + const newBridgeData = mswDB.bridge.create({ |
| 31 | + id: bridge.id, |
| 32 | + json: JSON.stringify(bridge), |
| 33 | + }) |
| 34 | + req.reply(200, newBridgeData) |
| 35 | + }) |
| 36 | + |
| 37 | + cy.intercept<Bridge>('PUT', '/api/v1/management/bridges/**', (req) => { |
| 38 | + const bridge = req.body |
| 39 | + |
| 40 | + mswDB.bridge.update({ |
| 41 | + where: { |
| 42 | + id: { |
| 43 | + equals: bridge.id, |
| 44 | + }, |
| 45 | + }, |
| 46 | + |
| 47 | + data: { json: JSON.stringify(bridge) }, |
| 48 | + }) |
| 49 | + |
| 50 | + req.reply(200, '') |
| 51 | + }) |
| 52 | + |
| 53 | + cy.intercept<Bridge>('DELETE', '/api/v1/management/bridges/**', (req) => { |
| 54 | + const urlParts = req.url.split('/') |
| 55 | + const bridgeId = urlParts[urlParts.length - 1] |
| 56 | + |
| 57 | + mswDB.bridge.delete({ |
| 58 | + where: { |
| 59 | + id: { |
| 60 | + equals: bridgeId, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }) |
| 64 | + req.reply(200, '') |
| 65 | + }).as('deleteBridge') |
| 66 | + |
| 67 | + loginPage.visit('/app/mqtt-bridges') |
| 68 | + loginPage.loginButton.click() |
| 69 | + bridgePage.navLink.click() |
| 70 | + }) |
| 71 | + |
| 72 | + context('Bridge configuration', () => { |
| 73 | + // TODO[NVL] Add support for the toasts |
| 74 | + |
| 75 | + it('should render the landing page', () => { |
| 76 | + cy.location().should((loc) => { |
| 77 | + expect(loc.pathname).to.eq('/app/mqtt-bridges') |
| 78 | + }) |
| 79 | + |
| 80 | + bridgePage.pageHeader.should('have.text', 'MQTT bridges') |
| 81 | + bridgePage.pageHeaderSubTitle.should( |
| 82 | + 'have.text', |
| 83 | + 'MQTT bridges let you connect multiple MQTT brokers to enable seamless data sharing between different networks or systems.' |
| 84 | + ) |
| 85 | + bridgePage.addNewBridge.should('have.text', 'Add bridge connection') |
| 86 | + |
| 87 | + bridgePage.table.container.should('be.visible') |
| 88 | + bridgePage.table.status |
| 89 | + .should('have.attr', 'data-status', 'info') |
| 90 | + .should('have.text', 'No bridges currently created') |
| 91 | + }) |
| 92 | + |
| 93 | + it('should create a new bridge', () => { |
| 94 | + cy.location().should((loc) => { |
| 95 | + expect(loc.pathname).to.eq('/app/mqtt-bridges') |
| 96 | + }) |
| 97 | + |
| 98 | + bridgePage.table.status |
| 99 | + .should('have.attr', 'data-status', 'info') |
| 100 | + .should('have.text', 'No bridges currently created') |
| 101 | + |
| 102 | + bridgePage.addNewBridge.click() |
| 103 | + |
| 104 | + cy.location().should((loc) => { |
| 105 | + expect(loc.pathname).to.eq('/app/mqtt-bridges/new') |
| 106 | + }) |
| 107 | + |
| 108 | + bridgePage.config.panel.should('be.visible') |
| 109 | + bridgePage.config.title.should('have.text', 'Create a new bridge configuration') |
| 110 | + bridgePage.config.submitButton.should('have.text', 'Create the bridge') |
| 111 | + |
| 112 | + bridgePage.config.errorSummary.should('have.length', 3) |
| 113 | + bridgePage.config.errorSummaryFocus(0).should('exist') |
| 114 | + |
| 115 | + rjsf.field('id').input.should('not.have.value') |
| 116 | + rjsf.field('id').input.type('my-bridge') |
| 117 | + rjsf.field('host').input.type('my-host') |
| 118 | + rjsf.field('clientId').input.type('my-client-id') |
| 119 | + bridgePage.config.errorSummary.should('have.length', 0) |
| 120 | + |
| 121 | + bridgePage.config.submitButton.click() |
| 122 | + |
| 123 | + cy.location().should((loc) => { |
| 124 | + expect(loc.pathname).to.eq('/app/mqtt-bridges') |
| 125 | + }) |
| 126 | + |
| 127 | + bridgePage.table.rows.should('have.length', 1) |
| 128 | + bridgePage.table.cell(0, 'id').should('have.text', 'my-bridge') |
| 129 | + |
| 130 | + bridgePage.table.action(0, 'edit').click() |
| 131 | + |
| 132 | + rjsf.field('id').input.should('be.disabled') |
| 133 | + rjsf.field('port').input.clear().type('2999') |
| 134 | + |
| 135 | + bridgePage.config.submitButton.click() |
| 136 | + |
| 137 | + //TODO[NVL] Better create a subscription |
| 138 | + }) |
| 139 | + |
| 140 | + it('should create a new bridge and delete it', () => { |
| 141 | + cy.location().should((loc) => { |
| 142 | + expect(loc.pathname).to.eq('/app/mqtt-bridges') |
| 143 | + }) |
| 144 | + |
| 145 | + bridgePage.table.status |
| 146 | + .should('have.attr', 'data-status', 'info') |
| 147 | + .should('have.text', 'No bridges currently created') |
| 148 | + |
| 149 | + bridgePage.addNewBridge.click() |
| 150 | + |
| 151 | + bridgePage.config.panel.should('be.visible') |
| 152 | + bridgePage.config.submitButton.should('have.text', 'Create the bridge') |
| 153 | + |
| 154 | + rjsf.field('id').input.type('my-bridge') |
| 155 | + rjsf.field('host').input.type('my-host') |
| 156 | + rjsf.field('clientId').input.type('my-client-id') |
| 157 | + |
| 158 | + bridgePage.config.submitButton.click() |
| 159 | + |
| 160 | + bridgePage.table.action(0, 'delete').click() |
| 161 | + bridgePage.modal.dialog.should('be.visible') |
| 162 | + bridgePage.modal.title.should('have.text', 'Delete Bridge') |
| 163 | + bridgePage.modal.prompt.should('have.text', "Are you sure? You can't undo this action afterward.") |
| 164 | + bridgePage.modal.confirm.should('have.text', 'Delete') |
| 165 | + bridgePage.modal.confirm.click() |
| 166 | + |
| 167 | + cy.wait('@deleteBridge') |
| 168 | + bridgePage.table.status |
| 169 | + .should('have.attr', 'data-status', 'info') |
| 170 | + .should('have.text', 'No bridges currently created') |
| 171 | + }) |
| 172 | + }) |
| 173 | + |
| 174 | + context('Bridge in Workspace', () => { |
| 175 | + it('should create a bridge also in the Workspace', () => { |
| 176 | + bridgePage.table.status.should('have.text', 'No bridges currently created') |
| 177 | + |
| 178 | + bridgePage.addNewBridge.click() |
| 179 | + |
| 180 | + bridgePage.config.panel.should('be.visible') |
| 181 | + bridgePage.config.title.should('have.text', 'Create a new bridge configuration') |
| 182 | + bridgePage.config.submitButton.should('have.text', 'Create the bridge') |
| 183 | + |
| 184 | + rjsf.field('id').input.type('my-bridge') |
| 185 | + rjsf.field('host').input.type('my-host') |
| 186 | + rjsf.field('clientId').input.type('my-client-id') |
| 187 | + |
| 188 | + bridgePage.config.submitButton.click() |
| 189 | + |
| 190 | + //TODO[NVL] Better create a subscription |
| 191 | + }) |
| 192 | + }) |
| 193 | + |
| 194 | + context('Bridge in Event Log', () => {}) |
| 195 | + |
| 196 | + it('should be accessible', () => { |
| 197 | + cy.injectAxe() |
| 198 | + bridgePage.table.status.should('have.text', 'No bridges currently created') |
| 199 | + |
| 200 | + bridgePage.addNewBridge.click() |
| 201 | + |
| 202 | + bridgePage.config.panel.should('be.visible') |
| 203 | + bridgePage.config.title.should('have.text', 'Create a new bridge configuration') |
| 204 | + bridgePage.config.submitButton.should('have.text', 'Create the bridge') |
| 205 | + |
| 206 | + rjsf.field('id').input.type('my-bridge') |
| 207 | + rjsf.field('host').input.type('my-host') |
| 208 | + rjsf.field('clientId').input.type('my-client-id') |
| 209 | + |
| 210 | + bridgePage.config.submitButton.click() |
| 211 | + |
| 212 | + bridgePage.toast.close() |
| 213 | + |
| 214 | + bridgePage.table.action(0, 'edit').click() |
| 215 | + |
| 216 | + bridgePage.config.formTab(4).click() // Click on the "Subscriptions" tab |
| 217 | + |
| 218 | + cy.checkAccessibility() |
| 219 | + }) |
| 220 | +}) |
0 commit comments