Search in sources :

Example 1 with AutoCompleteTextField

use of jgnash.uifx.control.AutoCompleteTextField in project jgnash by ccavanaugh.

the class AutoCompleteModelTest method testPayeeMemoModels.

@Test
@DisabledOnOs(OS.MAC)
void testPayeeMemoModels() {
    Options.useFuzzyMatchForAutoCompleteProperty().set(true);
    final Engine engine = createEngine("payee-test");
    final Account account = new Account(AccountType.CASH, engine.getDefaultCurrency());
    engine.addAccount(engine.getRootAccount(), account);
    assertEquals(1, engine.getAccountList().size());
    final LocalDate localDate = LocalDate.of(2000, Month.JANUARY, 1);
    // create a bunch of transactions
    for (int i = 1; i <= TRANSACTION_COUNT; i++) {
        final Transaction t = TransactionFactory.generateSingleEntryTransaction(account, BigDecimal.TEN, localDate.plusDays(i), "Memo " + i, "Payee " + i, Integer.toString(i));
        engine.addTransaction(t);
        assertEquals(i, engine.getTransactions().size());
    }
    assertEquals(TRANSACTION_COUNT, engine.getTransactions().size());
    final AutoCompleteTextField<Transaction> autoCompletePayeeTextField = new AutoCompleteTextField<>();
    AutoCompleteFactory.setPayeeModel(autoCompletePayeeTextField, account);
    final AutoCompleteTextField<Transaction> autoCompleteMemoTextField = new AutoCompleteTextField<>();
    AutoCompleteFactory.setMemoModel(autoCompleteMemoTextField);
    final AutoCompleteModel<Transaction> payeeModel = autoCompletePayeeTextField.autoCompleteModelObjectProperty().get();
    final AutoCompleteModel<Transaction> memoModel = autoCompleteMemoTextField.autoCompleteModelObjectProperty().get();
    final AtomicBoolean payeeModelLoaded = payeeModel.isLoadComplete();
    final AtomicBoolean memoModelLoaded = memoModel.isLoadComplete();
    // Block until the atomics have been set, or the test will fail
    Awaitility.await().untilTrue(payeeModelLoaded);
    Awaitility.await().untilTrue(memoModelLoaded);
    // noinspection SpellCheckingInspection
    final String payeeResult = payeeModel.doLookAhead("Paye");
    final String memoResult = memoModel.doLookAhead("Me");
    assertEquals("Payee " + TRANSACTION_COUNT, payeeResult);
    assertEquals("Memo " + TRANSACTION_COUNT, memoResult);
    EngineFactory.closeEngine(EngineFactory.DEFAULT);
}
Also used : Account(jgnash.engine.Account) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AutoCompleteTextField(jgnash.uifx.control.AutoCompleteTextField) Transaction(jgnash.engine.Transaction) LocalDate(java.time.LocalDate) Engine(jgnash.engine.Engine) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDate (java.time.LocalDate)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Account (jgnash.engine.Account)1 Engine (jgnash.engine.Engine)1 Transaction (jgnash.engine.Transaction)1 AutoCompleteTextField (jgnash.uifx.control.AutoCompleteTextField)1 Test (org.junit.jupiter.api.Test)1 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)1