<commit_before>'use strict';

import _ from 'underscore';

/**
* Test you can visit the Higlass Display page.
*/
describe("HiGlass Display pages", function(){
    context('Higlass Display summary page', function(){
        it('Can visit HiGlass Display summary page without login', function(){
            // Visit the page and confirm you can see the table and facet properties.
            cy.visit('/higlass-view-configs').wait(100).end()
                .get(".search-headers-column-block span.column-title").should('have.text', ['Title', 'Creator', 'Date Created', 'Date Modified'].join('')).end()
                .get(".facets-header .facets-title").should('have.text', 'Properties');

            // You should NOT be able to see the draft higlass view.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']").should('not.exist');
        });

        it('Can visit HiGlass Display summary page after logging in', function(){
            // Log in, visit the page and look for the create button
            cy.visit('/higlass-view-configs').login4DN().wait(500).end()
                .get(".create-add-button .btn").should('have.text', 'Create');

            // You should be able to see the draft higlass view.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");
        });
    });

    context('Individual Higlass display page', function() {
        afterEach(function(){
            // Assuming you're logged in, delete all newly created higlass views.
            cy.request("/higlass-view-configs/?format=json&datastore=database").then((response)=>{

                // Delete the newly created record.
                _.forEach(response.body["@graph"], (higlassViewConf)=>{
                    if (higlassViewConf.submitted_by && higlassViewConf.submitted_by.display_title !== "4dn DCIC") {
                        return;
                    }
                    if (['00000000-1111-0000-1111-000000000001', '00000000-1111-0000-1111-000000000002'].indexOf(higlassViewConf.uuid) !== -1) {
                        return;
                    }
                    cy.request("DELETE", higlassViewConf["@id"]).wait(100).then(() => {
                        cy.log(higlassViewConf["@id"]);
                    });
                });
            });
        });

        it('Can clone new draft views', function() {
            // Verify logged in users can save higlass displays.

            // Log in.
            cy.visit('/higlass-view-configs/').login4DN().wait(500);

            // Go to the display for the draft display.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");

            cy.visit(draftUrl);

            // Get the raw JSON of the display.
            let originalJson = null;
            cy.request(draftUrl + "?format=json&datastore=database").then((resp)=>{
                originalJson = resp.body;
            });

            // Click the save as button.
            cy.get('.text-right.inline-block .inline-block:nth-child(2) button.btn.btn-success').click().then(() => {
                // Confirm the underlying JSON of the original has not changed.
                cy.request(draftUrl + "?format=json&datastore=database").then((newJson)=>{
                    const newJsonStr = JSON.stringify(newJson.body);
                    const originalJsonStr = JSON.stringify(originalJson);
                    expect(newJsonStr).to.equal(originalJsonStr);
                });

                // Confirm there is a success message.
                cy.get('.alert div').should('have.text', 'Saved new display.');
            });
        });

        it('Can edit the title and description', function(){
            // Log in
            cy.visit('/higlass-view-configs/').login4DN().wait(500);

            // Go to the display for the view conf display.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");

            cy.visit(draftUrl);

            // Click Save As to make a new copy.
            cy.get('.text-right.inline-block .inline-block:nth-child(2) button.btn.btn-success').click().then(() => {
                // Visit the newly created viewconf.
                cy.request("/higlass-view-configs/?format=json&datastore=database").then((response)=>{
                    const newViewConf = _.filter(response.body["@graph"], (higlassViewConf)=>{
                        return (higlassViewConf.submitted_by && higlassViewConf.submitted_by.display_title === "4dn DCIC");
                    })[0];

                    // Click on the edit button and wait for the page load.
                    cy.get(".action-button[data-action='edit'] a").click();

                    // Change the title and description, then save.
                    const newTitle = "Cypress Cool Display";
                    const newDescription = "Look at the description";
                    cy.get("input#field_for_title").clear().type(newTitle).then(() => {
                        cy.get('#field_for_description').clear().type(newDescription).then(() => {
                            // Click validate then click submit
                            cy.get(".action-buttons-container button.btn-info").click().then(() => {
                                cy.get(".action-buttons-container button.btn-success").click().then(() => {
                                    // Once the page reloads, look for the updated title/description
                                    cy.request(draftUrl + "?format=json&datastore=database").then((resp)=>{
                                        expect(resp.body.title ).to.equal(newTitle);

                                        expect(resp.body.description ).to.equal(newDescription);
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});<commit_msg>viewconf_item: Fixed test bug that overwrote fixtures.<commit_after>'use strict';

import _ from 'underscore';

/**
* Test you can visit the Higlass Display page.
*/
describe("HiGlass Display pages", function(){
    context('Higlass Display summary page', function(){
        it('Can visit HiGlass Display summary page without login', function(){
            // Visit the page and confirm you can see the table and facet properties.
            cy.visit('/higlass-view-configs').wait(100).end()
                .get(".search-headers-column-block span.column-title").should('have.text', ['Title', 'Creator', 'Date Created', 'Date Modified'].join('')).end()
                .get(".facets-header .facets-title").should('have.text', 'Properties');

            // You should NOT be able to see the draft higlass view.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']").should('not.exist');
        });

        it('Can visit HiGlass Display summary page after logging in', function(){
            // Log in, visit the page and look for the create button
            cy.visit('/higlass-view-configs').login4DN().wait(500).end()
                .get(".create-add-button .btn").should('have.text', 'Create');

            // You should be able to see the draft higlass view.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");
        });
    });

    context('Individual Higlass display page', function() {

        beforeEach(function(){
            // Log in.
            cy.visit('/higlass-view-configs/').login4DN().wait(500);

            // Delete all newly created higlass views.
            const userDisplayTitle = "4dn DCIC";
            cy.request("/higlass-view-configs/?format=json&datastore=database").then((response)=>{

                // Delete the newly created record.
                _.forEach(response.body["@graph"], (higlassViewConf)=>{
                    if (higlassViewConf.submitted_by && higlassViewConf.submitted_by.display_title != userDisplayTitle) {
                        return;
                    }
                    if (['00000000-1111-0000-1111-000000000001', '00000000-1111-0000-1111-000000000002'].indexOf(higlassViewConf.uuid) !== -1) {
                        return;
                    }
                    cy.request("DELETE", higlassViewConf["@id"]).wait(100).then(() => {
                        cy.log(higlassViewConf["@id"]);
                    });
                });
            });
        });

/*
        it('Can clone new draft views', function() {
            // Verify logged in users can save higlass displays.

            // You should be logged in already.
            // Go to the display for the draft display.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");

            cy.visit(draftUrl);

            // Get the raw JSON of the display.
            let originalJson = null;
            cy.request(draftUrl + "?format=json&datastore=database").then((resp)=>{
                originalJson = resp.body;
            });

            // Click the save as button.
            cy.get('.text-right.inline-block .inline-block:nth-child(2) button.btn.btn-success').click().then(() => {
                // Confirm the underlying JSON of the original has not changed.
                cy.request(draftUrl + "?format=json&datastore=database").then((newJson)=>{
                    const newJsonStr = JSON.stringify(newJson.body);
                    const originalJsonStr = JSON.stringify(originalJson);
                    expect(newJsonStr).to.equal(originalJsonStr);
                });

                // Confirm there is a success message.
                cy.get('.alert div').should('have.text', 'Saved new display.');
            });
        });
*/
        it('Can edit the title and description', function(){
            // Assuming you are already logged in,
            // Go to the display for the view conf display.
            const draftUrl = "/higlass-view-configs/00000000-1111-0000-1111-000000000002/";
            cy.get("a[href='" + draftUrl + "']");

            cy.visit(draftUrl);

            // Click Save As to make a new copy.
            cy.get('.text-right.inline-block .inline-block:nth-child(2) button.btn.btn-success').click().wait(10000).then(() => {
                cy.visit("/higlass-view-configs/?datastore=database");
                // Visit the newly created viewconf.
                cy.request("/higlass-view-configs/?format=json&datastore=database").then((response)=>{
                    const newViewConf = _.filter(response.body["@graph"], (higlassViewConf)=>{
                        if (['00000000-1111-0000-1111-000000000001', '00000000-1111-0000-1111-000000000002'].indexOf(higlassViewConf.uuid) !== -1) {
                            return false;
                        }

                        return (higlassViewConf.submitted_by && higlassViewConf.submitted_by.display_title === "4dn DCIC");
                    })[0];

                    cy.visit("/higlass-view-configs/" + newViewConf.uuid);

                    // Click on the edit button and wait for the page load.
                    cy.get(".action-button[data-action='edit'] a").click();

                    // Change the title and description, then save.
                    const newTitle = "Cypress Cool Display";
                    const newDescription = "Look at the description";
                    cy.get("input#field_for_title").clear().type(newTitle).then(() => {
                        cy.get('#field_for_description').clear().type(newDescription).then(() => {
                            // Click validate then click submit
                            cy.get(".action-buttons-container button.btn-info").click().then(() => {
                                cy.get(".action-buttons-container button.btn-success").click().wait(10000).then(() => {
                                    // Once the page reloads, look for the updated title/description
                                    cy.request("/higlass-view-configs/" + newViewConf.uuid + "/?format=json&datastore=database").then((resp)=>{
                                        expect(resp.body.title ).to.equal(newTitle);

                                        expect(resp.body.description ).to.equal(newDescription);
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});
{'fraction_non_alphanumeric': 0.1418123027176842, 'fraction_numerical': 0.03872507506351528, 'mean_word_length': 1.66516208453016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 28, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5396649', 'n_tokens_mistral': 3792, 'n_tokens_neox': 3203, 'n_words': 710}