|
| 1 | +import { capitalizeWords } from '../support/utils'; |
| 2 | + |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +describe('Django admin workflows', () => { |
| 6 | + before(function () { |
| 7 | + // This ensures that Admin user's core user exists |
| 8 | + // because is only auto provisioned on first login to the frontend UI |
| 9 | + cy.login() |
| 10 | + cy.logout() |
| 11 | + }); |
| 12 | + |
| 13 | + beforeEach(function () { |
| 14 | + cy.loginAdminInterface() |
| 15 | + }); |
| 16 | + |
| 17 | + it('Configures menu', function () { |
| 18 | + cy.deleteModuleConfig("fe-core") |
| 19 | + cy.visit('/front') |
| 20 | + cy.get('div.MuiToolbar-root').should('exist') // default top toolbar menu |
| 21 | + |
| 22 | + cy.visit('/api/admin'); |
| 23 | + cy.contains('a', 'Module configurations').click() |
| 24 | + |
| 25 | + // Create menu config using fixture config file |
| 26 | + cy.contains('a', 'Add module configuration').click() |
| 27 | + cy.get('input[name="module"]').type('fe-core') |
| 28 | + cy.get('select[name="layer"]').select('frontend') |
| 29 | + cy.get('input[name="version"]').type(1) |
| 30 | + |
| 31 | + cy.fixture('menu-config-sp.json').then((config) => { |
| 32 | + const configString = JSON.stringify(config, null, 2); |
| 33 | + cy.get('textarea[name="config"]') |
| 34 | + .type(configString, { |
| 35 | + parseSpecialCharSequences: false, |
| 36 | + delay: 0 // Type faster |
| 37 | + }); |
| 38 | + cy.get('input[name="is_exposed"]').check() |
| 39 | + |
| 40 | + cy.get('input[value="Save"]').click() |
| 41 | + |
| 42 | + cy.visit('/front') |
| 43 | + cy.get('div.MuiDrawer-root').should('exist') // left drawer menu |
| 44 | + |
| 45 | + const expectedMenuItems = [ |
| 46 | + 'Social Protection', |
| 47 | + 'Dashboards', |
| 48 | + 'Payments', |
| 49 | + 'Grievance', |
| 50 | + 'Tasks Management', |
| 51 | + 'Administration', |
| 52 | + ] |
| 53 | + const programMenuText = 'programmes' |
| 54 | + const expectedSubMenuItems = [ |
| 55 | + 'Individuals', |
| 56 | + 'Groups', |
| 57 | + 'Import Data - API', |
| 58 | + programMenuText, |
| 59 | + ] |
| 60 | + cy.get('div.MuiDrawer-root').first().within(() => { |
| 61 | + cy.shouldHaveMenuItemsInOrder(expectedMenuItems) |
| 62 | + |
| 63 | + cy.contains('div[role="button"]', 'Social Protection').click(); |
| 64 | + |
| 65 | + cy.contains('div[role="button"]', 'Social Protection') |
| 66 | + .siblings('.MuiCollapse-root').within(() => { |
| 67 | + cy.shouldHaveMenuItemsInOrder(expectedSubMenuItems) |
| 68 | + |
| 69 | + // Verify submenu persistence selected state |
| 70 | + cy.contains('div[role="button"]', programMenuText).click(); |
| 71 | + cy.contains('div.Mui-selected[role="button"]', programMenuText); |
| 72 | + |
| 73 | + cy.contains('div[role="button"]', 'Individuals').click(); |
| 74 | + cy.contains('div.Mui-selected[role="button"]', 'Individuals'); |
| 75 | + |
| 76 | + cy.visit('/front/benefitPlans') |
| 77 | + cy.contains('div.Mui-selected[role="button"]', programMenuText); |
| 78 | + }) |
| 79 | + }); |
| 80 | + }) |
| 81 | + }) |
| 82 | + |
| 83 | + it('Configuring individual json schema reflects in advanced filters and upload template', function () { |
| 84 | + cy.setModuleConfig('individual', 'individual-config-minimal.json') |
| 85 | + |
| 86 | + cy.visit('/front/individuals') |
| 87 | + cy.contains('li', 'UPLOAD').click() |
| 88 | + cy.contains('button', 'Template').click() |
| 89 | + |
| 90 | + const downloadedFilename = path.join( |
| 91 | + Cypress.config('downloadsFolder'), |
| 92 | + 'individual_upload_template.csv' |
| 93 | + ); |
| 94 | + cy.readFile(downloadedFilename, { timeout: 15000 }).should('exist'); |
| 95 | + |
| 96 | + cy.readFile(downloadedFilename) |
| 97 | + .then(async (text) => { |
| 98 | + expect(text.length).to.be.greaterThan(0); |
| 99 | + expect(text).to.contain('able_bodied'); |
| 100 | + expect(text).to.contain('educated_level'); |
| 101 | + expect(text).to.contain('number_of_children'); |
| 102 | + }); |
| 103 | + |
| 104 | + cy.contains('button', 'Cancel').click() |
| 105 | + cy.contains('button', 'Advanced Filters').click() |
| 106 | + cy.get('div[role="dialog"] div.MuiSelect-select').click() |
| 107 | + cy.contains('li[role="option"]', 'Able bodied') |
| 108 | + cy.contains('li[role="option"]', 'Educated level') |
| 109 | + cy.contains('li[role="option"]', 'Number of children') |
| 110 | + }) |
| 111 | + |
| 112 | + it('Configures project activities', function () { |
| 113 | + const activities = [ |
| 114 | + 'E2E Tree Planting', |
| 115 | + 'E2E River Cleaning', |
| 116 | + 'E2E Soil Conservation', |
| 117 | + 'E2E Extra', |
| 118 | + ]; |
| 119 | + const newName = 'E2E Water Conservation' |
| 120 | + |
| 121 | + cy.deleteActivities(activities.concat([newName])) |
| 122 | + |
| 123 | + // Create |
| 124 | + activities.forEach(activityName => { |
| 125 | + cy.contains('a', 'Activities').click() |
| 126 | + cy.contains('a', 'Add Activity').click() |
| 127 | + cy.get('input[name="name"]').type(activityName) |
| 128 | + cy.get('input[value="Save"]').click() |
| 129 | + cy.contains('td.field-name', activityName) |
| 130 | + }) |
| 131 | + |
| 132 | + // Update |
| 133 | + cy.contains('td.field-name', 'E2E Soil Conservation') |
| 134 | + .parent('tr') |
| 135 | + .find('th.field-id a') |
| 136 | + .click(); |
| 137 | + cy.get('input[name="name"]').clear().type(newName) |
| 138 | + cy.get('input[value="Save"]').click() |
| 139 | + cy.contains('td.field-name', newName) |
| 140 | + .parent('tr') |
| 141 | + .within(() => { |
| 142 | + cy.get('td.field-name').should('contain', newName); |
| 143 | + cy.get('td.field-version').should('have.text', '2'); |
| 144 | + }); |
| 145 | + |
| 146 | + // Soft Delete |
| 147 | + cy.contains('td.field-name', 'E2E Extra') |
| 148 | + .parent('tr') |
| 149 | + .find('th.field-id a') |
| 150 | + .click(); |
| 151 | + cy.get('input[name="is_deleted"]').check() |
| 152 | + cy.get('input[value="Save"]').click() |
| 153 | + cy.contains('td.field-name', 'E2E Extra') |
| 154 | + .siblings('td.field-is_deleted') |
| 155 | + .find('img[alt="True"]') |
| 156 | + .should('exist'); |
| 157 | + }) |
| 158 | +}) |
| 159 | + |
0 commit comments