private void statusChanged(Observable<FormOfflineStatus> status) { if(status.isLoading()) { button.setEnabled(false); button.setText(I18N.CONSTANTS.loading()); } else { button.setEnabled(true); if(!status.get().isEnabled()) { button.setText(I18N.CONSTANTS.makeAvailableOffline()); } else if(status.get().isCached()) { button.setText(I18N.CONSTANTS.availableOffline()); } else { button.setText(I18N.CONSTANTS.downloadInProgress()); } } }
@Test public void offlineRecordFetching() { AsyncClientStub client = new AsyncClientStub(); HttpStore httpStore = new HttpStore(client, scheduler); OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub()); FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler); Survey survey = client.getStorageProvider().getSurvey(); // Start online Connection<FormOfflineStatus> offlineStatusView = connect(formStore.getOfflineStatus(survey.getFormId())); // Initially form should not be loaded assertFalse(offlineStatusView.assertLoaded().isEnabled()); // and mark the survey form for offline usage offlineStore.enableOffline(survey.getFormId(), true); assertTrue(offlineStatusView.assertLoaded().isEnabled()); assertFalse(offlineStatusView.assertLoaded().isCached()); // Now synchronize... RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore); runScheduled(); // We go offline... client.setConnected(false); // Should be able to view the form class and a record Connection<FormTree> schemaView = connect(formStore.getFormTree(survey.getFormId())); Connection<Maybe<FormRecord>> recordView = connect(formStore.getRecord(survey.getRecordRef(0))); runScheduled(); schemaView.assertLoaded(); recordView.assertLoaded(); assertTrue(offlineStatusView.assertLoaded().isEnabled()); assertTrue(offlineStatusView.assertLoaded().isCached()); }