-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable edit button if rejected (#176)
* feat: disable edit button if rejected * fix: jest types and unit tests * fix: page navigation delay removed * fix: restore nextjs headers
- Loading branch information
1 parent
23d7597
commit ad6f829
Showing
10 changed files
with
181 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ export const CustomRealms: CustomRealmFormData[] = [ | |
rcChannelOwnedBy: '', | ||
materialToSend: '', | ||
status: 'pending', | ||
idps: [], | ||
protocol: [], | ||
}, | ||
{ | ||
id: 2, | ||
|
@@ -43,6 +45,30 @@ export const CustomRealms: CustomRealmFormData[] = [ | |
division: 'division', | ||
approved: null, | ||
status: 'pending', | ||
idps: [], | ||
protocol: [], | ||
}, | ||
{ | ||
id: 3, | ||
realm: 'realm 3', | ||
productName: 'name', | ||
purpose: 'purpose', | ||
primaryEndUsers: ['livingInBC', 'businessInBC', 'govEmployees', 'details'], | ||
environments: ['dev', 'test', 'prod'], | ||
preferredAdminLoginMethod: 'idir', | ||
productOwnerEmail: '[email protected]', | ||
productOwnerIdirUserId: 'po', | ||
technicalContactEmail: '[email protected]', | ||
technicalContactIdirUserId: '[email protected]', | ||
secondTechnicalContactIdirUserId: 'dmsd', | ||
secondTechnicalContactEmail: '[email protected]', | ||
ministry: 'ministry', | ||
branch: 'branch', | ||
division: 'division', | ||
approved: false, | ||
status: 'pending', | ||
idps: [], | ||
protocol: [], | ||
}, | ||
]; | ||
|
||
|
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,85 @@ | ||
import React from 'react'; | ||
import { render, screen, within, waitFor, fireEvent } from '@testing-library/react'; | ||
import App from 'pages/_app'; | ||
import CustomRealmDashboard from 'pages/custom-realm-dashboard'; | ||
import { updateRealmProfile } from 'services/realm'; | ||
import { getRealmEvents } from 'services/events'; | ||
import { CustomRealmFormData } from 'types/realm-profile'; | ||
import Router from 'next/router'; | ||
import { CustomRealms } from './fixtures'; | ||
import RealmLeftPanel from 'page-partials/my-dashboard/RealmLeftPanel'; | ||
import noop from 'lodash.noop'; | ||
import { debug } from 'jest-preview'; | ||
|
||
const editFunction = jest.fn(); | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
return { | ||
route: '/', | ||
pathname: '', | ||
query: '', | ||
asPath: '', | ||
push: jest.fn(() => Promise.resolve(true)), | ||
events: { | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
}, | ||
beforePopState: jest.fn(() => null), | ||
prefetch: jest.fn(() => null), | ||
}; | ||
}, | ||
})); | ||
|
||
// Mock authentication | ||
const mockSession = { | ||
expires: new Date(Date.now() + 2 * 86400).toISOString(), | ||
user: { username: 'admin' }, | ||
}; | ||
jest.mock('next-auth/react', () => { | ||
const originalModule = jest.requireActual('next-auth/react'); | ||
return { | ||
__esModule: true, | ||
...originalModule, | ||
useSession: jest.fn(() => { | ||
return { data: mockSession, status: 'authenticated' }; // return type is [] in v3 but changed to {} in v4 | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock('next-auth/next', () => { | ||
return { | ||
__esModule: true, | ||
getServerSession: jest.fn(() => { | ||
return { data: mockSession, status: 'authenticated' }; | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock('../pages/api/realms', () => { | ||
return { | ||
__esModule: true, | ||
getAllRealms: jest.fn(() => Promise.resolve([CustomRealms, null])), | ||
authOptions: {}, | ||
}; | ||
}); | ||
|
||
describe('realm table', () => { | ||
it('loads all realms', () => { | ||
render(<RealmLeftPanel realms={CustomRealms as any} onCancel={noop} onEditClick={noop} onViewClick={noop} />); | ||
}); | ||
|
||
it('edit button disabled if realm is not approved', async () => { | ||
render( | ||
<RealmLeftPanel realms={CustomRealms as any} onCancel={noop} onEditClick={editFunction} onViewClick={noop} />, | ||
); | ||
const table = screen.getByRole('table'); | ||
const thirdRow = table.querySelector('tbody tr:nth-child(3)') as HTMLTableRowElement; | ||
expect(thirdRow).toBeInTheDocument(); | ||
const actionCell = thirdRow.querySelector('td:nth-child(10)') as HTMLTableCellElement; | ||
expect(actionCell).toBeInTheDocument(); | ||
const editButton = within(actionCell).getByRole('img', { name: 'Edit' }); | ||
fireEvent.click(editButton); | ||
expect(editFunction).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
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
Oops, something went wrong.