Skip to content

Commit 23d1f32

Browse files
committed
Restructure components
1 parent 24d633c commit 23d1f32

File tree

5 files changed

+52
-41
lines changed

5 files changed

+52
-41
lines changed

app/tests/auth/auth_web_client/page.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import Link from 'next/link';
18-
import ClientResults from './client_results';
1917
import type { Metadata } from 'next'
18+
import ClientResults from '../components/client_results';
2019

2120
export const metadata: Metadata = {
2221
title: 'Auth Web SDK CSR test',
@@ -26,9 +25,7 @@ export default function Page() {
2625
return (
2726
<>
2827
<h1>Auth CSR Test results:</h1>
29-
<ClientResults/>
30-
<p/>
31-
<Link href="/">Back to test index</Link>
28+
<ClientResults />
3229
</>
3330
);
3431
}

app/tests/auth/auth_web_ssr/page.tsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,15 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import Link from 'next/link';
18-
import { testAuth, TestAuthResult } from '../../../../lib/auth_test';
17+
import { testAuth, TestAuthResult } from '../lib/auth_test';
18+
import AuthResultsDisplay from '../components/auth_results_display';
1919

2020
export default async function Page() {
2121
const testAuthResult: TestAuthResult = await testAuth(/*isServerAuth=*/true);
2222
return (
2323
<>
2424
<h1>Auth SSR Test results:</h1>
25-
<h2 title="testStatus">Tests Complete!</h2>
26-
<h4 title="initializeAppResult">initializeAppResult: {testAuthResult.initializeAppResult}</h4>
27-
<h4 title="signInAnonymouslyResult">signInAnonymouslyResult: {testAuthResult.signInAnonymouslyResult}</h4>
28-
<h4 title="getTokenResult">getTokenResult: {testAuthResult.getTokenResult}</h4>
29-
<h4 title="initializeServerAppResult">initializeServerAppResult: {testAuthResult.initializeServerAppResult}</h4>
30-
<h4 title="getAuthServerAppResult">getAuthServerAppResult: {testAuthResult.getAuthServerAppResult}</h4>
31-
<h4 title="getServerAppUserResult">getServerAppUserResult: {testAuthResult.getServerAppUserResult}</h4>
32-
<h4 title="deleteServerAppResult">deleteServerAppResult: {testAuthResult.deleteServerAppResult}</h4>
33-
<h4 title="deleteUserResult">deleteUserResult: {testAuthResult.deleteUserResult}</h4>
34-
<h4 title="deleteAppResult">deleteAppResult: {testAuthResult.deleteAppResult}</h4>
35-
<p />
36-
<Link href="/">Back to test index</Link>
25+
<AuthResultsDisplay statusString='Tests Complete!' testAuthResult={testAuthResult} />
3726
</>
3827
);
3928
}

app/tests/auth/auth_web_client/client_results.tsx app/tests/auth/components/auth_results_display.tsx

+5-20
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,11 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
'use client'
18-
19-
import { useState, useEffect } from 'react'
20-
import { testAuth, createTestAuthResult } from '../../../../lib/auth_test';
21-
22-
export default function ClientResults() {
23-
const [testStatus, setTestStatus] = useState("running...");
24-
const [testAuthResult, setTestAuthResult] = useState(createTestAuthResult());
25-
useEffect(() => {
26-
const asyncTest = async () => {
27-
setTestAuthResult(await testAuth());
28-
setTestStatus("Complete!");
29-
}
30-
asyncTest().catch((e) => {
31-
console.error("Error encountered during testing: ", e);
32-
setTestStatus("Errored!");
33-
});
34-
}, []);
35-
17+
import Link from 'next/link';
18+
export default function AuthResultsDisplay({ statusString, testAuthResult }) {
3619
return (
3720
<>
38-
<h2 title="testStatus">Tests {testStatus}</h2>
21+
<h2 title="testStatus">Tests {statusString}</h2>
3922
<h4 title="initializeAppResult">initializeAppResult: {testAuthResult.initializeAppResult}</h4>
4023
<h4 title="signInAnonymouslyResult">signInAnonymouslyResult: {testAuthResult.signInAnonymouslyResult}</h4>
4124
<h4 title="getTokenResult">getTokenResult: {testAuthResult.getTokenResult}</h4>
@@ -45,6 +28,8 @@ export default function ClientResults() {
4528
<h4 title="deleteServerAppResult">deleteServerAppResult: {testAuthResult.deleteServerAppResult}</h4>
4629
<h4 title="deleteUserResult">deleteUserResult: {testAuthResult.deleteUserResult}</h4>
4730
<h4 title="deleteAppResult">deleteAppResult: {testAuthResult.deleteAppResult}</h4>
31+
<p />
32+
<Link href="/">Back to test index</Link>
4833
</>
4934
);
5035
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
'use client'
18+
19+
import { useState, useEffect } from 'react'
20+
import { testAuth, createTestAuthResult } from '../lib/auth_test';
21+
import AuthResultsDisplay from './auth_results_display';
22+
23+
export default function ClientResults() {
24+
const [testStatus, setTestStatus] = useState<string>("running...");
25+
const [testAuthResult, setTestAuthResult] = useState(createTestAuthResult());
26+
useEffect(() => {
27+
const asyncTest = async () => {
28+
setTestAuthResult(await testAuth());
29+
setTestStatus("Complete!");
30+
}
31+
asyncTest().catch((e) => {
32+
console.error("Error encountered during testing: ", e);
33+
setTestStatus("Errored!");
34+
});
35+
}, []);
36+
37+
return (
38+
<AuthResultsDisplay statusString={testStatus} testAuthResult={testAuthResult} />
39+
);
40+
}

lib/auth_test.ts app/tests/auth/lib/auth_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
import { deleteApp, initializeApp, initializeServerApp } from 'firebase/app';
1818
import { deleteUser, getAuth, onAuthStateChanged, signInAnonymously, User } from 'firebase/auth';
19-
import { firebaseConfig } from './firebase';
20-
import { OK, OK_SKIPPED, FAILED } from './util';
19+
import { firebaseConfig } from '../../../../lib/firebase';
20+
import { OK, OK_SKIPPED, FAILED } from '../../../../lib/util';
2121

2222
export type TestAuthResult = {
2323
initializeAppResult: string,

0 commit comments

Comments
 (0)