mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 17:21:35 +10:00
Builder tests: added test for loading screen
This commit is contained in:
@ -20,6 +20,8 @@ const user2 = {
|
|||||||
isAnonymous: AuthConstants.anonymousUser2.isAnonymous,
|
isAnonymous: AuthConstants.anonymousUser2.isAnonymous,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultDelayInMilliseconds = 100;
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
static get valueEventType() {
|
static get valueEventType() {
|
||||||
return valueEventType;
|
return valueEventType;
|
||||||
@ -60,6 +62,10 @@ class Database {
|
|||||||
static get user2() {
|
static get user2() {
|
||||||
return user2;
|
return user2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get defaultDelayInMilliseconds() {
|
||||||
|
return defaultDelayInMilliseconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Database;
|
export default Database;
|
||||||
|
|||||||
@ -149,7 +149,7 @@ class Reference {
|
|||||||
|
|
||||||
const debouncedEventCallback = debounce(
|
const debouncedEventCallback = debounce(
|
||||||
this.eventCallbacks[eventType],
|
this.eventCallbacks[eventType],
|
||||||
100,
|
DatabaseConstants.defaultDelayInMilliseconds,
|
||||||
);
|
);
|
||||||
debouncedEventCallback(snapshot);
|
debouncedEventCallback(snapshot);
|
||||||
}
|
}
|
||||||
@ -183,6 +183,10 @@ class Reference {
|
|||||||
throw new Error('eventType should be a string.');
|
throw new Error('eventType should be a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await new Promise((resolve) =>
|
||||||
|
setTimeout(resolve, DatabaseConstants.defaultDelayInMilliseconds),
|
||||||
|
);
|
||||||
|
|
||||||
return Promise.resolve(this._dataSnapshot);
|
return Promise.resolve(this._dataSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import {
|
|||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
waitFor,
|
waitFor,
|
||||||
|
waitForElementToBeRemoved,
|
||||||
} from '@testing-library/react';
|
} from '@testing-library/react';
|
||||||
|
|
||||||
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
|
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
|
||||||
@ -25,9 +26,11 @@ describe('Builder', () => {
|
|||||||
let resumeId = null;
|
let resumeId = null;
|
||||||
let resume = null;
|
let resume = null;
|
||||||
let mockDatabaseUpdateFunction = null;
|
let mockDatabaseUpdateFunction = null;
|
||||||
|
const loadingScreenTestId = 'loading-screen';
|
||||||
|
|
||||||
async function setup(
|
async function setup(
|
||||||
resumeIdParameter,
|
resumeIdParameter,
|
||||||
|
waitForLoadingScreenToDisappear = true,
|
||||||
waitForDatabaseUpdateFunctionToHaveBeenCalled = true,
|
waitForDatabaseUpdateFunctionToHaveBeenCalled = true,
|
||||||
) {
|
) {
|
||||||
FirebaseStub.database().initializeData();
|
FirebaseStub.database().initializeData();
|
||||||
@ -66,6 +69,12 @@ describe('Builder', () => {
|
|||||||
await FirebaseStub.auth().signInAnonymously();
|
await FirebaseStub.auth().signInAnonymously();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (waitForLoadingScreenToDisappear) {
|
||||||
|
await waitForElementToBeRemoved(() =>
|
||||||
|
screen.getByTestId(loadingScreenTestId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (waitForDatabaseUpdateFunctionToHaveBeenCalled) {
|
if (waitForDatabaseUpdateFunctionToHaveBeenCalled) {
|
||||||
await waitFor(() => mockDatabaseUpdateFunction.mock.calls[0][0], {
|
await waitFor(() => mockDatabaseUpdateFunction.mock.calls[0][0], {
|
||||||
timeout: DebounceWaitTime,
|
timeout: DebounceWaitTime,
|
||||||
@ -77,12 +86,13 @@ describe('Builder', () => {
|
|||||||
describe('handles errors', () => {
|
describe('handles errors', () => {
|
||||||
describe('if resume does not exist', () => {
|
describe('if resume does not exist', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await setup('xxxxxx', false);
|
await setup('xxxxxx', false, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigates to Dashboard', () => {
|
it('navigates to Dashboard', async () => {
|
||||||
expect(resume).toBeNull();
|
await waitFor(() =>
|
||||||
expect(mockNavigateFunction).toHaveBeenCalledTimes(1);
|
expect(mockNavigateFunction).toHaveBeenCalledTimes(1),
|
||||||
|
);
|
||||||
expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard');
|
expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -187,4 +197,14 @@ describe('Builder', () => {
|
|||||||
).toBeGreaterThanOrEqual(now);
|
).toBeGreaterThanOrEqual(now);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('while loading', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await setup(DatabaseConstants.demoStateResume1Id, false, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders loading screen', () => {
|
||||||
|
expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,7 +23,7 @@ describe('Dashboard', () => {
|
|||||||
const user = DatabaseConstants.user1;
|
const user = DatabaseConstants.user1;
|
||||||
const loadingScreenTestId = 'loading-screen';
|
const loadingScreenTestId = 'loading-screen';
|
||||||
|
|
||||||
async function setup(waitForLoadingScreenToDisappear) {
|
async function setup(waitForLoadingScreenToDisappear = true) {
|
||||||
FirebaseStub.database().initializeData();
|
FirebaseStub.database().initializeData();
|
||||||
|
|
||||||
resumes = (
|
resumes = (
|
||||||
@ -61,32 +61,30 @@ describe('Dashboard', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('after loading', () => {
|
describe('renders', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await setup(true);
|
await setup();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renders', () => {
|
it('document title', () => {
|
||||||
it('document title', () => {
|
expect(document.title).toEqual('Dashboard | Reactive Resume');
|
||||||
expect(document.title).toEqual('Dashboard | Reactive Resume');
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('create resume', () => {
|
it('create resume', () => {
|
||||||
expect(screen.getByText(/create resume/i)).toBeInTheDocument();
|
expect(screen.getByText(/create resume/i)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preview of user resumes', () => {
|
it('preview of user resumes', () => {
|
||||||
expect(Object.keys(resumes)).toHaveLength(2);
|
expect(Object.keys(resumes)).toHaveLength(2);
|
||||||
|
|
||||||
expect(Object.values(resumes)[0].user).toEqual(user.uid);
|
expect(Object.values(resumes)[0].user).toEqual(user.uid);
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(Object.values(resumes)[0].name),
|
screen.getByText(Object.values(resumes)[0].name),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
expect(Object.values(resumes)[1].user).toEqual(user.uid);
|
expect(Object.values(resumes)[1].user).toEqual(user.uid);
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(Object.values(resumes)[1].name),
|
screen.getByText(Object.values(resumes)[1].name),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -95,10 +93,8 @@ describe('Dashboard', () => {
|
|||||||
await setup(false);
|
await setup(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renders', () => {
|
it('renders loading screen', () => {
|
||||||
it('loading screen', () => {
|
expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
|
||||||
expect(screen.getByTestId(loadingScreenTestId)).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user