var utils = require('./utils.js');

describe('Admin upload custom CSS', function() {
  it('should upload a file and the file should be available for download', function() {
    if (!utils.testFileUpload()) {
      return;
    }

    browser.setLocation('admin/content');

    utils.waitUntilPresent(element(by.cssContainingText("a", "Theme customization")));

    element(by.cssContainingText("a", "Theme customization")).click();

    var customCSSFile = utils.makeTestFilePath('application-home.css');

    browser.executeScript('angular.element(document.querySelectorAll(\'input[type="file"]\')).attr("style", "opacity:0; visibility: visible;");');
    element(by.css("div.uploadfile.file-css")).element(by.css("input")).sendKeys(customCSSFile);

    utils.waitUntilPresent(element(by.cssContainingText("a", "Theme customization")));

    element(by.cssContainingText("a", "Theme customization")).click();

    if (utils.testFileDownload() && utils.verifyFileDownload()) {
      element(by.css("div.uploadfile.file-css")).element(by.cssContainingText("a", "Download"))
      .click().then(function() {
        var actualFile = utils.makeSavedFilePath('custom_stylesheet.css');
        utils.TestFileEquality(customCSSFile, actualFile);
      });
    }
  });
});

describe('Custom CSS classes are attached to the interface', function() {
  var EC = protractor.ExpectedConditions;

  // check that element is hidden.
  it('the logo should be hidden in the public interface', function() {
    browser.get('/');
    expect(EC.invisibilityOf($('#LogoBox')));
    expect(EC.visibilityOf($('#FooterBox')));
  });

  it('the footer should be hidden from an authenticated user', function() {
    utils.login_admin();
    browser.setLocation('/#/admin/landing');
    expect(EC.invisibilityOf($('#FooterBox')));
    expect(EC.visibilityOf($('#LogoBox')));
  });

  it('the login button should be hidden on the embedded login page', function() {
    browser.get('/#/login?embed=true');
    expect(EC.invisibilityOf($('#login-button')));
  });

  it('should allow deletion of the file', function() {
    utils.login_admin();
    browser.setLocation('admin/content');
    element(by.cssContainingText("a", "Theme customization")).click();

    element(by.cssContainingText("a", "Delete")).click();

    // wait until redirect to the first tab of the admin/content section
    utils.waitUntilPresent(element(by.cssContainingText("label", "Project name")));
  });
});

@@ -45,22 +45,25 @@
 ('Admin 
-upload
+configure
  custom 
@@ -98,67 +98,41 @@
 uld 
-upload a file and the file should be available for download
+be able to configure a custom CSS
 ', f
@@ -199,16 +199,61 @@
 %0A    %7D%0A%0A
+    var EC = protractor.ExpectedConditions;%0A%0A
     brow
@@ -1274,241 +1274,8 @@
   %7D%0A
-  %7D);%0A%7D);%0A%0Adescribe('Custom CSS classes are attached to the interface', function() %7B%0A  var EC = protractor.ExpectedConditions;%0A%0A  // check that element is hidden.%0A  it('the logo should be hidden in the public interface', function() %7B
 %0A   
@@ -1389,90 +1389,8 @@
 ));%0A
-  %7D);%0A%0A  it('the footer should be hidden from an authenticated user', function() %7B
 %0A   
@@ -1552,96 +1552,8 @@
 ));%0A
-  %7D);%0A%0A  it('the login button should be hidden on the embedded login page', function() %7B
 %0A   
@@ -1644,69 +1644,8 @@
 ));%0A
-  %7D);%0A%0A  it('should allow deletion of the file', function() %7B
 %0A   

Make the CSS test be subject to file upload capability