|
| 1 | +// Import utils |
| 2 | +import testContext from '@utils/testContext'; |
| 3 | +import {expect} from 'chai'; |
| 4 | +import type {BrowserContext, Page} from 'playwright'; |
| 5 | + |
| 6 | +import { |
| 7 | + // Import BO pages |
| 8 | + boDashboardPage, |
| 9 | + boLoginPage, |
| 10 | + boDesignLinkListPage, |
| 11 | + boDesignLinkListCreatePage, |
| 12 | + // Import FO pages |
| 13 | + foHummingbirdHomePage, |
| 14 | + // Import data |
| 15 | + dataHooks, |
| 16 | + FakerLinkWidget, |
| 17 | + type LinkWidgetPage, |
| 18 | + utilsPlaywright, |
| 19 | +} from '@prestashop-core/ui-testing'; |
| 20 | + |
| 21 | +const baseContext: string = 'functional_BO_design_linkList_CRUDLinkBlock'; |
| 22 | + |
| 23 | +/* |
| 24 | +Create link block |
| 25 | +Check existence in FO |
| 26 | +Delete link block |
| 27 | + */ |
| 28 | +describe('BO - Design - Link block : CRUD link block', async () => { |
| 29 | + let browserContext: BrowserContext; |
| 30 | + let page: Page; |
| 31 | + let numberOfLinkWidgetInFooter: number = 0; |
| 32 | + let linkId: number = 1; |
| 33 | + const linkBlockData: FakerLinkWidget = new FakerLinkWidget({ |
| 34 | + name: 'Footer test block', |
| 35 | + frName: 'Test block dans le footer', |
| 36 | + hook: dataHooks.displayFooter, |
| 37 | + contentPages: ['Delivery'], |
| 38 | + productsPages: ['New products'], |
| 39 | + staticPages: ['Contact us'], |
| 40 | + customPages: [{name: 'Home in footer', url: global.FO.URL}], |
| 41 | + }); |
| 42 | + const updateLinkBlockData: FakerLinkWidget = new FakerLinkWidget({ |
| 43 | + name: 'Products section', |
| 44 | + hook: dataHooks.displayFooterBefore, |
| 45 | + contentPages: ['Delivery'], |
| 46 | + productsPages: ['Prices drop'], |
| 47 | + categoriesPages: ['Accessories', 'Art'], |
| 48 | + staticPages: ['Contact us', 'My account'], |
| 49 | + customPages: [{name: 'Home in footer', url: global.FO.URL}], |
| 50 | + }); |
| 51 | + const secondUpdateLinkBlockData = new FakerLinkWidget({ |
| 52 | + name: 'Products', |
| 53 | + hook: dataHooks.displayFooterBefore, |
| 54 | + contentPages: ['Delivery'], |
| 55 | + productsPages: ['Prices drop'], |
| 56 | + categoriesPages: ['Accessories', 'Art'], |
| 57 | + staticPages: ['Contact us', 'My account'], |
| 58 | + customPages: [{name: 'Home in footer', url: global.FO.URL}, {name: 'Home in footer 2', url: global.FO.URL}], |
| 59 | + }); |
| 60 | + |
| 61 | + // before and after functions |
| 62 | + before(async function () { |
| 63 | + browserContext = await utilsPlaywright.createBrowserContext(this.browser); |
| 64 | + page = await utilsPlaywright.newTab(browserContext); |
| 65 | + }); |
| 66 | + |
| 67 | + after(async () => { |
| 68 | + await utilsPlaywright.closeBrowserContext(browserContext); |
| 69 | + }); |
| 70 | + |
| 71 | + describe('Create link block with hook \'DisplayFooter\'', async () => { |
| 72 | + it('should login in BO', async function () { |
| 73 | + await testContext.addContextItem(this, 'testIdentifier', 'loginBO', baseContext); |
| 74 | + |
| 75 | + await boLoginPage.goTo(page, global.BO.URL); |
| 76 | + await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD); |
| 77 | + |
| 78 | + const pageTitle = await boDashboardPage.getPageTitle(page); |
| 79 | + expect(pageTitle).to.contains(boDashboardPage.pageTitle); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should go to \'Design > Link block\' page', async function () { |
| 83 | + await testContext.addContextItem(this, 'testIdentifier', 'goToLinkWidgetPage', baseContext); |
| 84 | + |
| 85 | + await boDashboardPage.goToSubMenu( |
| 86 | + page, |
| 87 | + boDashboardPage.designParentLink, |
| 88 | + boDashboardPage.linkWidgetLink, |
| 89 | + ); |
| 90 | + await boDesignLinkListPage.closeSfToolBar(page); |
| 91 | + |
| 92 | + const pageTitle = await boDesignLinkListPage.getPageTitle(page); |
| 93 | + expect(pageTitle).to.contains(boDesignLinkListPage.pageTitle); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should get link block number', async function () { |
| 97 | + await testContext.addContextItem(this, 'testIdentifier', 'getLinkBlockNumber', baseContext); |
| 98 | + |
| 99 | + numberOfLinkWidgetInFooter = await boDesignLinkListPage.getNumberOfElementInGrid(page, dataHooks.displayFooter.name); |
| 100 | + expect(numberOfLinkWidgetInFooter).to.be.above(0); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should go to add new link block page', async function () { |
| 104 | + await testContext.addContextItem(this, 'testIdentifier', 'goToNewLinkBlockPage', baseContext); |
| 105 | + |
| 106 | + await boDesignLinkListPage.goToNewLinkWidgetPage(page); |
| 107 | + |
| 108 | + const pageTitle = await boDesignLinkListCreatePage.getPageTitle(page); |
| 109 | + expect(pageTitle).to.contains(boDesignLinkListCreatePage.pageTitle); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should create link block', async function () { |
| 113 | + await testContext.addContextItem(this, 'testIdentifier', 'createFooterLinkBlock', baseContext); |
| 114 | + |
| 115 | + const textResult = await boDesignLinkListCreatePage.addLinkWidget(page, linkBlockData); |
| 116 | + expect(textResult).to.equal(boDesignLinkListPage.successfulCreationMessage); |
| 117 | + |
| 118 | + const numberOfLinkWidget = await boDesignLinkListPage.getNumberOfElementInGrid(page, dataHooks.displayFooter.name); |
| 119 | + expect(numberOfLinkWidget).to.equal(numberOfLinkWidgetInFooter + 1); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should get the Id of the created link', async function () { |
| 123 | + await testContext.addContextItem(this, 'testIdentifier', 'getID', baseContext); |
| 124 | + |
| 125 | + linkId = await boDesignLinkListPage.getLinkId(page, dataHooks.displayFooter.name, numberOfLinkWidgetInFooter + 1); |
| 126 | + expect(linkId).not.equal(1); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + describe('Go to FO and check existence of new link Block', async () => { |
| 131 | + it('should view my shop', async function () { |
| 132 | + await testContext.addContextItem(this, 'testIdentifier', 'viewMyShop', baseContext); |
| 133 | + |
| 134 | + // View shop |
| 135 | + page = await boDesignLinkListPage.viewMyShop(page); |
| 136 | + // Change FO language |
| 137 | + await foHummingbirdHomePage.changeLanguage(page, 'en'); |
| 138 | + |
| 139 | + const pageTitle = await foHummingbirdHomePage.getPageTitle(page); |
| 140 | + expect(pageTitle).to.contains(foHummingbirdHomePage.pageTitle); |
| 141 | + }); |
| 142 | + |
| 143 | + it('should check link block in the footer of home page', async function () { |
| 144 | + await testContext.addContextItem(this, 'testIdentifier', 'checkLinBlockInFO', baseContext); |
| 145 | + |
| 146 | + const title = await foHummingbirdHomePage.getFooterLinksBlockTitle(page, linkId); |
| 147 | + expect(title).to.contains(linkBlockData.name); |
| 148 | + |
| 149 | + const linksTextContent = await foHummingbirdHomePage.getFooterLinksTextContent(page, linkId); |
| 150 | + await Promise.all([ |
| 151 | + expect(linksTextContent).to.include.members(linkBlockData.contentPages), |
| 152 | + expect(linksTextContent).to.include.members(linkBlockData.productsPages), |
| 153 | + expect(linksTextContent).to.include.members(linkBlockData.staticPages), |
| 154 | + expect(linksTextContent).to.include.members(linkBlockData.customPages.map((el: LinkWidgetPage) => el.name)), |
| 155 | + ]); |
| 156 | + }); |
| 157 | + |
| 158 | + it('should go back to BO', async function () { |
| 159 | + await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO', baseContext); |
| 160 | + |
| 161 | + // Go back to BO |
| 162 | + page = await foHummingbirdHomePage.closePage(browserContext, page, 0); |
| 163 | + |
| 164 | + const pageTitle = await boDesignLinkListPage.getPageTitle(page); |
| 165 | + expect(pageTitle).to.contains(boDesignLinkListPage.pageTitle); |
| 166 | + }); |
| 167 | + }); |
| 168 | + |
| 169 | + describe('Update link block to hook \'DisplayFooterBefore\'', async () => { |
| 170 | + it('should click on edit block product', async function () { |
| 171 | + await testContext.addContextItem(this, 'testIdentifier', 'goToUpdatePage', baseContext); |
| 172 | + |
| 173 | + await boDesignLinkListPage.goToEditBlock(page, dataHooks.displayFooter.name, numberOfLinkWidgetInFooter + 1); |
| 174 | + |
| 175 | + const pageTitle = await boDesignLinkListCreatePage.getPageTitle(page); |
| 176 | + expect(pageTitle).to.contains(boDesignLinkListCreatePage.pageTitle); |
| 177 | + }); |
| 178 | + |
| 179 | + it('should update link block', async function () { |
| 180 | + await testContext.addContextItem(this, 'testIdentifier', 'updateBlockProduct', baseContext); |
| 181 | + |
| 182 | + const textResult = await boDesignLinkListCreatePage.addLinkWidget(page, updateLinkBlockData, 2); |
| 183 | + expect(textResult).to.contains(boDesignLinkListPage.successfulUpdateMessage); |
| 184 | + |
| 185 | + const numberOfLinkWidget = await boDesignLinkListPage.getNumberOfElementInGrid(page, dataHooks.displayFooterBefore.name); |
| 186 | + expect(numberOfLinkWidget).to.equal(1); |
| 187 | + }); |
| 188 | + }); |
| 189 | + |
| 190 | + describe('Go to FO and check existence of updated link Block just before the footer', async () => { |
| 191 | + it('should view my shop', async function () { |
| 192 | + await testContext.addContextItem(this, 'testIdentifier', 'viewMyShop2', baseContext); |
| 193 | + |
| 194 | + // View shop |
| 195 | + page = await boDesignLinkListPage.viewMyShop(page); |
| 196 | + // Change FO language |
| 197 | + await foHummingbirdHomePage.changeLanguage(page, 'en'); |
| 198 | + |
| 199 | + const pageTitle = await foHummingbirdHomePage.getPageTitle(page); |
| 200 | + expect(pageTitle).to.contains(foHummingbirdHomePage.pageTitle); |
| 201 | + }); |
| 202 | + |
| 203 | + it('should check link block before the footer of home page', async function () { |
| 204 | + await testContext.addContextItem(this, 'testIdentifier', 'checkLinBlockInFO2', baseContext); |
| 205 | + |
| 206 | + const linksTitle = await foHummingbirdHomePage.getFooterLinksBlockTitle(page, linkId); |
| 207 | + await expect(linksTitle).to.contains(updateLinkBlockData.name); |
| 208 | + |
| 209 | + const linksTextContent = await foHummingbirdHomePage.getFooterLinksTextContent(page, linkId); |
| 210 | + await Promise.all([ |
| 211 | + expect(linksTextContent).to.include.members(updateLinkBlockData.contentPages), |
| 212 | + expect(linksTextContent).to.include.members(updateLinkBlockData.productsPages), |
| 213 | + expect(linksTextContent).to.include.members(updateLinkBlockData.categoriesPages), |
| 214 | + expect(linksTextContent).to.include.members(updateLinkBlockData.staticPages), |
| 215 | + expect(linksTextContent).to.include.members(updateLinkBlockData.customPages.map((el: LinkWidgetPage) => el.name)), |
| 216 | + ]); |
| 217 | + }); |
| 218 | + |
| 219 | + it('should go back to BO', async function () { |
| 220 | + await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO2', baseContext); |
| 221 | + |
| 222 | + // Go back to BO |
| 223 | + page = await foHummingbirdHomePage.closePage(browserContext, page, 0); |
| 224 | + |
| 225 | + const pageTitle = await boDesignLinkListPage.getPageTitle(page); |
| 226 | + expect(pageTitle).to.contains(boDesignLinkListPage.pageTitle); |
| 227 | + }); |
| 228 | + }); |
| 229 | + |
| 230 | + describe('Update link block', async () => { |
| 231 | + it('should click on edit block product', async function () { |
| 232 | + await testContext.addContextItem(this, 'testIdentifier', 'goToUpdatePage2', baseContext); |
| 233 | + |
| 234 | + await boDesignLinkListPage.goToEditBlock(page, dataHooks.displayFooterBefore.name, 1); |
| 235 | + |
| 236 | + const pageTitle = await boDesignLinkListCreatePage.getPageTitle(page); |
| 237 | + expect(pageTitle).to.contains(boDesignLinkListCreatePage.pageTitle); |
| 238 | + }); |
| 239 | + |
| 240 | + it('should update link block', async function () { |
| 241 | + await testContext.addContextItem(this, 'testIdentifier', 'updateBlockProduct2', baseContext); |
| 242 | + |
| 243 | + await boDesignLinkListCreatePage.addCustomPages(page, secondUpdateLinkBlockData.customPages, 3); |
| 244 | + |
| 245 | + const textResult = await boDesignLinkListCreatePage.saveForm(page); |
| 246 | + expect(textResult).to.contains(boDesignLinkListPage.successfulUpdateMessage); |
| 247 | + |
| 248 | + const numberOfLinkWidget = await boDesignLinkListPage.getNumberOfElementInGrid(page, dataHooks.displayFooterBefore.name); |
| 249 | + expect(numberOfLinkWidget).to.equal(1); |
| 250 | + }); |
| 251 | + }); |
| 252 | + |
| 253 | + describe('Delete updated link block and check the FO', async () => { |
| 254 | + it('should delete link block', async function () { |
| 255 | + await testContext.addContextItem(this, 'testIdentifier', 'deleteLinkBlock', baseContext); |
| 256 | + |
| 257 | + const textResult = await boDesignLinkListPage.deleteLinkWidget(page, dataHooks.displayFooterBefore.name, 1); |
| 258 | + expect(textResult).to.equal(boDesignLinkListPage.successfulDeleteMessage); |
| 259 | + }); |
| 260 | + |
| 261 | + it('should view my shop', async function () { |
| 262 | + await testContext.addContextItem(this, 'testIdentifier', 'viewMyShop3', baseContext); |
| 263 | + |
| 264 | + // View shop |
| 265 | + page = await boDesignLinkListPage.viewMyShop(page); |
| 266 | + // Change FO language |
| 267 | + await foHummingbirdHomePage.changeLanguage(page, 'en'); |
| 268 | + |
| 269 | + const pageTitle = await foHummingbirdHomePage.getPageTitle(page); |
| 270 | + expect(pageTitle).to.contains(foHummingbirdHomePage.pageTitle); |
| 271 | + }); |
| 272 | + |
| 273 | + it('should check the first link block in the footer of home page', async function () { |
| 274 | + await testContext.addContextItem(this, 'testIdentifier', 'checkLinBlockInFO3', baseContext); |
| 275 | + |
| 276 | + const linksTitle = await foHummingbirdHomePage.getFooterLinksBlockTitle(page, 1); |
| 277 | + await expect(linksTitle).to.not.equal(updateLinkBlockData.name); |
| 278 | + }); |
| 279 | + }); |
| 280 | +}); |
0 commit comments