|
| 1 | +import { apps, productRegistration, productRegistrations, versions } from '../fixtures/consts' |
| 2 | + |
| 3 | +describe('Contextual Developer Analytics', () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.mockPrivatePortal() |
| 6 | + cy.mockApplications(apps, 4) |
| 7 | + cy.intercept('POST', '**/api/v2/stats*', { |
| 8 | + statusCode: 200, |
| 9 | + body: { |
| 10 | + records: [] |
| 11 | + }, |
| 12 | + delay: 0 |
| 13 | + }) |
| 14 | + }) |
| 15 | + |
| 16 | + const selectors = { |
| 17 | + chartsParent: '[data-testid="analytics-charts"]', |
| 18 | + dashboardDropdownLink: '[data-testid="dropdown-analytics-dashboard"]', |
| 19 | + dateTimePicker: '[data-testid="analytics-timepicker"]', |
| 20 | + metricCardsParent: '[data-testid="analytics-metric-cards"]', |
| 21 | + viewAnalyticsButton: '[data-testid="application-dashboard-button"]' |
| 22 | + } |
| 23 | + |
| 24 | + it('My Apps – displays displays metric cards if the feature flag is on', () => { |
| 25 | + cy.mockLaunchDarklyFlags([{ name: 'ma-1002-dev-portal-contextual-analytics', value: true }]) |
| 26 | + |
| 27 | + cy.mockApplications(apps, 4) |
| 28 | + |
| 29 | + cy.visit('/', { useOriginalFn: true }) |
| 30 | + cy.visit('/my-apps') |
| 31 | + |
| 32 | + cy.get(selectors.metricCardsParent).should('exist') |
| 33 | + cy.get(selectors.metricCardsParent).find('.metricscard').should('have.length', 3) |
| 34 | + |
| 35 | + cy.get('[data-testid="applications-table"]').find('.actions-badge').first().click() |
| 36 | + cy.get(selectors.dashboardDropdownLink).should('exist') |
| 37 | + }) |
| 38 | + |
| 39 | + it('My Apps – does not display metric cards or the analytics dropdown link if the feature flag is off', () => { |
| 40 | + cy.mockLaunchDarklyFlags([{ name: 'ma-1002-dev-portal-contextual-analytics', value: false }]) |
| 41 | + |
| 42 | + cy.mockApplications(apps, 5) |
| 43 | + cy.visit('/my-apps') |
| 44 | + |
| 45 | + cy.get(selectors.metricCardsParent).should('not.exist') |
| 46 | + cy.get('[data-testid="applications-table"]').find('.actions-badge').first().click() |
| 47 | + cy.get(selectors.dashboardDropdownLink).should('not.exist') |
| 48 | + }) |
| 49 | + |
| 50 | + it('My App details page – does not display Metrics Card, View Analytics button if the feature flag is off', () => { |
| 51 | + cy.mockLaunchDarklyFlags([{ name: 'ma-1002-dev-portal-contextual-analytics', value: true }]) |
| 52 | + cy.mockApplications(apps, 4) |
| 53 | + |
| 54 | + cy.intercept( |
| 55 | + 'GET', |
| 56 | + `**/api/v2/applications/${apps[0].id}`, { |
| 57 | + statusCode: 200, |
| 58 | + body: { ...apps[0] } |
| 59 | + } |
| 60 | + ).as('getSingleApplication') |
| 61 | + |
| 62 | + cy.mockApplicationWithCredAndReg(apps[0]) |
| 63 | + |
| 64 | + cy.visit(`/application/${apps[0].id}`) |
| 65 | + cy.get('[data-testid="analytics-metric-cards"]').should('not.exist') |
| 66 | + cy.get('[data-testid="application-dashboard-button"]').should('not.exist') |
| 67 | + }) |
| 68 | + |
| 69 | + it('App Dashboard - vitals elements load when contextual analytics feature flag is on', () => { |
| 70 | + cy.mockLaunchDarklyFlags([{ name: 'ma-1002-dev-portal-contextual-analytics', value: true }]) |
| 71 | + cy.mockApplications(apps, 4) |
| 72 | + |
| 73 | + cy.intercept('GET', `**/api/v2/applications/${apps[0].id}`, { |
| 74 | + statusCode: 200, |
| 75 | + body: apps[0], |
| 76 | + delay: 0 |
| 77 | + }).as('getSingleApplication') |
| 78 | + |
| 79 | + cy.intercept( |
| 80 | + 'GET', |
| 81 | + `**/api/v2/applications/${apps[0].id}/registrations*`, |
| 82 | + { |
| 83 | + body: { |
| 84 | + data: productRegistrations, |
| 85 | + meta: { |
| 86 | + page: { |
| 87 | + total: 1, |
| 88 | + number: 1, |
| 89 | + size: 1 |
| 90 | + } |
| 91 | + } |
| 92 | + }, |
| 93 | + delay: 0 |
| 94 | + } |
| 95 | + ).as('getApplicationRegistration') |
| 96 | + |
| 97 | + cy.visit('/my-apps') |
| 98 | + |
| 99 | + // Navigate to Application Dashboard page |
| 100 | + cy.get('[data-testid="applications-table"]').find('.actions-badge').first().click() |
| 101 | + cy.get(selectors.dashboardDropdownLink).first().click() |
| 102 | + |
| 103 | + // All application dashboard elements should be present |
| 104 | + cy.get('.analytics-filters').should('exist') |
| 105 | + cy.get(selectors.metricCardsParent).should('exist') |
| 106 | + cy.get(selectors.chartsParent).should('exist') |
| 107 | + |
| 108 | + // Check that the Service Versions filter bar contains at least one item |
| 109 | + const mockedServiceVersionName = `${productRegistrations[0].product_name} - ${productRegistrations[0].product_version_name}` |
| 110 | + |
| 111 | + cy.get('[data-testid="k-multiselect-input"]').should('exist').click() |
| 112 | + cy.get('.k-multiselect-item').first().should('contain', mockedServiceVersionName) |
| 113 | + }) |
| 114 | +}) |
0 commit comments