Ghost/ghost/admin/tests/integration/components/gh-file-uploader-test.js

368 lines
14 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
import Pretender from 'pretender';
import Service from '@ember/service';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import {UnsupportedMediaTypeError} from 'ghost-admin/services/ajax';
import {click, find, findAll, render, settled, triggerEvent} from '@ember/test-helpers';
import {createFile, fileUpload} from '../../helpers/file-upload';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {run} from '@ember/runloop';
import {setupRenderingTest} from 'ember-mocha';
const notificationsStub = Service.extend({
showAPIError() {
// noop - to be stubbed
}
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
const stubSuccessfulUpload = function (server, delay = 0) {
server.post('/ghost/api/v3/admin/images/', function () {
return [200, {'Content-Type': 'application/json'}, '{"url":"/content/images/test.png"}'];
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
}, delay);
};
const stubFailedUpload = function (server, code, error, delay = 0) {
server.post('/ghost/api/v3/admin/images/', function () {
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
return [code, {'Content-Type': 'application/json'}, JSON.stringify({
errors: [{
type: error,
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
message: `Error: ${error}`
}]
})];
}, delay);
};
describe('Integration: Component: gh-file-uploader', function () {
setupRenderingTest();
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
2016-11-24 01:50:57 +03:00
let server;
2016-11-24 01:50:57 +03:00
beforeEach(function () {
server = new Pretender();
this.set('uploadUrl', '/ghost/api/v3/admin/images/');
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
this.owner.register('service:notifications', notificationsStub);
2016-11-24 01:50:57 +03:00
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
2016-11-24 01:50:57 +03:00
afterEach(function () {
server.shutdown();
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
it('renders', async function () {
await render(hbs`{{gh-file-uploader}}`);
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
expect(find('label').textContent.trim(), 'default label')
2016-11-24 01:50:57 +03:00
.to.equal('Select or drag-and-drop a file');
});
it('allows file input "accept" attribute to be changed', async function () {
await render(hbs`{{gh-file-uploader}}`);
2016-11-24 01:50:57 +03:00
expect(
find('input[type="file"]').getAttribute('accept'),
2016-11-24 01:50:57 +03:00
'default "accept" attribute'
).to.equal('text/csv');
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
await render(hbs`{{gh-file-uploader accept="application/zip"}}`);
2016-11-24 01:50:57 +03:00
expect(
find('input[type="file"]').getAttribute('accept'),
2016-11-24 01:50:57 +03:00
'specified "accept" attribute'
).to.equal('application/zip');
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
it('renders form with supplied label text', async function () {
2016-11-24 01:50:57 +03:00
this.set('labelText', 'My label');
await render(hbs`{{gh-file-uploader labelText=labelText}}`);
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
expect(find('label').textContent.trim(), 'label')
2016-11-24 01:50:57 +03:00
.to.equal('My label');
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
it('generates request to supplied endpoint', async function () {
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
2016-11-24 01:50:57 +03:00
expect(server.handledRequests.length).to.equal(1);
expect(server.handledRequests[0].url).to.equal('/ghost/api/v3/admin/images/');
2016-11-24 01:50:57 +03:00
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
it('fires uploadSuccess action on successful upload', async function () {
2016-11-24 01:50:57 +03:00
let uploadSuccess = sinon.spy();
this.set('uploadSuccess', uploadSuccess);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadSuccess=(action uploadSuccess)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(uploadSuccess.calledOnce).to.be.true;
expect(uploadSuccess.firstCall.args[0]).to.eql({url: '/content/images/test.png'});
2016-11-24 01:50:57 +03:00
});
it('doesn\'t fire uploadSuccess action on failed upload', async function () {
2016-11-24 01:50:57 +03:00
let uploadSuccess = sinon.spy();
this.set('uploadSuccess', uploadSuccess);
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 500);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadSuccess=(action uploadSuccess)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
await settled();
expect(uploadSuccess.calledOnce).to.be.false;
2016-11-24 01:50:57 +03:00
});
it('fires fileSelected action on file selection', async function () {
2016-11-24 01:50:57 +03:00
let fileSelected = sinon.spy();
this.set('fileSelected', fileSelected);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl fileSelected=(action fileSelected)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(fileSelected.calledOnce).to.be.true;
expect(fileSelected.args[0]).to.not.be.empty;
2016-11-24 01:50:57 +03:00
});
it('fires uploadStarted action on upload start', async function () {
2016-11-24 01:50:57 +03:00
let uploadStarted = sinon.spy();
this.set('uploadStarted', uploadStarted);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadStarted=(action uploadStarted)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(uploadStarted.calledOnce).to.be.true;
2016-11-24 01:50:57 +03:00
});
it('fires uploadFinished action on successful upload', async function () {
2016-11-24 01:50:57 +03:00
let uploadFinished = sinon.spy();
this.set('uploadFinished', uploadFinished);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadFinished=(action uploadFinished)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(uploadFinished.calledOnce).to.be.true;
2016-11-24 01:50:57 +03:00
});
it('fires uploadFinished action on failed upload', async function () {
2016-11-24 01:50:57 +03:00
let uploadFinished = sinon.spy();
this.set('uploadFinished', uploadFinished);
2016-11-24 01:50:57 +03:00
stubFailedUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadFinished=(action uploadFinished)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(uploadFinished.calledOnce).to.be.true;
2016-11-24 01:50:57 +03:00
});
it('displays invalid file type error', async function () {
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 415, 'UnsupportedMediaTypeError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/The file type you uploaded is not supported/);
expect(findAll('.gh-btn-green').length, 'reset button is displayed').to.equal(1);
expect(find('.gh-btn-green').textContent).to.equal('Try Again');
2016-11-24 01:50:57 +03:00
});
it('displays file too large for server error', async function () {
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 413, 'RequestEntityTooLargeError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/The file you uploaded was larger/);
2016-11-24 01:50:57 +03:00
});
it('handles file too large error directly from the web server', async function () {
server.post('/ghost/api/v3/admin/images/', function () {
2016-11-24 01:50:57 +03:00
return [413, {}, ''];
});
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/The file you uploaded was larger/);
2016-11-24 01:50:57 +03:00
});
it('displays other server-side error with message', async function () {
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 400, 'UnknownError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/Error: UnknownError/);
2016-11-24 01:50:57 +03:00
});
it('handles unknown failure', async function () {
server.post('/ghost/api/v3/admin/images/', function () {
2016-11-24 01:50:57 +03:00
return [500, {'Content-Type': 'application/json'}, ''];
});
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/Something went wrong/);
2016-11-24 01:50:57 +03:00
});
it('triggers notifications.showAPIError for VersionMismatchError', async function () {
2016-11-24 01:50:57 +03:00
let showAPIError = sinon.spy();
let notifications = this.owner.lookup('service:notifications');
notifications.set('showAPIError', showAPIError);
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 400, 'VersionMismatchError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(showAPIError.calledOnce).to.be.true;
2016-11-24 01:50:57 +03:00
});
it('doesn\'t trigger notifications.showAPIError for other errors', async function () {
2016-11-24 01:50:57 +03:00
let showAPIError = sinon.spy();
let notifications = this.owner.lookup('service:notifications');
notifications.set('showAPIError', showAPIError);
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 400, 'UnknownError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(showAPIError.called).to.be.false;
2016-11-24 01:50:57 +03:00
});
it('can be reset after a failed upload', async function () {
2016-11-24 01:50:57 +03:00
stubFailedUpload(server, 400, 'UnknownError');
await render(hbs`{{gh-file-uploader url=uploadUrl}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
await click('.gh-btn-green');
expect(findAll('input[type="file"]').length).to.equal(1);
2016-11-24 01:50:57 +03:00
});
Subscribers: Admin User Interface v1 Initial Subscribers screen - set up mocked api endpoints - basic subscribers screen with data loading, infinite scroll "Add Subscriber" screen - uses modal to display a new subscriber form - validates subscriber e-mail address - moves pagination from route into controller to use filtered/sorted CPs on top of a live-query so that new subscribers are added to the list and the total can be properly managed TODO: - there is currently a pretty serious performance issue where the whole table is re-rendered when the live-query is updated. `ember-light-table` doesn't allow for live-binding and has no options to easily manipulate it's rows using an external interface - it's possible to move the page loading into the component so we only render new rows but that leaves it difficult to react to new subscribers being added through the UI. I believe the number of components used within the table is also adding to the performance problems. - most likely solution is to drop `ember-light-table` in favour of rendering the table directly - glimmer should do a good job of fast updates even though the underlying array will be completely swapped out "Import subscribers" screen - uses modal to display an import subscribers CSV file upload form - displays upload progress - displays import stats and reloads subscribers table once import has completed - adds `gh-file-uploader` component (NB. pared down copy of `gh-image-uploader`, ripe for some refactoring) - fixes subscribers acceptance test failing because fixtures did not have the labs flag enabled Unfortunately this doesn't have 100% test coverage as we're limited in how we can simulate file uploads 😞 Fix performance issues with subscribers table - moves the table definition from the component up to the controller - switches back to manually manipulating table rows instead of using a live-query This is a quick-fix in that it allows us to continue using the `ember-light-table` component but it does mean that we lose some flexibility that the live-query gave us. For now it's not much of an issue and it allows us to defer deeper performance/flexibility work until we have a concrete need and requirements. Hook up Export CSV button - use a hidden iFrame to trigger the browser to hit the CSV export endpoint and download the file Re-order subscribers table by clicking column headers - displays currently sorted column and sort direction - clicking a column header re-fetches the data from the server with the appropriate query params Fix scroll triggers for infinite pagination + icon change - adds a debounce as well as the throttle so that we always get a final scroll trigger once scrolling has stopped - changes the subscribers icon from the temporary team icon to the mail icon
2016-04-15 17:45:50 +03:00
it('handles drag over/leave', async function () {
await render(hbs`{{gh-file-uploader}}`);
2016-11-24 01:50:57 +03:00
run(() => {
// eslint-disable-next-line new-cap
2016-11-24 01:50:57 +03:00
let dragover = $.Event('dragover', {
dataTransfer: {
2016-11-24 01:50:57 +03:00
files: []
}
});
$(find('.gh-image-uploader')).trigger(dragover);
2016-11-24 01:50:57 +03:00
});
await settled();
expect(find('.gh-image-uploader').classList.contains('-drag-over'), 'has drag-over class').to.be.true;
await triggerEvent('.gh-image-uploader', 'dragleave');
expect(find('.gh-image-uploader').classList.contains('-drag-over'), 'has drag-over class').to.be.false;
2016-11-24 01:50:57 +03:00
});
it('triggers file upload on file drop', async function () {
2016-11-24 01:50:57 +03:00
let uploadSuccess = sinon.spy();
// eslint-disable-next-line new-cap
let drop = $.Event('drop', {
dataTransfer: {
files: [createFile(['test'], {name: 'test.csv'})]
}
});
2016-11-24 01:50:57 +03:00
this.set('uploadSuccess', uploadSuccess);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader url=uploadUrl uploadSuccess=(action uploadSuccess)}}`);
2016-11-24 01:50:57 +03:00
run(() => {
$(find('.gh-image-uploader')).trigger(drop);
2016-11-24 01:50:57 +03:00
});
await settled();
expect(uploadSuccess.calledOnce).to.be.true;
expect(uploadSuccess.firstCall.args[0]).to.eql({url: '/content/images/test.png'});
2016-11-24 01:50:57 +03:00
});
it('validates extension by default', async function () {
2016-11-24 01:50:57 +03:00
let uploadSuccess = sinon.spy();
let uploadFailed = sinon.spy();
2016-11-24 01:50:57 +03:00
this.set('uploadSuccess', uploadSuccess);
this.set('uploadFailed', uploadFailed);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader
2016-11-24 01:50:57 +03:00
url=uploadUrl
uploadSuccess=(action uploadSuccess)
uploadFailed=(action uploadFailed)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.txt'});
expect(uploadSuccess.called).to.be.false;
expect(uploadFailed.calledOnce).to.be.true;
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/The file type you uploaded is not supported/);
2016-11-24 01:50:57 +03:00
});
it('uploads if validate action supplied and returns true', async function () {
2016-11-24 01:50:57 +03:00
let validate = sinon.stub().returns(true);
let uploadSuccess = sinon.spy();
2016-11-24 01:50:57 +03:00
this.set('validate', validate);
this.set('uploadSuccess', uploadSuccess);
2016-11-24 01:50:57 +03:00
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader
2016-11-24 01:50:57 +03:00
url=uploadUrl
uploadSuccess=(action uploadSuccess)
validate=(action validate)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
await settled();
expect(validate.calledOnce).to.be.true;
expect(uploadSuccess.calledOnce).to.be.true;
2016-11-24 01:50:57 +03:00
});
it('skips upload and displays error if validate action supplied and doesn\'t return true', async function () {
2016-11-24 01:50:57 +03:00
let validate = sinon.stub().returns(new UnsupportedMediaTypeError());
let uploadSuccess = sinon.spy();
let uploadFailed = sinon.spy();
this.set('validate', validate);
this.set('uploadSuccess', uploadSuccess);
this.set('uploadFailed', uploadFailed);
stubSuccessfulUpload(server);
await render(hbs`{{gh-file-uploader
2016-11-24 01:50:57 +03:00
url=uploadUrl
uploadSuccess=(action uploadSuccess)
uploadFailed=(action uploadFailed)
validate=(action validate)}}`);
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
2016-11-24 01:50:57 +03:00
expect(validate.calledOnce).to.be.true;
expect(uploadSuccess.called).to.be.false;
expect(uploadFailed.calledOnce).to.be.true;
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/The file type you uploaded is not supported/);
2016-11-24 01:50:57 +03:00
});
});