-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36c8b3b
commit c7b0902
Showing
10 changed files
with
131 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import {render, screen} from '@testing-library/react'; | ||
import BeforeLogin from '@/app/(index)/_components/BeforeLogin'; | ||
describe('BeforeLogin Component', () =>{ | ||
test('renders UHGroupingsInfo component', ()=> { | ||
test('renders UHGroupingsInfo and a button with correct text and link', ()=> { | ||
render(<BeforeLogin />); | ||
const uhGroupingsInfo = screen.getByText('What is a UH Grouping?'); | ||
expect(uhGroupingsInfo).toBeInTheDocument(); | ||
}) | ||
const size = 'text-[1.2rem]' | ||
const linkUrl = 'https://uhawaii.atlassian.net/wiki/spaces/UHIAM/pages/13403213/UH+Groupings' | ||
expect(screen.getByRole('heading', {name:'What is a UH Grouping?'})) | ||
.toHaveClass('text-text-color'); | ||
expect(screen.getByTestId('description')).toBeInTheDocument() | ||
|
||
test('renders LearnMoreButton Component', ()=>{ | ||
render(<BeforeLogin />); | ||
const LearnMoreButton = screen.getByText('Learn More'); | ||
expect(LearnMoreButton).toBeInTheDocument(); | ||
}) | ||
expect(screen.getByAltText('Cogs icon')).toHaveAttribute('src', '/uhgroupings/cogs.svg') | ||
expect(screen.getByText('Create groupings, manage grouping memberships, control members\' ' + | ||
'self-service options, designate sync destinations, and more.')).toHaveClass(size) | ||
|
||
expect(screen.getByAltText('Email icon')).toHaveAttribute('src', '/uhgroupings/id-email.svg') | ||
expect(screen.getByText('Synchronize groupings email LISTSERV lists,' + | ||
' attributes for access control via CAS and LDAP, etc..')).toHaveClass(size) | ||
|
||
expect(screen.getByAltText('Watch icon')).toHaveAttribute('src', '/uhgroupings/watch.svg') | ||
expect(screen.getByText('Leverage group data from official sources,' + | ||
' which can substantially reduce the manual overhead of membership management.')).toHaveClass(size) | ||
|
||
test('LearningMoreButton redirects to the correct link', ()=>{ | ||
render(<BeforeLogin />) | ||
const linkElement = screen.getByRole('link'); | ||
expect((linkElement)).toHaveAttribute('href', | ||
'https://uhawaii.atlassian.net/wiki/spaces/UHIAM/pages/13403213/UH+Groupings') | ||
expect(screen.getByRole('link')).toHaveAttribute('href', linkUrl) | ||
expect(screen.getByRole('button', {name:'Learn More'})).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { redirect } from 'next/navigation'; | ||
import User, { AnonymousUser } from '@/access/User'; | ||
import Role from '@/access/Role'; | ||
import LoginButton from "@/app/(index)/_components/LoginButton"; | ||
|
||
const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string; | ||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; | ||
const testUser: User = JSON.parse(process.env.TEST_USER_A as string); | ||
|
||
describe('LoginButton Component', () => { | ||
|
||
describe('User is not logged in', () => { | ||
|
||
it('should render a Login button', () => { | ||
render(<LoginButton currentUser={AnonymousUser}/>); | ||
|
||
expect(screen.getByRole('button', { name: 'Login Here' })).toBeInTheDocument; | ||
}); | ||
|
||
it('should visit the CAS login url on click', () => { | ||
render(<LoginButton currentUser={AnonymousUser} />); | ||
|
||
const casLoginUrl = `${casUrl}/login?service=${encodeURIComponent(`${baseUrl}/api/cas/login`)}`; | ||
fireEvent.click(screen.getByRole('button', { name: 'Login Here' })); | ||
expect(redirect).toHaveBeenCalledWith(casLoginUrl); | ||
}); | ||
|
||
}); | ||
|
||
describe('User is logged in', () => { | ||
|
||
beforeAll(() => { | ||
testUser.roles.push(Role.UH); | ||
}); | ||
|
||
it('should render a Logout button with the uid of the logged-in user', () => { | ||
render(<LoginButton currentUser={testUser} />); | ||
|
||
expect(screen.getByRole('button', { name: 'Logout' })).toBeInTheDocument; | ||
}); | ||
|
||
it('should visit the CAS logout url on click', () => { | ||
render(<LoginButton currentUser={testUser} />); | ||
|
||
const casLogoutUrl = `${casUrl}/logout?service=${encodeURIComponent(`${baseUrl}/api/cas/logout`)}`; | ||
fireEvent.click(screen.getByRole('button', { name: 'Logout' })); | ||
expect(redirect).toHaveBeenCalledWith(casLogoutUrl); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters