-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
100 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
render, | ||
screen, | ||
waitFor, | ||
waitForElementToBeRemoved, | ||
} from '@testing-library/react' | ||
import { mockAxios, regexUsers } from 'test/axios-mock' | ||
import { TGarden } from 'test/garden-test-values' | ||
import { TServerAuthConfig, TServerConfig } from 'test/test-values' | ||
import { AllProviders, LoggedInProviders } from 'test/testMocks' | ||
import { TAdmin, TUser } from 'test/user-test-values' | ||
|
||
import { GardenAdminCard } from './GardenAdminCard' | ||
|
||
describe('GardenAdminCard', () => { | ||
describe('permission checks', () => { | ||
beforeAll(() => { | ||
mockAxios.onGet('/config').reply(200, TServerAuthConfig) | ||
}) | ||
|
||
afterAll(() => { | ||
mockAxios.onGet('/config').reply(200, TServerConfig) | ||
mockAxios.onGet(regexUsers).reply(200, TUser) | ||
}) | ||
|
||
test('should hide edit button when no permission', async () => { | ||
mockAxios.onGet(regexUsers).reply(200, TUser) | ||
render( | ||
<AllProviders> | ||
<GardenAdminCard garden={TGarden} setRequestStatus={jest.fn()} /> | ||
</AllProviders>, | ||
) | ||
await waitFor(() => { | ||
expect( | ||
screen.queryByText('Edit configurations'), | ||
).not.toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test('should show edit button when permission', async () => { | ||
mockAxios.onGet(regexUsers).reply(200, TAdmin) | ||
render( | ||
<LoggedInProviders> | ||
<GardenAdminCard garden={TGarden} setRequestStatus={jest.fn()} /> | ||
</LoggedInProviders>, | ||
) | ||
await waitFor(() => { | ||
expect(screen.getByText('Edit configurations')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test('should hide delete button when no permission', async () => { | ||
mockAxios.onGet(regexUsers).reply(200, TUser) | ||
render( | ||
<LoggedInProviders> | ||
<GardenAdminCard garden={TGarden} setRequestStatus={jest.fn()} /> | ||
</LoggedInProviders>, | ||
) | ||
await waitFor(() => { | ||
expect( | ||
screen.queryByRole('button', { name: 'Delete' }), | ||
).not.toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test('should show delete button when permission', async () => { | ||
mockAxios.onGet(regexUsers).reply(200, TAdmin) | ||
render( | ||
<LoggedInProviders> | ||
<GardenAdminCard garden={TGarden} setRequestStatus={jest.fn()} /> | ||
</LoggedInProviders>, | ||
) | ||
await waitForElementToBeRemoved(() => | ||
screen.queryByRole('button', { name: 'Delete' }), | ||
) | ||
}) | ||
}) | ||
}) |
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