import { test } from 'qunit';
import moduleForAcceptance from 'web-client/tests/helpers/module-for-acceptance';
import subscriptionDashScenario from 'web-client/mirage/scenarios/subscription-dash';
import { TicketInformationPage } from 'web-client/tests/pages/dashboards/subscription-dash';
import { stubLogin } from 'web-client/tests/helpers/stub-login';

const USERNAME = 'twitch';

moduleForAcceptance('Acceptance | dashboard/subscription/ticket', {
  beforeEach() {
    this.setupServer = (options) => {
      subscriptionDashScenario(this.server, options);
      this.page = TicketInformationPage.create({ username: options.name });
    };

    stubLogin({ login: USERNAME });
  }
});

test('visits /dashboard/subscription/ticket and goes back to /dashboard/subscription index page', function (assert) {
  assert.expect(3);

  this.setupServer({ name: USERNAME });
  visit(this.page.url());

  andThen(() => {
    assert.equal(
      currentURL(),
      `/twitch/dashboard/subscription/ticket`,
      `/twitch/dashboard/subscription/ticket is visited`
    );

    assert.equal(
      find(this.page.pageTitle()).text().trim(),
      'Subscription Information',
      'title of "Subscription Information" is present'
    );
  });

  click(this.page.backToIndex());

  andThen(() => {
    assert.equal(
      currentURL(),
      `/twitch/dashboard/subscription`,
      `/twitch/dashboard/subscription is visited`
    );
  });
});
