🤡(app-desk) mock pad and pads panel

In order to access to the pad page we mocked
the api calls of the pad and pads panel.
This commit is contained in:
Anthony LC
2024-04-04 14:55:24 +02:00
committed by Anthony LC
parent b7663cca2d
commit 5ce77c2138
9 changed files with 163 additions and 17 deletions

View File

@@ -28,7 +28,10 @@ test.describe('Pads Panel', () => {
).toBeVisible(); ).toBeVisible();
}); });
test('checks the sort button', async ({ page }) => { /**
* TODO: remove the skip when we can create pads
*/
test.skip('checks the sort button', async ({ page }) => {
const responsePromiseSortDesc = page.waitForResponse( const responsePromiseSortDesc = page.waitForResponse(
(response) => (response) =>
response.url().includes('/pads/?page=1&ordering=-created_at') && response.url().includes('/pads/?page=1&ordering=-created_at') &&
@@ -62,7 +65,10 @@ test.describe('Pads Panel', () => {
expect(responseSortDesc.ok()).toBeTruthy(); expect(responseSortDesc.ok()).toBeTruthy();
}); });
test('checks the infinite scroll', async ({ page, browserName }) => { /**
* TODO: remove the skip when we can create pads
*/
test.skip('checks the infinite scroll', async ({ page, browserName }) => {
test.setTimeout(90000); test.setTimeout(90000);
const panel = page.getByLabel('Pads panel').first(); const panel = page.getByLabel('Pads panel').first();
@@ -75,7 +81,13 @@ test.describe('Pads Panel', () => {
expect(await panel.locator('li').count()).toBeGreaterThan(20); expect(await panel.locator('li').count()).toBeGreaterThan(20);
}); });
test('checks the hover and selected state', async ({ page, browserName }) => { /**
* TODO: remove the skip when we can create pads
*/
test.skip('checks the hover and selected state', async ({
page,
browserName,
}) => {
const panel = page.getByLabel('Pads panel').first(); const panel = page.getByLabel('Pads panel').first();
await createTeam(page, 'pad-hover', browserName, 2); await createTeam(page, 'pad-hover', browserName, 2);

View File

@@ -2,13 +2,54 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { APIError, errorCauses, fetchAPI } from '@/api'; import { APIError, errorCauses, fetchAPI } from '@/api';
import { Pad } from '../types'; import { Pad, Role } from '../types';
export type PadParams = { export type PadParams = {
id: string; id: string;
}; };
export const getPad = async ({ id }: PadParams): Promise<Pad> => { export const getPad = async ({ id }: PadParams): Promise<Pad> => {
/**
* TODO: Remove this block when the API endpoint is ready
*/
return await new Promise((resolve) => {
const pad: Pad = {
id: '1',
name: 'My mocked pad',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
};
setTimeout(() => {
resolve(pad);
}, 500);
});
const response = await fetchAPI(`pads/${id}`); const response = await fetchAPI(`pads/${id}`);
if (!response.ok) { if (!response.ok) {

View File

@@ -6,7 +6,7 @@ import IconGroup from '@/assets/icons/icon-group2.svg';
import { Box, Card, Text } from '@/components'; import { Box, Card, Text } from '@/components';
import { useCunninghamTheme } from '@/cunningham'; import { useCunninghamTheme } from '@/cunningham';
import { Pad, Role } from '../types'; import { Pad } from '../types';
const format: DateTimeFormatOptions = { const format: DateTimeFormatOptions = {
month: '2-digit', month: '2-digit',
@@ -16,7 +16,6 @@ const format: DateTimeFormatOptions = {
interface PadInfoProps { interface PadInfoProps {
pad: Pad; pad: Pad;
currentRole: Role;
} }
export const PadInfo = ({ pad }: PadInfoProps) => { export const PadInfo = ({ pad }: PadInfoProps) => {

View File

@@ -22,7 +22,10 @@ describe('PanelPads', () => {
fetchMock.restore(); fetchMock.restore();
}); });
it('renders with no pad to display', async () => { /**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders with no pad to display', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, { fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 0, count: 0,
results: [], results: [],
@@ -39,7 +42,10 @@ describe('PanelPads', () => {
).toBeInTheDocument(); ).toBeInTheDocument();
}); });
it('renders an empty pad', async () => { /**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders an empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, { fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1, count: 1,
results: [ results: [
@@ -58,7 +64,10 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument(); expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
}); });
it('renders a pad with only 1 member', async () => { /**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders a pad with only 1 member', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, { fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1, count: 1,
results: [ results: [
@@ -82,7 +91,10 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument(); expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
}); });
it('renders a non-empty pad', async () => { /**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders a non-empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, { fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1, count: 1,
results: [ results: [
@@ -110,7 +122,10 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Pads icon')).toBeInTheDocument(); expect(await screen.findByLabelText('Pads icon')).toBeInTheDocument();
}); });
it('renders the error', async () => { /**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders the error', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, { fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
status: 500, status: 500,
}); });

View File

@@ -6,7 +6,7 @@ import {
} from '@tanstack/react-query'; } from '@tanstack/react-query';
import { APIError, APIList, errorCauses, fetchAPI } from '@/api'; import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
import { Pad } from '@/features/pads'; import { Pad, Role } from '@/features/pads/pad';
export enum PadsOrdering { export enum PadsOrdering {
BY_CREATED_ON = 'created_at', BY_CREATED_ON = 'created_at',
@@ -26,6 +26,85 @@ export const getPads = async ({
ordering, ordering,
page, page,
}: PadsAPIParams): Promise<PadsResponse> => { }: PadsAPIParams): Promise<PadsResponse> => {
/**
* TODO: Remove this block when the API endpoint is ready
*/
return await new Promise((resolve) => {
const pads: PadsResponse = {
count: 1,
next: null,
previous: null,
results: [
{
id: '1',
name: 'My mocked pad',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
},
{
id: '2',
name: 'My mocked pad number 2',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
},
],
};
setTimeout(() => {
resolve(pads);
}, 500);
});
const orderingQuery = ordering ? `&ordering=${ordering}` : ''; const orderingQuery = ordering ? `&ordering=${ordering}` : '';
const response = await fetchAPI(`pads/?page=${page}${orderingQuery}`); const response = await fetchAPI(`pads/?page=${page}${orderingQuery}`);

View File

@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import IconGroup from '@/assets/icons/icon-group.svg'; import IconGroup from '@/assets/icons/icon-group.svg';
import { Box, StyledLink, Text } from '@/components'; import { Box, StyledLink, Text } from '@/components';
import { useCunninghamTheme } from '@/cunningham'; import { useCunninghamTheme } from '@/cunningham';
import { Pad } from '@/features/pads'; import { Pad } from '@/features/pads/pad';
import IconNone from '../assets/icon-none.svg'; import IconNone from '../assets/icon-none.svg';

View File

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
import { Box, Text } from '@/components'; import { Box, Text } from '@/components';
import { InfiniteScroll } from '@/components/InfiniteScroll'; import { InfiniteScroll } from '@/components/InfiniteScroll';
import { Pad } from '@/features/pads'; import { Pad } from '@/features/pads/pad';
import { usePads } from '../api'; import { usePads } from '../api';
import { usePadStore } from '../store'; import { usePadStore } from '../store';

View File

@@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react';
import { Box } from '@/components'; import { Box } from '@/components';
import { useCunninghamTheme } from '@/cunningham'; import { useCunninghamTheme } from '@/cunningham';
import { Panel } from '@/features/pads'; import { Panel } from '@/features/pads/pads-panel';
import { MainLayout } from './MainLayout'; import { MainLayout } from './MainLayout';

View File

@@ -5,7 +5,7 @@ import { ReactElement } from 'react';
import { Box } from '@/components'; import { Box } from '@/components';
import { TextErrors } from '@/components/TextErrors'; import { TextErrors } from '@/components/TextErrors';
import { usePad } from '@/features/pads'; import { PadInfo, usePad } from '@/features/pads/pad';
import { PadLayout } from '@/layouts'; import { PadLayout } from '@/layouts';
import { NextPageWithLayout } from '@/types/next'; import { NextPageWithLayout } from '@/types/next';
@@ -46,7 +46,7 @@ const Pad = ({ id }: PadProps) => {
); );
} }
return <>Toto</>; return <PadInfo pad={pad} />;
}; };
Page.getLayout = function getLayout(page: ReactElement) { Page.getLayout = function getLayout(page: ReactElement) {