Skip to content

Commit

Permalink
Fix conflicts with new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Jul 16, 2024
1 parent 2270639 commit d95ae29
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook } from '@testing-library/react-hooks';
import { renderHook, waitFor } from '@testing-library/react';

import { useAuditMenu } from './useAuditMenu';

it('should return an empty array of items if doesn`t have license', async () => {
const { result, waitFor } = renderHook(() => useAuditMenu(), {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error: just for testing
Expand All @@ -18,13 +19,12 @@ it('should return an empty array of items if doesn`t have license', async () =>
.build(),
});

await waitFor(() => result.all.length > 1);

expect(result.current).toEqual([]);
});

it('should return an empty array of items if have license and not have permissions', async () => {
const { result, waitFor } = renderHook(() => useAuditMenu(), {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand All @@ -41,13 +41,12 @@ it('should return an empty array of items if have license and not have permissio
.build(),
});

await waitFor(() => result.all.length > 1);

expect(result.current).toEqual([]);
});

it('should return auditItems if have license and permissions', async () => {
const { result, waitFor } = renderHook(() => useAuditMenu(), {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand All @@ -65,7 +64,7 @@ it('should return auditItems if have license and permissions', async () => {
.build(),
});

await waitFor(() => result.current.length > 0);
await waitFor(() => expect(result.current[0]).toBeDefined());

expect(result.current[0].items[0]).toEqual(
expect.objectContaining({
Expand All @@ -81,7 +80,8 @@ it('should return auditItems if have license and permissions', async () => {
});

it('should return auditMessages item if have license and can-audit permission', async () => {
const { result, waitFor } = renderHook(() => useAuditMenu(), {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand All @@ -98,7 +98,7 @@ it('should return auditMessages item if have license and can-audit permission',
.build(),
});

await waitFor(() => result.current.length > 0);
await waitFor(() => expect(result.current[0]).toBeDefined());

expect(result.current[0].items[0]).toEqual(
expect.objectContaining({
Expand All @@ -108,7 +108,8 @@ it('should return auditMessages item if have license and can-audit permission',
});

it('should return audiLogs item if have license and can-audit-log permission', async () => {
const { result, waitFor } = renderHook(() => useAuditMenu(), {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand All @@ -125,7 +126,7 @@ it('should return audiLogs item if have license and can-audit-log permission', a
.build(),
});

await waitFor(() => result.current.length > 0);
await waitFor(() => expect(result.current[0]).toBeDefined());

expect(result.current[0].items[0]).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { UIActionButtonContext } from '@rocket.chat/apps-engine/definition/ui';
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook } from '@testing-library/react-hooks';
import { renderHook, waitFor } from '@testing-library/react';

import { useMarketPlaceMenu } from './useMarketPlaceMenu';

it('should return and empty array if the user does not have `manage-apps` and `access-marketplace` permission', () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [])
.build(),
Expand All @@ -16,6 +17,7 @@ it('should return and empty array if the user does not have `manage-apps` and `a

it('should return `explore` and `installed` items if the user has `access-marketplace` permission', () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [])
.withPermission('access-marketplace')
Expand All @@ -37,6 +39,7 @@ it('should return `explore` and `installed` items if the user has `access-market

it('should return `explore`, `installed` and `requested` items if the user has `manage-apps` permission', () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [])
.withEndpoint('GET', '/apps/app-request/stats', () => ({
Expand Down Expand Up @@ -69,7 +72,8 @@ it('should return `explore`, `installed` and `requested` items if the user has `
});

it('should return one action from the server with no conditions', async () => {
const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -101,18 +105,19 @@ it('should return one action from the server with no conditions', async () => {
}),
);

await waitForValueToChange(() => result.current[0].items[3]);

expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
await waitFor(() =>
expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
),
);
});

describe('Marketplace menu with role conditions', () => {
it('should return the action if the user has admin role', async () => {
const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -149,17 +154,18 @@ describe('Marketplace menu with role conditions', () => {
}),
);

await waitForValueToChange(() => result.current[0].items[3]);

expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
await waitFor(() =>
expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
),
);
});

it('should return filter the action if the user doesn`t have admin role', async () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -206,7 +212,8 @@ describe('Marketplace menu with role conditions', () => {

describe('Marketplace menu with permission conditions', () => {
it('should return the action if the user has manage-apps permission', async () => {
const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -241,17 +248,18 @@ describe('Marketplace menu with permission conditions', () => {
}),
);

await waitForValueToChange(() => result.current[0].items[3]);

expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
await waitFor(() =>
expect(result.current[0].items[3]).toEqual(
expect.objectContaining({
id: 'APP_ID_ACTION_ID',
}),
),
);
});

it('should return filter the action if the user doesn`t have `any` permission', async () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook } from '@testing-library/react-hooks';
import { renderHook, waitFor } from '@testing-library/react';

import { useAdministrationMenu } from './useAdministrationMenu';

it('should return omnichannel item if has `view-livechat-manager` permission ', async () => {
const { result, waitFor } = renderHook(() => useAdministrationMenu(), {
const { result } = renderHook(() => useAdministrationMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error this is a mock
Expand All @@ -29,7 +30,8 @@ it('should return omnichannel item if has `view-livechat-manager` permission ',
});

it('should show administration item if has at least one admin permission', async () => {
const { result, waitFor } = renderHook(() => useAdministrationMenu(), {
const { result } = renderHook(() => useAdministrationMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error this is a mock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import '@testing-library/jest-dom/extend-expect';

import { createRenteionPolicySettingsMock as createMock } from '../../../tests/mocks/client/mockRetentionPolicySettings';
import { createFakeRoom } from '../../../tests/mocks/data';
Expand All @@ -13,14 +12,18 @@ describe('RetentionPolicyCallout', () => {
it('Should render callout if settings are valid', () => {
setDate();
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyCallout room={fakeRoom} />, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) });
render(<RetentionPolicyCallout room={fakeRoom} />, {
legacyRoot: true,
wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }),
});
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM');
});

it('Should not render callout if settings are invalid', () => {
setDate();
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyCallout room={fakeRoom} />, {
legacyRoot: true,
wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }),
});
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
Expand Down
Loading

0 comments on commit d95ae29

Please sign in to comment.