dididy commented on code in PR #5087: URL: https://github.com/apache/zeppelin/pull/5087#discussion_r2398983765
########## zeppelin-web-angular/e2e/tests/authentication/anonymous-login-redirect.spec.ts: ########## @@ -0,0 +1,176 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect, test } from '@playwright/test'; +import { ZeppelinHelper } from '../../helper'; +import { HomePageUtil } from '../../models/home-page.util'; +import { addPageAnnotationBeforeEach, PAGES, waitForUrlNotContaining, getCurrentPath } from '../../utils'; + +test.describe('Anonymous User Login Redirect', () => { + addPageAnnotationBeforeEach(PAGES.WORKSPACE.HOME); + + let zeppelinHelper: ZeppelinHelper; + let homePageUtil: HomePageUtil; + + test.beforeEach(async ({ page }) => { + zeppelinHelper = new ZeppelinHelper(page); + homePageUtil = new HomePageUtil(page); + }); + + test.describe('Given an anonymous user is already logged in', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + }); + + test('When accessing login page directly, Then should redirect to home with proper URL change', async ({ + page + }) => { + const redirectResult = await homePageUtil.verifyAnonymousUserRedirectFromLogin(); + + expect(redirectResult.isLoginUrlMaintained).toBe(false); + expect(redirectResult.isHomeContentDisplayed).toBe(true); + expect(redirectResult.isAnonymousUser).toBe(true); + expect(redirectResult.currentPath).toContain('#/'); + expect(redirectResult.currentPath).not.toContain('#/login'); + }); + + test('When accessing login page directly, Then should display all home page elements correctly', async ({ + page + }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + await homePageUtil.verifyHomePageIntegrity(); + }); + + test('When clicking Zeppelin logo after redirect, Then should maintain home URL and content', async ({ page }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + const navigationResult = await homePageUtil.testNavigationConsistency(); + + expect(navigationResult.pathBeforeClick).toContain('#/'); + expect(navigationResult.pathBeforeClick).not.toContain('#/login'); + expect(navigationResult.pathAfterClick).toContain('#/'); + expect(navigationResult.homeContentMaintained).toBe(true); + }); + + test('When accessing login page, Then should redirect and maintain anonymous user state', async ({ page }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + const metadata = await homePageUtil.getPageMetadata(); + + expect(metadata.title).toContain('Zeppelin'); + expect(metadata.path).toContain('#/'); + expect(metadata.path).not.toContain('#/login'); + expect(metadata.isAnonymous).toBe(true); + }); + + test('When accessing login page, Then should display welcome heading and main sections', async ({ page }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + await expect(page.locator('h1', { hasText: 'Welcome to Zeppelin!' })).toBeVisible(); + await expect(page.locator('text=Notebook').first()).toBeVisible(); + await expect(page.locator('text=Help').first()).toBeVisible(); + await expect(page.locator('text=Community').first()).toBeVisible(); + }); + + test('When accessing login page, Then should display notebook functionalities', async ({ page }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + await expect(page.locator('text=Create new Note')).toBeVisible(); + await expect(page.locator('text=Import Note')).toBeVisible(); + + const filterInput = page.locator('input[placeholder*="Filter"]'); + if ((await filterInput.count()) > 0) { + await expect(filterInput).toBeVisible(); + } + }); + + test('When accessing login page, Then should display tutorial notebooks', async ({ page }) => { + await page.goto('/#/login', { waitUntil: 'load' }); + await zeppelinHelper.waitForZeppelinReady(); + await page.waitForURL(url => !url.toString().includes('#/login')); + + await expect(page.locator('text=Flink Tutorial')).toBeVisible(); + await expect(page.locator('text=Python Tutorial')).toBeVisible(); + await expect(page.locator('text=Spark Tutorial')).toBeVisible(); + await expect(page.locator('text=R Tutorial')).toBeVisible(); + await expect(page.locator('text=Miscellaneous Tutorial')).toBeVisible(); + }); Review Comment: 13a09d9 I missed that part. Thanks for the review. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
