Skip to content

Commit

Permalink
Revert D41603109: Manually add annotations in xplat to prepare for LTI
Browse files Browse the repository at this point in the history
Differential Revision:
D41603109 (0ff0fae)

Original commit changeset: 800b2e701d33

Original Phabricator Diff: D41603109 (0ff0fae)

fbshipit-source-id: c63979864304d2ac15c2f00ffd3189e9f0e702ff
  • Loading branch information
mendoncakeegan authored and facebook-github-bot committed Dec 1, 2022
1 parent 0ff0fae commit 0ffb76b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 87 deletions.
Expand Up @@ -15,9 +15,7 @@ import type {
loadQueryStoreBehaviorTestQuery$data,
loadQueryStoreBehaviorTestQuery$variables,
} from './__generated__/loadQueryStoreBehaviorTestQuery.graphql';
import type {Sink} from 'relay-runtime/network/RelayObservable';
import type {GraphQLSingularResponse} from 'relay-runtime/network/RelayNetworkTypes';
import type {Query, OperationType} from 'relay-runtime/util/RelayRuntimeTypes';
import type {Query} from 'relay-runtime/util/RelayRuntimeTypes';

const {loadQuery} = require('../loadQuery');
const {
Expand Down Expand Up @@ -54,7 +52,7 @@ const preloadableConcreteRequest = {
params: query.params,
};

const response: GraphQLSingularResponse = {
const response = {
data: {
node: {
__typename: 'User',
Expand All @@ -67,7 +65,7 @@ const response: GraphQLSingularResponse = {
},
};

const updatedResponse: GraphQLSingularResponse = {
const updatedResponse = {
data: {
node: {
__typename: 'User',
Expand All @@ -94,16 +92,12 @@ let writeDataToStore;

beforeEach(() => {
operation = createOperationDescriptor(query, variables);
fetch = jest.fn(
(_query, _variables, _cacheConfig, _uploadables, _logRequestInfo) => {
const observableCreate = Observable.create(
(_sink: Sink<GraphQLSingularResponse>) => {
sink = _sink;
},
);
return observableCreate;
},
);
fetch = jest.fn((_query, _variables, _cacheConfig) => {
const observableCreate = Observable.create(_sink => {
sink = _sink;
});
return observableCreate;
});
environment = createMockEnvironment({network: Network.create(fetch)});
store = environment.getStore();

Expand All @@ -116,11 +110,7 @@ beforeEach(() => {
.mockImplementation(() => resolvedModule);

writeDataToStore = () => {
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
);
loadQuery(environment, preloadableConcreteRequest, variables);
sink.next(response);
sink.complete();
PreloadableQueryRegistry.set(ID, query);
Expand All @@ -143,11 +133,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});
it('should write the data to the store after the query AST and network response are available', () => {
expect(store.check(operation).status).toBe('missing');
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
);
loadQuery(environment, preloadableConcreteRequest, variables);
expect(fetch).toHaveBeenCalled();
expect(store.check(operation).status).toBe('missing');
PreloadableQueryRegistry.set(ID, query);
Expand All @@ -158,11 +144,7 @@ describe('when passed a PreloadableConcreteRequest', () => {

it('should write the data to the store after the network response and query AST are available', () => {
expect(store.check(operation).status).toBe('missing');
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
);
loadQuery(environment, preloadableConcreteRequest, variables);
expect(store.check(operation).status).toBe('missing');
sink.next(response);
expect(store.check(operation).status).toBe('missing');
Expand All @@ -172,7 +154,7 @@ describe('when passed a PreloadableConcreteRequest', () => {

it('should not write the data to the store if dispose is called before the query AST and network response are available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -186,7 +168,7 @@ describe('when passed a PreloadableConcreteRequest', () => {

it('should not write the data to the store if dispose is called before the network response and query AST are available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -200,7 +182,7 @@ describe('when passed a PreloadableConcreteRequest', () => {

it('should not write the data to the store if dispose is called after the query AST is available, but before the network response is available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -214,7 +196,7 @@ describe('when passed a PreloadableConcreteRequest', () => {

it('should not write the data to the store if dispose is called after the network response is available, but before the query AST is available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -230,18 +212,14 @@ describe('when passed a PreloadableConcreteRequest', () => {
describe('when the query AST is available synchronously', () => {
it('should write data to the store when the network response is available', () => {
expect(store.check(operation).status).toBe('missing');
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
);
loadQuery(environment, preloadableConcreteRequest, variables);
sink.next(response);
expect(store.check(operation).status).toBe('available');
});

it('should not write data to the store if dispose is called before the network response is available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -257,14 +235,9 @@ describe('when passed a PreloadableConcreteRequest', () => {
beforeEach(() => writeDataToStore());
describe('when the query AST is available synchronously', () => {
it('should write updated data to the store when the network response is available', () => {
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
{
fetchPolicy: 'network-only',
},
);
loadQuery(environment, preloadableConcreteRequest, variables, {
fetchPolicy: 'network-only',
});

expect(
(store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name,
Expand All @@ -276,7 +249,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});

it('should not write updated data to the store if dispose is called before the network response is available', () => {
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -297,14 +270,9 @@ describe('when passed a PreloadableConcreteRequest', () => {
resolvedModule = undefined;
});
it('should write updated data to the store when the network response and query AST are available', () => {
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
{
fetchPolicy: 'network-only',
},
);
loadQuery(environment, preloadableConcreteRequest, variables, {
fetchPolicy: 'network-only',
});

expect(
(store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name,
Expand All @@ -320,14 +288,9 @@ describe('when passed a PreloadableConcreteRequest', () => {
).toEqual('Mark');
});
it('should write updated data to the store when the query AST and network response are available', () => {
loadQuery<OperationType>(
environment,
preloadableConcreteRequest,
variables,
{
fetchPolicy: 'network-only',
},
);
loadQuery(environment, preloadableConcreteRequest, variables, {
fetchPolicy: 'network-only',
});

expect(
(store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name,
Expand All @@ -344,7 +307,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});

it('should not write updated data to the store if dispose is called before the network response and query AST are available', () => {
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -365,7 +328,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});

it('should not write updated data to the store if dispose is called before the query AST and network response are available', () => {
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -386,7 +349,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});

it('should not write updated data to the store if dispose is called after the query AST is available and before the network response is available', () => {
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand All @@ -410,7 +373,7 @@ describe('when passed a PreloadableConcreteRequest', () => {
});

it('should not write updated data to the store if dispose is called after ·the network repsonse is available and before the query AST is available', () => {
const {dispose} = loadQuery<OperationType>(
const {dispose} = loadQuery(
environment,
preloadableConcreteRequest,
variables,
Expand Down Expand Up @@ -440,14 +403,14 @@ describe('when passed a query AST', () => {
describe('when data is unavailable in the store', () => {
it('should write data to the store when the network response is available', () => {
expect(store.check(operation).status).toBe('missing');
loadQuery<OperationType>(environment, query, variables);
loadQuery(environment, query, variables);
sink.next(response);
expect(store.check(operation).status).toBe('available');
});

it('should not write data to the store if dispose is called before the network response is available', () => {
expect(store.check(operation).status).toBe('missing');
const {dispose} = loadQuery<OperationType>(environment, query, variables);
const {dispose} = loadQuery(environment, query, variables);
dispose();
sink.next(response);
expect(store.check(operation).status).toBe('missing');
Expand All @@ -456,7 +419,7 @@ describe('when passed a query AST', () => {
describe("when data is available in the store, but the fetch policy is 'network-only'", () => {
beforeEach(() => writeDataToStore());
it('should write updated data to the store when the network response is available', () => {
loadQuery<OperationType>(environment, query, variables, {
loadQuery(environment, query, variables, {
fetchPolicy: 'network-only',
});

Expand All @@ -470,14 +433,9 @@ describe('when passed a query AST', () => {
});

it('should not write updated data to the store if dispose is called before the network response is available', () => {
const {dispose} = loadQuery<OperationType>(
environment,
query,
variables,
{
fetchPolicy: 'network-only',
},
);
const {dispose} = loadQuery(environment, query, variables, {
fetchPolicy: 'network-only',
});

dispose();
sink.next(updatedResponse);
Expand Down
Expand Up @@ -51,7 +51,7 @@ const {
const defaultFetchPolicy = 'network-only';

function expectToBeRendered(
renderFn: JestMockFn<$ReadOnlyArray<any>, any>,
renderFn: JestMockFn<Array<any>, any>,
readyState: ?SelectorData,
) {
// Ensure useEffect is called before other timers
Expand Down
Expand Up @@ -71,8 +71,8 @@ beforeEach(() => {
initialDataIDs,
initialCallback,
}: {
initialCallback: JestMockFn<$ReadOnlyArray<mixed>, void>,
initialDataIDs: $ReadOnlyArray<string>,
initialCallback: JestMockFn<Array<mixed>, void>,
initialDataIDs: Array<string>,
}) {
const [dataIDs, _setDataIDs] = useState(initialDataIDs);
const [cbState, _setCallback] = useState({callback: initialCallback});
Expand All @@ -91,8 +91,8 @@ beforeEach(() => {
}

function Container(props: {
callback: JestMockFn<$ReadOnlyArray<mixed>, void>,
dataIDs: $ReadOnlyArray<string>,
callback: JestMockFn<Array<mixed>, void>,
dataIDs: Array<string>,
environment: RelayMockEnvironment,
}) {
const [env, setEnv] = useState(props.environment);
Expand All @@ -109,8 +109,8 @@ beforeEach(() => {

render = (
env: RelayMockEnvironment,
dataIDs: $ReadOnlyArray<string>,
cb: JestMockFn<$ReadOnlyArray<mixed>, void>,
dataIDs: Array<string>,
cb: JestMockFn<Array<mixed>, void>,
) => {
ReactTestRenderer.act(() => {
renderedInstance = ReactTestRenderer.create(
Expand Down

0 comments on commit 0ffb76b

Please sign in to comment.