Skip to content

Commit 23e5374

Browse files
committed
Add tests regarding disableAuthentication
1 parent 0678a7e commit 23e5374

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

packages/ra-core/src/controller/list/InfiniteListBase.spec.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ describe('InfiniteListBase', () => {
7373
resolveAuth!();
7474
await screen.findByText('Hello');
7575
});
76+
it('should not wait for the authentication resolution before loading data when disableAuthentication is true', async () => {
77+
const authProvider = {
78+
login: () => Promise.resolve(),
79+
logout: () => Promise.resolve(),
80+
checkError: () => Promise.resolve(),
81+
checkAuth: jest.fn(),
82+
};
83+
const dataProvider = testDataProvider({
84+
// @ts-ignore
85+
getList: jest.fn(() =>
86+
Promise.resolve({ data: [{ id: 1, title: 'Hello' }], total: 1 })
87+
),
88+
});
89+
render(
90+
<WithAuthProviderNoAccessControl
91+
authProvider={authProvider}
92+
dataProvider={dataProvider}
93+
InfiniteListProps={{ disableAuthentication: true }}
94+
/>
95+
);
96+
await screen.findByText('Hello');
97+
expect(authProvider.checkAuth).not.toHaveBeenCalled();
98+
});
7699
it('should wait for both the authentication and authorization resolution before loading data', async () => {
77100
let resolveAuth: () => void;
78101
let resolveCanAccess: (value: boolean) => void;

packages/ra-core/src/controller/list/InfiniteListBase.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,18 @@ export const WithAuthProviderNoAccessControl = ({
143143
checkError: () => Promise.resolve(),
144144
},
145145
dataProvider = defaultDataProvider,
146+
InfiniteListProps,
146147
}: {
147148
authProvider?: AuthProvider;
148149
dataProvider?: DataProvider;
150+
InfiniteListProps?: Partial<InfiniteListBaseProps>;
149151
}) => (
150152
<CoreAdminContext authProvider={authProvider} dataProvider={dataProvider}>
151153
<InfiniteListBase
152154
resource="books"
153155
perPage={5}
154156
loading={<div>Authentication loading...</div>}
157+
{...InfiniteListProps}
155158
>
156159
<BookListView />
157160
</InfiniteListBase>

packages/ra-core/src/controller/list/ListBase.spec.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ describe('ListBase', () => {
2222
expect(dataProvider.getList).toHaveBeenCalled();
2323
await screen.findByText('Hello');
2424
});
25+
it('should not wait for the authentication resolution before loading data when disableAuthentication is true', async () => {
26+
const authProvider = {
27+
login: () => Promise.resolve(),
28+
logout: () => Promise.resolve(),
29+
checkError: () => Promise.resolve(),
30+
checkAuth: jest.fn(),
31+
};
32+
const dataProvider = testDataProvider({
33+
// @ts-ignore
34+
getList: jest.fn(() =>
35+
Promise.resolve({ data: [{ id: 1, title: 'Hello' }], total: 1 })
36+
),
37+
});
38+
render(
39+
<WithAuthProviderNoAccessControl
40+
authProvider={authProvider}
41+
dataProvider={dataProvider}
42+
ListProps={{ disableAuthentication: true }}
43+
/>
44+
);
45+
await screen.findByText('Hello');
46+
expect(authProvider.checkAuth).not.toHaveBeenCalled();
47+
});
2548
it('should wait for the authentication resolution before loading data', async () => {
2649
let resolveAuth: () => void;
2750
const authProvider = {

packages/ra-core/src/controller/list/ListBase.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,18 @@ export const WithAuthProviderNoAccessControl = ({
147147
checkError: () => Promise.resolve(),
148148
},
149149
dataProvider = defaultDataProvider,
150+
ListProps,
150151
}: {
151152
authProvider?: AuthProvider;
152153
dataProvider?: DataProvider;
154+
ListProps?: Partial<ListBaseProps>;
153155
}) => (
154156
<CoreAdminContext authProvider={authProvider} dataProvider={dataProvider}>
155157
<ListBase
156158
resource="books"
157159
perPage={5}
158160
loading={<div>Authentication loading...</div>}
161+
{...ListProps}
159162
>
160163
<BookListView />
161164
</ListBase>

0 commit comments

Comments
 (0)