From 7cde7cbec18e3bb239a5cc39be087901a2baf52e Mon Sep 17 00:00:00 2001 From: nk2136 <156982976+nk2136@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:47:54 -0600 Subject: [PATCH] new test cases --- end2end/tests/sitemapEditor.spec.ts | 199 ++++++++++++++++++++-------- 1 file changed, 147 insertions(+), 52 deletions(-) diff --git a/end2end/tests/sitemapEditor.spec.ts b/end2end/tests/sitemapEditor.spec.ts index 5aed9506..29a16946 100644 --- a/end2end/tests/sitemapEditor.spec.ts +++ b/end2end/tests/sitemapEditor.spec.ts @@ -1,76 +1,73 @@ import { test, expect } from '@playwright/test'; -test('Validate sitemap card edit functionality', async ({ page }) => { - await page.goto('https://host.docker.internal/Test_Request_Portal/admin/'); - - const sitemapEditorButton = page.getByRole('button', { name: 'Sitemap Editor' }); - await sitemapEditorButton.click(); +test('Edit and revert a sitemap card title', async ({ page }) => { + await page.goto('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_sitemaps_template'); const firstSitemapCard = page.locator('#sortable div').nth(0); await firstSitemapCard.waitFor({ state: 'visible' }); - await firstSitemapCard.click(); + // Capture the original site title + const firstCardHeading = firstSitemapCard.locator('h3'); + const originalSiteTitle = await firstCardHeading.textContent(); + + // Edit the site title + await firstSitemapCard.click(); const editSiteDialog = page.locator('text=Edit Site'); await editSiteDialog.waitFor({ state: 'visible' }); - // Add new site title const siteInput = page.locator('label:has-text("Site Title")'); await siteInput.fill('New Site Title'); - // Add new site description - const siteDescriptionInput = page.locator('label:has-text("Site Description")'); - await siteDescriptionInput.fill('This is the site description'); - - const saveButton = page.locator('button', { hasText: 'Save Change' }); + const saveButton = page.locator('button:has-text("Save Change")'); await saveButton.click(); - // Add timeout to complete the backend process - await page.waitForTimeout(1000); + // Wait for the alert to become visible + const sitemapAlert = page.locator('#sitemap-alert'); + await sitemapAlert.waitFor({ state: 'visible' }); - // Ensure that the new card title is visible on the page - await firstSitemapCard.waitFor({ state: 'visible' }); - const firstCardHeading = firstSitemapCard.locator('h3'); - await firstCardHeading.waitFor({ state: 'visible' }); + // Validate the new site title const updatedFirstCardHeading = await firstCardHeading.textContent(); expect(updatedFirstCardHeading).toContain('New Site Title'); - // Ensure that the new card description is visible on the page - const firstCardDescription = firstSitemapCard.locator('p'); - await firstCardDescription.waitFor({ state: 'visible' }); - const updatedFirstCardDescription = await firstCardDescription.textContent(); - expect(updatedFirstCardDescription).toContain('This is the site description'); -}); + // Revert to the original site title + await firstSitemapCard.click(); + await editSiteDialog.waitFor({ state: 'visible' }); -test('Validate sitemap card deletion', async ({ page }) => { - await page.goto('https://host.docker.internal/Test_Request_Portal/admin/'); + await siteInput.fill(originalSiteTitle); + await saveButton.click(); - const sitemapEditorButton = page.getByRole('button', { name: 'Sitemap Editor' }); - await sitemapEditorButton.click(); + // Wait for the alert to become visible + await sitemapAlert.waitFor({ state: 'visible' }); - // Second sitemap card - const secondSitemapCard = page.locator('#sortable div').nth(1); - await secondSitemapCard.waitFor({ state: 'visible' }); - await secondSitemapCard.click(); + // Validate the site title is reverted to the original + const revertedFirstCardHeading = await firstCardHeading.textContent(); + expect(revertedFirstCardHeading).toContain(originalSiteTitle); +}); - const editSiteDialog = page.getByText('Edit Site'); - await editSiteDialog.waitFor({ state: 'visible' }); +test('Inbox visibility on view combined inbox page', async ({ page }) => { + await page.goto('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_sitemaps_template'); - const deleteSiteButton = page.getByRole('button', { name: 'Delete Site' }); - await deleteSiteButton.click(); + // Wait for the new page to open in a popup when clicking the "View Combined Inbox" link + const page1Promise = page.waitForEvent('popup'); + const viewSitemap = page.getByRole('link', { name: 'View Combined Inbox' }); + await viewSitemap.waitFor(); + await viewSitemap.click(); + const page1 = await page1Promise; - // Reload the page to ensure the changes are reflected - await secondSitemapCard.waitFor({ state: 'hidden' }); - await page.reload(); + await page1.waitForLoadState('domcontentloaded'); - // Assert that the second sitemap card is no longer visible - await expect(secondSitemapCard).toBeHidden(); -}); + // Validate new page url + const newPageUrl = page1.url(); + expect(newPageUrl).toBe('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_Inbox'); -test('Validate sitemap card creation', async ({ page }) => { - await page.goto('https://host.docker.internal/Test_Request_Portal/admin/'); + // Validate if the inbox is visible on the new page + const inbox = page1.locator('#inbox'); + await inbox.waitFor({ state: 'visible' }); + await expect(inbox).toBeVisible(); +}); - const sitemapEditorButton = page.getByRole('button', { name: 'Sitemap Editor' }); - await sitemapEditorButton.click(); +test('Sitemap card creation, deletion, and appearance on the view sitemap page', async ({ page }) => { + await page.goto('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_sitemaps_template'); const addSiteButton = page.getByRole('button', { name: 'Add Site' }); await addSiteButton.click(); @@ -78,9 +75,12 @@ test('Validate sitemap card creation', async ({ page }) => { const addSiteDialog = page.locator('span:has-text("Add Site")'); await addSiteDialog.waitFor({ state: 'visible' }); + // Generate a unique site name + const uniqueSiteName = `TestSite-${Math.floor(Math.random() * 10000)}`; + // Add site title const siteInput = page.locator('#button-title'); - await siteInput.fill('Test 3'); + await siteInput.fill(uniqueSiteName); // Add site description const siteDescriptionInput = page.getByLabel('Enter group name'); @@ -99,15 +99,110 @@ test('Validate sitemap card creation', async ({ page }) => { const saveButton = page.getByRole('button', { name: 'Save Change' }); await saveButton.click(); - // Add timeout to complete the backend process - await page.waitForTimeout(1000); - const newCard = page.getByRole('heading', { name: 'Test 3', exact: true }); - await newCard.waitFor({state: 'visible'}) + const sitemapAlert = page.locator('#sitemap-alert'); + await sitemapAlert.waitFor({ state: 'visible' }); // Verify the card background and font color - const newCardElement = page.locator('div.leaf-sitemap-card:has(h3:has-text("Test 3"))'); + const newCardElement = page.locator('div.leaf-sitemap-card:has(h3:has-text("' + uniqueSiteName + '"))'); await newCardElement.waitFor({ state: 'visible' }); const styleAttribute = await newCardElement.getAttribute('style'); expect(styleAttribute).toContain('background-color: #9e4747'); expect(styleAttribute).toContain('color: #a4bd17'); + + // Wait for the new page to open in a popup when clicking the "View Sitemap" link + const page1Promise = page.waitForEvent('popup'); + const viewSitemap = page.getByRole('link', { name: 'View Sitemap' }); + await viewSitemap.waitFor(); + await viewSitemap.click(); + const page1 = await page1Promise; + + await page1.waitForLoadState('domcontentloaded'); + + // Validate new page url + const newPageUrl = page1.url(); + expect(newPageUrl).toBe('https://host.docker.internal/Test_Request_Portal/?a=sitemap'); + + const sitemapCard = page.locator('div.leaf-sitemap-card:has-text("' + uniqueSiteName + '")'); + await expect(sitemapCard).toBeVisible(); + + await page1.close(); + await newCardElement.waitFor(); + await newCardElement.click(); + + // Wait for the "Edit Site" dialog to appear + const editSiteDialog = page.getByText('Edit Site'); + await editSiteDialog.waitFor({ state: 'visible' }); + + await page.getByRole('button', { name: 'Delete Site' }).click(); + await sitemapAlert.waitFor({ state: 'visible' }); + + // Assert that the created sitemap card is no longer visible or attached + await expect(sitemapCard).not.toBeVisible(); +}); + +test('Change and revert sitemap card color from sidenav link', async ({ page }) => { + await page.goto('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_sitemaps_template'); + + const firstItem = page.locator('ul.usa-sidenav li:first-child'); + await firstItem.click(); + + const siteColor = page.locator('input[name="btnColor"]'); + const initialColor = await siteColor.inputValue(); + await siteColor.fill('#803838'); + + // Save changes + const saveButton = page.getByRole('button', { name: 'Save Change' }); + await saveButton.click(); + + // Wait for the alert to become visible + const sitemapAlert = page.locator('#sitemap-alert'); + await sitemapAlert.waitFor({ state: 'visible' }); + + // Verify the color change on the first card + const firstCard = page.locator('#sortable div').first(); + const styleAttribute = await firstCard.getAttribute('style'); + expect(styleAttribute).toContain('background-color: #803838'); + + // Revert the color to the initial value + await firstItem.click(); + await siteColor.fill(initialColor); + await saveButton.click(); + + // Verify the color reverted successfully + const revertedStyleAttribute = await firstCard.getAttribute('style'); + expect(revertedStyleAttribute).toContain(`background-color: ${initialColor}`); +}); + +test('Inbox visibility from view sitemap page', async ({ page }) => { + await page.goto('https://host.docker.internal/Test_Request_Portal/report.php?a=LEAF_sitemaps_template'); + + // Wait for the popup page to open when "View Sitemap" is clicked + const sitemapPopup = page.waitForEvent('popup'); + const sitemapLink = page.getByRole('link', { name: 'View Sitemap' }); + await sitemapLink.waitFor(); + await sitemapLink.click(); + const sitemapPage = await sitemapPopup; + + await sitemapPage.waitForLoadState('domcontentloaded'); + + // Validate the sitemap page URL + const sitemapUrl = sitemapPage.url(); + expect(sitemapUrl).toBe('https://host.docker.internal/Test_Request_Portal/?a=sitemap'); + + // Wait for the Combined Inbox page to open when "View Combined Inbox" is clicked + const inboxPopup = sitemapPage.waitForEvent('popup'); + const inboxBtn = sitemapPage.getByRole('button', { name: 'View Combined Inbox' }); + await inboxBtn.waitFor(); + await inboxBtn.click(); + const inboxPage = await inboxPopup; + + // Wait for the combined inbox page to load + await inboxPage.waitForLoadState('domcontentloaded'); + const inboxUrl = inboxPage.url(); + expect(inboxUrl).toMatch(/https:\/\/host\.docker\.internal\/Test_Request_Portal\/report\.php\?a=leaf_inbox/i); + + // Validate that the inbox is visible on the sitemap page + const inbox = inboxPage.locator('#inbox'); + await inbox.waitFor({ state: 'visible' }); + await expect(inbox).toBeVisible(); });