Advertisement
Guest User

Tests

a guest
Sep 17th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. import { assert, expect } from "chai";
  2. import puppeteer from "puppeteer";
  3. import axios from "axios";
  4.  
  5. import EstateDBFields from 'shared/EstateDBFields';
  6. import EstateTransactionTypes from 'shared/EstateTransactionTypes';
  7.  
  8. import { ObjectID as MongoID } from "mongodb";
  9.  
  10. let browser;
  11. let page;
  12.  
  13. const IndexPageURL = `${process.env.PANORO_TESTS_URL}`;
  14. const SearchPageURL = `${process.env.PANORO_TESTS_URL}/cauta/vanzari/Apartamente/Cluj-Napoca`;
  15. const SearchPageMetaDescription = 'Vanzari apartamente Cluj si Inchirieri Apartamente Cluj prin Agentia Imobiliara Panoro. Oferte imobiliare spre Inchiriere si Vanzare in Cluj. Vanzare terenuri si case';
  16. const SearchPageTitle = 'Imobiliare Cluj | Portal anunturi imobiliare Panoro';
  17.  
  18. let TransactionTypeData = [0, 1];
  19. let ImobilTypeData = [
  20. { id: '59fd616efef3121cf8028f71', name: 'Apartamente', url: 'Apartamente' },
  21. { id: '5a6599d48e595c292c981c5c', name: 'Case/Vile', url: 'Case-Vile' },
  22. { id: '5a6599df8e595c292c981c5f', name: 'Spatii industriale', url: 'Spatii-industriale' },
  23. { id: '5a6599e78e595c292c981c65', name: 'Terenuri', url: 'Terenuri' },
  24. { id: '5a6599e28e595c292c981c62', name: 'Spatii comerciale', url: 'Spatii_comerciale' },
  25. { id: '5a65b7a8c0217b07387dcf23', name: 'Birouri', url: 'Birouri' }
  26. ];
  27.  
  28. console.log("RUN HEADLESS:", process.env.PANORO_TESTS_RUNHEADLESS);
  29.  
  30. function testDataFromIndex(getData) {
  31. let CityName = 'Cluj-Napoca';
  32. let TransactionType;
  33. let TransactionName;
  34. let CategoryID;
  35. let CategoryName;
  36. let CategoryUrl;
  37. let CityID;
  38. let EstatesData;
  39. let LastSearchObject;
  40. let SearchData;
  41.  
  42. describe("[SearchPage][Data from IndexPage]", () => {
  43.  
  44. before(async () => {
  45. browser = await puppeteer.launch({ headless: parseInt(process.env.PANORO_TESTS_RUNHEADLESS) });
  46.  
  47. let data = getData();
  48. TransactionType = data.transactionType;
  49. TransactionName = TransactionType == [EstateTransactionTypes.VANZARE] ? 'vanzari' : 'inchirieri';
  50. CategoryID = data.imobilTypeId;
  51. CategoryName = data.imobilTypeName;
  52. CategoryUrl = data.imobilTypeUrl;
  53. // console.log('data ->', data);
  54. });
  55.  
  56. it("Search Ads has the correct url", async () => {
  57. await page.goto(IndexPageURL);
  58. await page.waitForSelector('#indexTop4-type');
  59.  
  60. if (TransactionType == [EstateTransactionTypes.VANZARE]) {
  61. await page.click("#vanzari");
  62. } else {
  63. await page.click("#inchirieri");
  64. }
  65.  
  66. await page.click(".select-wrapper");
  67. const selectHandle = await page.$('#imobilType-select');
  68.  
  69. let values = await selectHandle.$$eval('.imobilType-option', nodes => nodes.map(n => n.innerText));
  70.  
  71. for (let i = 0, length = values.length; i < length; i++) {
  72. if (values[i] == CategoryName) {
  73. /*** Nu stiu cum sa dau click exact pe optiunea pe care trebuie ***/
  74. // await page.click(".imobilType-option");
  75. console.log('CLICKED ->', values[i], CategoryName);
  76. }
  77. }
  78.  
  79. await page.focus('#liveSearch_input');
  80. await page.keyboard.type(CityName);
  81.  
  82. await Promise.all([
  83. page.click("#liveSearch_button"),
  84. page.waitForNavigation()
  85. ]);
  86.  
  87. await page.waitForSelector('#searchPage_layout1_cnt');
  88.  
  89. let url = `${process.env.PANORO_TESTS_URL}/cauta/${TransactionName}/${CategoryUrl}/${CityName}`;
  90. let expectedUrl = await page.evaluate(() => window.location.href);
  91. /*** expectedUrl este mereu '.../cauta/vanzari/Apartamente/Cluj-Napoca' ***/
  92.  
  93. // console.log('URL ->', url, 'expectedUrl ->', expectedUrl);
  94. // expect(url).to.equal(expectedUrl);
  95. console.log(`DONE TESTING -> ${TransactionName} ${CategoryName}`);
  96. });
  97.  
  98. it("SearchPage has the correct number of ads", async () => {
  99. await page.waitForSelector('.ad-grid-wrapper');
  100. let ads = await page.$$('.ad-grid-wrapper');
  101.  
  102. let city = await axios.get(`${process.env.PANORO_TESTS_URL}/api/locations/visitors/search`, { params : { name: CityName, limit: 1 } });
  103. CityID = city.data[0]._id;
  104.  
  105. let lastSearchObject = {
  106. [EstateDBFields.TRANSACTION_TYPE]: { valueType: "i", value: TransactionType },
  107. [EstateDBFields.CITYID]: { type: "in", value: [ CityID ] },
  108. imobilTypeID: { value: CategoryID, valueType: "id" }
  109. };
  110.  
  111. let searchData = { sort: { code: -1 }, search: lastSearchObject };
  112. // console.log('searchData Before Request ->', searchData);
  113.  
  114. let estates = await axios.post(`${process.env.PANORO_TESTS_URL}/api/estates/visitors/get/all`, searchData);
  115. EstatesData = estates.data;
  116. console.log('EstatesData ->', EstatesData.length);
  117. // expect(ads.length).to.equal(estates.data.length);
  118. console.log(`DONE TESTING -> ${TransactionName} ${CategoryName}`);
  119. });
  120. });
  121. };
  122.  
  123. describe("[IndexPage]", () => {
  124. before(async () => {
  125. browser = await puppeteer.launch({ headless: parseInt(process.env.PANORO_TESTS_RUNHEADLESS) });
  126. page = await browser.newPage();
  127. page.setViewport({ width: 1440, height: 768 });
  128. });
  129.  
  130. for (let i = 0, length = TransactionTypeData.length; i < length; i++) {
  131. for (let j = 0, length2 = ImobilTypeData.length; j < length2; j++) {
  132. let indexData = {
  133. transactionType: TransactionTypeData[i],
  134. imobilTypeId: ImobilTypeData[j].id,
  135. imobilTypeName: ImobilTypeData[j].name,
  136. imobilTypeUrl: ImobilTypeData[j].url
  137. };
  138. testDataFromIndex(
  139. () => { return indexData; }
  140. );
  141. }
  142. }
  143. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement