Skip to content

Commit 3bd4cff

Browse files
committed
All working, needs refactor.
1 parent 4dd23c6 commit 3bd4cff

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

src/components/app_tests/firestore/csr_test_runner.tsx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ import { initializeApp } from 'firebase/app';
2121
import { testFirestore, initializeTestResults, SerializedFirestoreData, TestResults } from '@/lib/app_tests/firestore/test';
2222
import ResultsDisplay from './results_display';
2323
import {
24+
Bytes,
2425
DocumentSnapshot,
26+
documentSnapshotFromJSON,
2527
getFirestore,
28+
GeoPoint,
29+
Timestamp,
2630
onSnapshotResume,
2731
QuerySnapshot,
28-
documentSnapshotFromJSON,
29-
querySnapshotFromJSON
32+
querySnapshotFromJSON,
33+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34+
VectorValue,
35+
vector
3036
} from 'firebase/firestore';
3137
import { firebaseConfig } from '@/lib/app_tests/firebase';
3238
import { OK } from '@/lib/app_tests/util';
@@ -105,6 +111,37 @@ async function runDeserializationTests(
105111
});
106112
await bundleQuerySnapshotPromise;
107113
}
114+
115+
if(serializedFirestoreData.bytesJson !== null) {
116+
const bytes = Bytes.fromJSON(serializedFirestoreData.bytesJson);
117+
if(bytes.isEqual(Bytes.fromUint8Array(new Uint8Array([0, 1, 2, 3, 4, 5])))) {
118+
testResults.clientSideDeserializedBytesResult = OK;
119+
}
120+
}
121+
122+
if(serializedFirestoreData.geoPointJson !== null) {
123+
const geoPoint = GeoPoint.fromJSON(serializedFirestoreData.geoPointJson);
124+
if(geoPoint.latitude === 1 && geoPoint.longitude === 2) {
125+
testResults.clientSideDeserializedGeoPointResult = OK;
126+
}
127+
}
128+
129+
if(serializedFirestoreData.timestampJson !== null) {
130+
const timestamp = Timestamp.fromJSON(serializedFirestoreData.timestampJson);
131+
if(timestamp.seconds === 123 && timestamp.nanoseconds === 456) {
132+
testResults.clientSideDeserializedTimestampResult = OK;
133+
}
134+
}
135+
136+
if(serializedFirestoreData.vectorValueJson !== null) {
137+
const num: number[] = [1, 2, 3];
138+
const deserializedVectorValue = VectorValue.fromJSON(serializedFirestoreData.vectorValueJson);
139+
const controlVectorValue = vector(num);
140+
if(deserializedVectorValue.isEqual(controlVectorValue)) {
141+
testResults.clientSideDeserializedVectorValueResult = OK;
142+
}
143+
}
144+
108145
return testResults;
109146
}
110147

src/components/app_tests/firestore/results_display.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export default function ResultsDisplay({ statusString, testResults }) {
4444
<h4 title="clientSideDocumentSnapshotOnResumeResult">clientSideDocumentSnapshotOnResumeResult: {testResults.clientSideDocumentSnapshotOnResumeResult}</h4>
4545
<h4 title="clientSideQuerySnapshotResult">clientSideQuerySnapshotResult: {testResults.clientSideQuerySnapshotResult}</h4>
4646
<h4 title="clientSideQuerySnapshotOnResumeResult">clientSideQuerySnapshotOnResumeResult: {testResults.clientSideQuerySnapshotOnResumeResult}</h4>
47-
47+
<h4 title="clientSideDeserializedBytesResult">clientSideDeserializedBytesResult: {testResults.clientSideDeserializedBytesResult}</h4>
48+
<h4 title="clientSideDeserializedGeoPointResult">clientSideDeserializedGeoPointResult: {testResults.clientSideDeserializedGeoPointResult}</h4>
49+
<h4 title="clientSideDeserializedTimestampResult">clientSideDeserializedTimestampResult: {testResults.clientSideDeserializedTimestampResult}</h4>
50+
<h4 title="clientSideDeserializedVectorValueResult">clientSideDeserializedVectorValueResult: {testResults.clientSideDeserializedVectorValueResult}</h4>
51+
4852
<p />
4953
<Link href="/">Back to test index</Link>
5054
</>

src/lib/app_tests/firestore/test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717

1818
import { deleteApp, initializeApp } from 'firebase/app';
1919
import {
20+
Bytes,
2021
collection,
2122
DocumentSnapshot,
2223
deleteDoc,
2324
doc,
2425
documentSnapshotFromJSON,
26+
GeoPoint,
2527
getDoc,
2628
getDocs,
2729
getFirestore,
2830
onSnapshot,
2931
onSnapshotResume,
32+
QuerySnapshot,
3033
query,
3134
querySnapshotFromJSON,
32-
QuerySnapshot,
3335
setDoc,
36+
Timestamp,
3437
updateDoc,
35-
38+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
39+
VectorValue,
40+
vector
3641
} from 'firebase/firestore';
3742
import { firebaseConfig } from '@/lib/app_tests/firebase';
3843
import { OK, FAILED, OK_SKIPPED } from '@/lib/app_tests/util';
@@ -63,6 +68,10 @@ export type TestResults = {
6368
clientSideDocumentSnapshotOnResumeResult: string,
6469
clientSideQuerySnapshotResult: string
6570
clientSideQuerySnapshotOnResumeResult: string,
71+
clientSideDeserializedBytesResult: string,
72+
clientSideDeserializedGeoPointResult: string,
73+
clientSideDeserializedTimestampResult: string,
74+
clientSideDeserializedVectorValueResult: string
6675
};
6776

6877
export function initializeTestResults(): TestResults {
@@ -91,13 +100,21 @@ export function initializeTestResults(): TestResults {
91100
clientSideDocumentSnapshotResult: FAILED,
92101
clientSideDocumentSnapshotOnResumeResult: FAILED,
93102
clientSideQuerySnapshotResult: FAILED,
94-
clientSideQuerySnapshotOnResumeResult: FAILED
103+
clientSideQuerySnapshotOnResumeResult: FAILED,
104+
clientSideDeserializedBytesResult: FAILED,
105+
clientSideDeserializedGeoPointResult: FAILED,
106+
clientSideDeserializedTimestampResult: FAILED,
107+
clientSideDeserializedVectorValueResult: FAILED
95108
};
96109
}
97110

98111
export type SerializedFirestoreData = {
99112
documentSnapshotJson: object | null,
100113
querySnapshotJson: object | null,
114+
bytesJson: object | null,
115+
geoPointJson: object | null,
116+
timestampJson: object | null,
117+
vectorValueJson: object | null
101118
}
102119

103120
export async function setExpectedSerializedDataInFirestore(firestore, path) {
@@ -116,7 +133,11 @@ export async function buildSerializedFirestoreData(): Promise<SerializedFirestor
116133
const DOCUMENT_PATH = QUERY_PATH + '/doc';
117134
const result: SerializedFirestoreData = {
118135
documentSnapshotJson: null,
119-
querySnapshotJson: null
136+
querySnapshotJson: null,
137+
bytesJson: null,
138+
geoPointJson: null,
139+
timestampJson: null,
140+
vectorValueJson: null
120141
};
121142

122143
const firebaseApp = initializeApp(firebaseConfig);
@@ -136,6 +157,13 @@ export async function buildSerializedFirestoreData(): Promise<SerializedFirestor
136157
result.querySnapshotJson = querySnapshot.toJSON();
137158
}
138159

160+
result.bytesJson = Bytes.fromUint8Array(new Uint8Array([0, 1, 2, 3, 4, 5])).toJSON();
161+
result.geoPointJson = new GeoPoint(1, 2).toJSON();
162+
result.timestampJson = new Timestamp(123, 456).toJSON();
163+
const num: number[] = [1, 2, 3];
164+
165+
result.vectorValueJson = vector(num).toJSON();
166+
139167
return result;
140168
}
141169

@@ -149,6 +177,10 @@ export async function testFirestore(isServer: boolean = false): Promise<TestResu
149177
result.clientSideDocumentSnapshotOnResumeResult = OK_SKIPPED;
150178
result.clientSideQuerySnapshotResult = OK_SKIPPED;
151179
result.clientSideQuerySnapshotOnResumeResult = OK_SKIPPED;
180+
result.clientSideDeserializedBytesResult = OK_SKIPPED;
181+
result.clientSideDeserializedGeoPointResult = OK_SKIPPED;
182+
result.clientSideDeserializedTimestampResult = OK_SKIPPED;
183+
result.clientSideDeserializedVectorValueResult = OK_SKIPPED;
152184
}
153185

154186
try {

tests/firestore.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ async function commonExpectations(page) {
4444
await expect(page.getByTitle('clientSideDocumentSnapshotOnResumeResult')).not.toContainText("FAILED");
4545
await expect(page.getByTitle('clientSideQuerySnapshotResult')).not.toContainText("FAILED");
4646
await expect(page.getByTitle('clientSideQuerySnapshotOnResumeResult')).not.toContainText("FAILED");
47+
await expect(page.getByTitle('clientSideDeserializedBytesResult')).not.toContainText("FAILED");
48+
await expect(page.getByTitle('clientSideDeserializedGeoPointResult')).not.toContainText("FAILED");
49+
await expect(page.getByTitle('clientSideDeserializedTimestampResult')).not.toContainText("FAILED");
50+
await expect(page.getByTitle('clientSideDeserializedVectorValueResult')).not.toContainText("FAILED");
4751
}
4852

4953
test('firestore operations should pass - client', async ({ page, baseURL }) => {

0 commit comments

Comments
 (0)