/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import { mount } from 'enzyme';
import { Unstable_FileUploader, StyledContentMessage, StyledErrorMessage } from '../index.js';
describe('FileUploader', function () {
  it('applies expected accessibility attributes to button', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, null));
    var button = wrapper.find('button').getDOMNode();
    expect(button.getAttribute('aria-controls')).toBe('fileupload');
    expect(button.getAttribute('role')).toBe('button');
  });
  it('renders progress bar if progressAmount provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressAmount: 50
    }));
    var progressBar = wrapper.find('ProgressBar');
    expect(progressBar).toHaveLength(1);
  });
  it('renders content message if progressMessage provided', function () {
    var message = 'uploading...';
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressMessage: message
    }));
    var progressMessage = wrapper.find(StyledContentMessage);
    expect(progressMessage).toHaveLength(1);
    expect(progressMessage.text()).toBe(message);
  });
  it('does not render progress bar if progressAmount not provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressMessage: "uploading..."
    }));
    var progressBar = wrapper.find('ProgressBar');
    expect(progressBar).toHaveLength(0);
  });
  it('renders error message if errorMessage provided', function () {
    var message = 'error!';
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      errorMessage: message
    }));
    var errorMessage = wrapper.find(StyledErrorMessage);
    expect(errorMessage).toHaveLength(1);
    expect(errorMessage.text()).toBe(message);
  });
  it('renders cancel button if progressAmount provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressAmount: 50
    }));
    var button = wrapper.find('button');
    expect(button.text()).toBe('Cancel');
  });
  it('renders cancel button if progressMessage provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressMessage: "uploading..."
    }));
    var button = wrapper.find('button');
    expect(button.text()).toBe('Cancel');
  });
  it('renders retry button if errorMessage provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      errorMessage: "error!"
    }));
    var button = wrapper.find('button');
    expect(button.text()).toBe('Retry Upload');
  });
  it('renders retry button if progressAmount and errorMessage provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressAmount: 40,
      errorMessage: "error!"
    }));
    var button = wrapper.find('button');
    expect(button.text()).toBe('Retry Upload');
  });
  it('renders error message if progressAmount and errorMessage provided', function () {
    var message = 'error!';
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressAmount: 40,
      errorMessage: message
    }));
    var errorMessage = wrapper.find(StyledErrorMessage);
    expect(errorMessage).toHaveLength(1);
    expect(errorMessage.text()).toBe(message);
  });
  it('renders retry button if progressMessage and errorMessage provided', function () {
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressMessage: "uploading...",
      errorMessage: "error!"
    }));
    var button = wrapper.find('button');
    expect(button.text()).toBe('Retry Upload');
  });
  it('renders error message if progressMessage and errorMessage provided', function () {
    var message = 'error!';
    var wrapper = mount(React.createElement(Unstable_FileUploader, {
      progressMessage: "uploading...",
      errorMessage: message
    }));
    var errorMessage = wrapper.find(StyledErrorMessage);
    expect(errorMessage).toHaveLength(1);
    expect(errorMessage.text()).toBe(message);
  });
});