Search in sources :

Example 1 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketCreateViewModelTest method shouldInitializeTicket.

@Test
public void shouldInitializeTicket() {
    Ticket ticket = createTicketViewModel.getTicket();
    Assert.assertEquals("free", ticket.getType());
    Assert.assertNotNull(ticket.getSalesStartsAt());
    Assert.assertNotNull(ticket.getSalesEndsAt());
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) Test(org.junit.Test)

Example 2 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketCreateViewModelTest method shouldShowErrorOnFailure.

@Test
public void shouldShowErrorOnFailure() {
    String errorString = "Error";
    Ticket ticket = createTicketViewModel.getTicket();
    ContextManager.setSelectedEvent(event);
    when(ticketRepository.createTicket(ticket)).thenReturn(Observable.error(new Throwable("Error")));
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateThen = DateUtils.formatDateToIso(LocalDateTime.MAX);
    ticket.setSalesStartsAt(isoDateNow);
    ticket.setSalesEndsAt(isoDateThen);
    InOrder inOrder = inOrder(progress, error);
    createTicketViewModel.getProgress().observeForever(progress);
    createTicketViewModel.getError().observeForever(error);
    createTicketViewModel.createTicket();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged(errorString);
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketCreateViewModelTest method shouldRejectWrongSaleDates.

@Test
public void shouldRejectWrongSaleDates() {
    Ticket ticket = createTicketViewModel.getTicket();
    String isoDate = DateUtils.formatDateToIso(LocalDateTime.now());
    ticket.setSalesStartsAt(isoDate);
    ticket.setSalesEndsAt(isoDate);
    InOrder inOrder = inOrder(error);
    createTicketViewModel.getError().observeForever(error);
    createTicketViewModel.createTicket();
    inOrder.verify(error).onChanged(anyString());
    verify(ticketRepository, never()).createTicket(any());
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketsPresenterTest method testProgressbarOnSwipeRefreshNoItem.

@Test
public void testProgressbarOnSwipeRefreshNoItem() {
    List<Ticket> emptyList = new ArrayList<>();
    when(ticketRepository.getTickets(ID, true)).thenReturn(Observable.fromIterable(emptyList));
    ticketsPresenter.loadTickets(true);
    InOrder inOrder = Mockito.inOrder(ticketsView);
    inOrder.verify(ticketsView).showProgress(true);
    inOrder.verify(ticketsView).onRefreshComplete(true);
    inOrder.verify(ticketsView).showProgress(false);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketDetailFragment method doPrint.

private void doPrint() {
    PrintManager printManager;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        printManager = (PrintManager) getActivity().getSystemService(Context.PRINT_SERVICE);
        String jobName = this.getString(R.string.app_name) + " Document";
        Ticket ticket = ticketDetailViewModel.getTicket().getValue();
        printManager.print(jobName, new TicketPrintAdapter(getActivity(), ticket), null);
    } else {
        ViewUtils.showSnackbar(binding.getRoot(), "No Printing Support!");
    }
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) PrintManager(android.print.PrintManager)

Aggregations

Ticket (com.eventyay.organizer.data.ticket.Ticket)14 Test (org.junit.Test)8 InOrder (org.mockito.InOrder)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Event (com.eventyay.organizer.data.event.Event)2 PrintManager (android.print.PrintManager)1 LiveData (androidx.lifecycle.LiveData)1 ViewModel (androidx.lifecycle.ViewModel)1 ContextManager (com.eventyay.organizer.common.ContextManager)1 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)1 Repository (com.eventyay.organizer.data.Repository)1 Attendee (com.eventyay.organizer.data.attendee.Attendee)1 DbFlowDatabaseRepository (com.eventyay.organizer.data.db.DbFlowDatabaseRepository)1 TicketRepository (com.eventyay.organizer.data.ticket.TicketRepository)1 TicketRepositoryImpl (com.eventyay.organizer.data.ticket.TicketRepositoryImpl)1 DateUtils (com.eventyay.organizer.utils.DateUtils)1 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 ArrayList (java.util.ArrayList)1 Inject (javax.inject.Inject)1