<commit_before>import $ from 'jquery';
import Pretender from 'pretender';
import Service from '@ember/service';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import {click, find, findAll, render, settled, triggerEvent} from '@ember/test-helpers';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {fileUpload} from '../../helpers/file-upload';
import {run} from '@ember/runloop';
import {setupRenderingTest} from 'ember-mocha';

const notificationsStub = Service.extend({
    showAPIError() {
        // noop - to be stubbed
    }
});

const stubSuccessfulUpload = function (server, delay = 0) {
    server.post('/ghost/api/v3/admin/members/csv/', function () {
        return [200, {'Content-Type': 'application/json'}, '{"url":"/content/images/test.png"}'];
    }, delay);
};

const stubFailedUpload = function (server, code, error, delay = 0) {
    server.post('/ghost/api/v3/admin/members/csv/', function () {
        return [code, {'Content-Type': 'application/json'}, JSON.stringify({
            errors: [{
                type: error,
                message: `Error: ${error}`
            }]
        })];
    }, delay);
};

describe('Integration: Component: modal-import-members-test', function () {
    setupRenderingTest();

    let server;

    beforeEach(function () {
        server = new Pretender();
        this.set('uploadUrl', '/ghost/api/v3/admin/members/csv/');

        this.owner.register('service:notifications', notificationsStub);
    });

    afterEach(function () {
        server.shutdown();
    });

    it('renders', async function () {
        await render(hbs`{{modal-import-members}}`);

        expect(find('h1').textContent.trim(), 'default header')
            .to.equal('Import');
        expect(find('.description').textContent.trim(), 'upload label')
            .to.equal('Select or drag-and-drop a CSV File');
    });

    it('generates request to supplied endpoint', async function () {
        stubSuccessfulUpload(server);

        await render(hbs`{{modal-import-members}}`);
        await fileUpload('input[type="file"]', ['membersfile'], {name: 'test.csv'});
<commit_msg>Fixed test for member import dialog copy changes<commit_after>import $ from 'jquery';
import Pretender from 'pretender';
import Service from '@ember/service';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import {click, find, findAll, render, settled, triggerEvent} from '@ember/test-helpers';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {fileUpload} from '../../helpers/file-upload';
import {run} from '@ember/runloop';
import {setupRenderingTest} from 'ember-mocha';

const notificationsStub = Service.extend({
    showAPIError() {
        // noop - to be stubbed
    }
});

const stubSuccessfulUpload = function (server, delay = 0) {
    server.post('/ghost/api/v3/admin/members/csv/', function () {
        return [200, {'Content-Type': 'application/json'}, '{"url":"/content/images/test.png"}'];
    }, delay);
};

const stubFailedUpload = function (server, code, error, delay = 0) {
    server.post('/ghost/api/v3/admin/members/csv/', function () {
        return [code, {'Content-Type': 'application/json'}, JSON.stringify({
            errors: [{
                type: error,
                message: `Error: ${error}`
            }]
        })];
    }, delay);
};

describe('Integration: Component: modal-import-members-test', function () {
    setupRenderingTest();

    let server;

    beforeEach(function () {
        server = new Pretender();
        this.set('uploadUrl', '/ghost/api/v3/admin/members/csv/');

        this.owner.register('service:notifications', notificationsStub);
    });

    afterEach(function () {
        server.shutdown();
    });

    it('renders', async function () {
        await render(hbs`{{modal-import-members}}`);

        expect(find('h1').textContent.trim(), 'default header')
            .to.equal('Import members');
        expect(find('.description').textContent.trim(), 'upload label')
            .to.equal('Select or drag-and-drop a CSV File');
    });

    it('generates request to supplied endpoint', async function () {
        stubSuccessfulUpload(server);

        await render(hbs`{{modal-import-members}}`);
        await fileUpload('input[type="file"]', ['membersfile'], {name: 'test.csv'});

{'fraction_non_alphanumeric': 0.17035852934459922, 'fraction_numerical': 0.004110527517698105, 'mean_word_length': 3.183381088825215, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3634295', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1274, 'n_words': 294}