|
| 1 | +import loginPage from '../Login.page'; |
| 2 | +import foldersPage from '../Folders.page'; |
| 3 | +import { generateRandmString } from '../helper-functions'; |
| 4 | +import { expect } from 'chai'; |
| 5 | +import {applicationLanguages} from '../../../src/app/common/const/application-languages.const'; |
| 6 | + |
| 7 | +const parentFolderName = generateRandmString(); |
| 8 | + |
| 9 | +describe('Folders - Add child folder', function () { |
| 10 | + before(() => { |
| 11 | + cy.visit('http://localhost:4200'); |
| 12 | + loginPage.login(); |
| 13 | + foldersPage.goToFoldersPage(); |
| 14 | + |
| 15 | + // Create a parent folder |
| 16 | + const description = generateRandmString(); |
| 17 | + foldersPage.newFolderBtn().click(); |
| 18 | + cy.wait(500); |
| 19 | + cy.get('#cancelCreateBtn').should('be.visible'); |
| 20 | + |
| 21 | + const da = applicationLanguages[0]; |
| 22 | + cy.get('#createLanguageSelector input').type(da.text); |
| 23 | + cy.get('ng-dropdown-panel .ng-option').contains(da.text).click(); |
| 24 | + cy.wait(500); |
| 25 | + |
| 26 | + const nameIndex = applicationLanguages.findIndex((x) => x.text === da.text); |
| 27 | + cy.get(`#createFolderNameTranslation_${nameIndex}`).type(parentFolderName); |
| 28 | + cy.wait(500); |
| 29 | + |
| 30 | + cy.get('#createLanguageSelector input').clear().type(da.text); |
| 31 | + cy.get('ng-dropdown-panel .ng-option').contains(da.text).click(); |
| 32 | + cy.wait(500); |
| 33 | + cy.get(`#createFolderDescriptionTranslation_${nameIndex} .NgxEditor__Content`).type(description); |
| 34 | + cy.wait(500); |
| 35 | + |
| 36 | + cy.get('#folderSaveBtn').click(); |
| 37 | + cy.get('#spinner-animation').should('not.exist', { timeout: 90000 }); |
| 38 | + foldersPage.newFolderBtn().should('be.visible'); |
| 39 | + cy.wait(500); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should create child folder with name and description', () => { |
| 43 | + const childName = generateRandmString(); |
| 44 | + const childDescription = generateRandmString(); |
| 45 | + |
| 46 | + // Count children before creation |
| 47 | + cy.get('mat-tree > mat-tree-node.children').then(($children) => { |
| 48 | + const rowCountBeforeCreation = $children.length; |
| 49 | + |
| 50 | + // Open parent folder menu and create child |
| 51 | + cy.get('.folder-tree-name').contains(parentFolderName).parents('mat-tree-node').find('button.mat-menu-trigger').click(); |
| 52 | + cy.get('#createFolderChildBtn').should('be.visible').click(); |
| 53 | + cy.get('#cancelCreateBtn').should('be.visible'); |
| 54 | + |
| 55 | + // Enter child folder details |
| 56 | + const da = applicationLanguages[0]; |
| 57 | + cy.get('#createLanguageSelector input').type(da.text); |
| 58 | + cy.get('ng-dropdown-panel .ng-option').contains(da.text).click(); |
| 59 | + cy.wait(500); |
| 60 | + |
| 61 | + const nameIndex = applicationLanguages.findIndex((x) => x.text === da.text); |
| 62 | + cy.get(`#createFolderNameTranslation_${nameIndex}`).type(childName); |
| 63 | + cy.wait(500); |
| 64 | + |
| 65 | + cy.get('#createLanguageSelector input').clear().type(da.text); |
| 66 | + cy.get('ng-dropdown-panel .ng-option').contains(da.text).click(); |
| 67 | + cy.wait(500); |
| 68 | + cy.get(`#createFolderDescriptionTranslation_${nameIndex} .NgxEditor__Content`).type(childDescription); |
| 69 | + cy.wait(500); |
| 70 | + |
| 71 | + // Save |
| 72 | + cy.get('#folderSaveBtn').click(); |
| 73 | + cy.get('#spinner-animation').should('not.exist', { timeout: 90000 }); |
| 74 | + foldersPage.newFolderBtn().should('be.visible'); |
| 75 | + cy.wait(500); |
| 76 | + |
| 77 | + // Expand parent to see children |
| 78 | + cy.get('.folder-tree-name').contains(parentFolderName).parents('mat-tree-node').find('button[aria-label="Toggle"]').then(($btn) => { |
| 79 | + if ($btn.attr('aria-expanded') === 'false') { |
| 80 | + cy.wrap($btn).click(); |
| 81 | + cy.wait(1000); |
| 82 | + } |
| 83 | + }); |
| 84 | + |
| 85 | + // Verify child was created |
| 86 | + cy.get('mat-tree > mat-tree-node.children').then(($childrenAfter) => { |
| 87 | + const rowCountAfterCreation = $childrenAfter.length; |
| 88 | + expect( |
| 89 | + rowCountAfterCreation, |
| 90 | + 'Number of child rows hasn\'t changed after creating new child folder' |
| 91 | + ).to.equal(rowCountBeforeCreation + 1); |
| 92 | + }); |
| 93 | + |
| 94 | + // Verify child folder exists |
| 95 | + cy.get('mat-tree-node.children .folder-tree-name').contains(childName).should('exist'); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + after('should delete folders', () => { |
| 100 | + // Delete parent folder (which will delete children too) |
| 101 | + cy.get('.folder-tree-name').contains(parentFolderName).parents('mat-tree-node').first().find('button.mat-menu-trigger').click(); |
| 102 | + cy.get('#deleteFolderTreeBtn').click(); |
| 103 | + cy.get('#saveDeleteBtn').should('be.visible').click(); |
| 104 | + cy.get('#spinner-animation').should('not.exist', { timeout: 90000 }); |
| 105 | + foldersPage.newFolderBtn().should('be.visible'); |
| 106 | + cy.wait(500); |
| 107 | + |
| 108 | + // Verify all folders deleted |
| 109 | + foldersPage.rowNum().then((count) => { |
| 110 | + expect(count, 'Folders not deleted').to.equal(0); |
| 111 | + }); |
| 112 | + }); |
| 113 | +}); |
0 commit comments