Skip to content

Commit

Permalink
Ion to Onyx
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Nov 12, 2020
1 parent 38eafcc commit fa65f33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
45 changes: 23 additions & 22 deletions tests/unit/ionTest.js → tests/unit/onyxTest.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import 'react-native';
import Ion from '../../src/libs/Ion';
import Onyx from 'react-native-onyx';

const TEST_KEY = 'test';

jest.mock('../../node_modules/@react-native-community/async-storage',
() => require('./mocks/@react-native-community/async-storage'));

Ion.registerLogger(() => {});
Ion.init({
Onyx.registerLogger(() => {});
Onyx.init({
keys: {
TEST_KEY,
COLLECTION: {},
COLLECTOnyx: {},
},
registerStorageEventListener: () => {},
});

describe('Ion', () => {
describe('Onyx', () => {
let connectionID;

afterEach((done) => {
Ion.disconnect(connectionID);
Ion.clear().then(done);
Onyx.disconnect(connectionID);
Onyx.clear().then(done);
});

it('should set a simple key', (done) => {
const mockCallback = jest.fn();
connectionID = Ion.connect({
connectionID = Onyx.connect({
key: TEST_KEY,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -40,12 +41,12 @@ describe('Ion', () => {
});

// Set a simple key
Ion.set(TEST_KEY, 'test');
Onyx.set(TEST_KEY, 'test');
});

it('should merge an object with another object', (done) => {
const mockCallback = jest.fn();
connectionID = Ion.connect({
connectionID = Onyx.connect({
key: TEST_KEY,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -70,13 +71,13 @@ describe('Ion', () => {
}
});

Ion.set(TEST_KEY, {test1: 'test1'});
Ion.merge(TEST_KEY, {test2: 'test2'});
Onyx.set(TEST_KEY, {test1: 'test1'});
Onyx.merge(TEST_KEY, {test2: 'test2'});
});

it('should notify subscribers when data has been cleared', (done) => {
const mockCallback = jest.fn();
connectionID = Ion.connect({
connectionID = Onyx.connect({
key: TEST_KEY,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -96,13 +97,13 @@ describe('Ion', () => {
}
});

Ion.set(TEST_KEY, 'test');
Ion.clear();
Onyx.set(TEST_KEY, 'test');
Onyx.clear();
});

it('should not notify subscribers after they have disconnected', (done) => {
const mockCallback = jest.fn();
connectionID = Ion.connect({
connectionID = Onyx.connect({
key: TEST_KEY,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -111,10 +112,10 @@ describe('Ion', () => {
}
});

Ion.set(TEST_KEY, 'test')
Onyx.set(TEST_KEY, 'test')
.then(() => {
Ion.disconnect(connectionID);
return Ion.set(TEST_KEY, 'test updated');
Onyx.disconnect(connectionID);
return Onyx.set(TEST_KEY, 'test updated');
})
.then(() => {
try {
Expand All @@ -128,7 +129,7 @@ describe('Ion', () => {

it('should merge arrays by appending new items to the end of a value', (done) => {
const mockCallback = jest.fn();
connectionID = Ion.connect({
connectionID = Onyx.connect({
key: TEST_KEY,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -148,7 +149,7 @@ describe('Ion', () => {
}
});

Ion.set(TEST_KEY, ['test1']);
Ion.merge(TEST_KEY, ['test2', 'test3', 'test4']);
Onyx.set(TEST_KEY, ['test1']);
Onyx.merge(TEST_KEY, ['test2', 'test3', 'test4']);
});
});
18 changes: 9 additions & 9 deletions tests/unit/withIonTest.js → tests/unit/withOnyxTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'react-native';
import {render} from '@testing-library/react-native';
import React from 'react';
import Ion from '../../src/libs/Ion';
import withIon from '../../src/components/withIon';
import Onyx, {withOnyx} from 'react-native-onyx';
import ViewWithText from '../components/ViewWithText';

import waitForPromisesToResolve from '../utils/waitForPromisesToResolve';
Expand All @@ -12,27 +11,28 @@ const TEST_KEY = 'test';
jest.mock('../../node_modules/@react-native-community/async-storage',
() => require('./mocks/@react-native-community/async-storage'));

Ion.registerLogger(() => {});
Ion.init({
Onyx.registerLogger(() => {});
Onyx.init({
keys: {
TEST_KEY,
COLLECTION: {},
},
registerStorageEventListener: () => {},
});

describe('withIon', () => {
it('should render with the test data when using withIon', () => {
describe('withOnyx', () => {
it('should render with the test data when using withOnyx', () => {
let result;

Ion.set(TEST_KEY, 'test1')
Onyx.set(TEST_KEY, 'test1')
.then(() => {
const TestComponentWithIon = withIon({
const TestComponentWithOnyx = withOnyx({
text: {
key: TEST_KEY,
},
})(ViewWithText);

result = render(<TestComponentWithIon />);
result = render(<TestComponentWithOnyx />);
return waitForPromisesToResolve();
})
.then(() => {
Expand Down

0 comments on commit fa65f33

Please sign in to comment.