Updated styles in javascript to fulfill adidas rules

This commit is contained in:
Alejandro Celaya
2018-08-25 23:39:27 +02:00
parent ed0aa68452
commit 6a016d8e6f
70 changed files with 1250 additions and 759 deletions

View File

@@ -1,8 +1,8 @@
import React from 'react';
import { shallow } from 'enzyme';
import { CreateServer } from '../../src/servers/CreateServer';
import { identity } from 'ramda';
import sinon from 'sinon';
import { CreateServerComponent } from '../../src/servers/CreateServer';
import ImportServersBtn from '../../src/servers/helpers/ImportServersBtn';
describe('<CreateServer />', () => {
@@ -17,7 +17,7 @@ describe('<CreateServer />', () => {
historyMock.push.resetHistory();
wrapper = shallow(
<CreateServer
<CreateServerComponent
createServer={createServerMock}
resetSelectedServer={identity}
history={historyMock}
@@ -41,7 +41,10 @@ describe('<CreateServer />', () => {
it('creates server and redirects to it when form is submitted', () => {
const form = wrapper.find('form');
form.simulate('submit', { preventDefault: () => {} });
form.simulate('submit', { preventDefault() {
return '';
} });
expect(createServerMock.callCount).toEqual(1);
expect(historyMock.push.callCount).toEqual(1);

View File

@@ -1,13 +1,14 @@
import React from 'react';
import DeleteServerButton from '../../src/servers/DeleteServerButton';
import { shallow } from 'enzyme';
import DeleteServerButton from '../../src/servers/DeleteServerButton';
import DeleteServerModal from '../../src/servers/DeleteServerModal';
describe('<DeleteServerButton />', () => {
let wrapper;
beforeEach(() =>
wrapper = shallow(<DeleteServerButton server={{}} className="button" />));
beforeEach(() => {
wrapper = shallow(<DeleteServerButton server={{}} className="button" />);
});
afterEach(() => wrapper.unmount());
it('renders a button and a modal', () => {

View File

@@ -1,8 +1,8 @@
import React from 'react';
import { shallow } from 'enzyme';
import { DeleteServerModal } from '../../src/servers/DeleteServerModal';
import sinon from 'sinon';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { DeleteServerModalComponent } from '../../src/servers/DeleteServerModal';
describe('<DeleteServerModal />', () => {
let wrapper;
@@ -17,7 +17,7 @@ describe('<DeleteServerModal />', () => {
historyMock.push.resetHistory();
wrapper = shallow(
<DeleteServerModal
<DeleteServerModalComponent
server={{ name: serverName }}
toggle={toggleMock}
isOpen={true}
@@ -37,6 +37,7 @@ describe('<DeleteServerModal />', () => {
it('displays the name of the server as part of the content', () => {
const modalBody = wrapper.find(ModalBody);
expect(modalBody.find('p').first().text()).toEqual(
`Are you sure you want to delete server ${serverName}?`
);
@@ -44,6 +45,7 @@ describe('<DeleteServerModal />', () => {
it('toggles when clicking cancel button', () => {
const cancelBtn = wrapper.find('button').first();
cancelBtn.simulate('click');
expect(toggleMock.callCount).toEqual(1);
@@ -53,6 +55,7 @@ describe('<DeleteServerModal />', () => {
it('deletes server when clicking accept button', () => {
const acceptBtn = wrapper.find('button').last();
acceptBtn.simulate('click');
expect(toggleMock.callCount).toEqual(1);

View File

@@ -1,34 +1,37 @@
import { identity } from 'ramda';
import { identity, values } from 'ramda';
import React from 'react';
import { ServersDropdown } from '../../src/servers/ServersDropdown';
import { shallow } from 'enzyme';
import { DropdownItem, DropdownToggle } from 'reactstrap';
import { ServersDropdownComponent } from '../../src/servers/ServersDropdown';
describe('<ServersDropdown />', () => {
let wrapped;
const servers = [{ name: 'foo', id: 1 }, { name: 'bar', id: 2 }, { name: 'baz', id: 3 }];
const servers = {
'1a': { name: 'foo', id: 1 },
'2b': { name: 'bar', id: 2 },
'3c': { name: 'baz', id: 3 },
};
beforeEach(() => {
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} />);
wrapped = shallow(<ServersDropdownComponent servers={servers} listServers={identity} />);
});
afterEach(() => wrapped.unmount());
it('contains the list of servers', () =>
expect(wrapped.find(DropdownItem).filter('[to]')).toHaveLength(servers.length)
);
expect(wrapped.find(DropdownItem).filter('[to]')).toHaveLength(values(servers).length));
it('contains a toggle with proper title', () =>
expect(wrapped.find(DropdownToggle)).toHaveLength(1)
);
expect(wrapped.find(DropdownToggle)).toHaveLength(1));
it('contains a button to export servers', () => {
const items = wrapped.find(DropdownItem);
expect(items.filter('[divider]')).toHaveLength(1);
expect(items.filter('.servers-dropdown__export-item')).toHaveLength(1);
});
it('contains a message when no servers exist yet', () => {
wrapped = shallow(<ServersDropdown servers={[]} listServers={identity} />);
wrapped = shallow(<ServersDropdownComponent servers={{}} listServers={identity} />);
const item = wrapped.find(DropdownItem);
expect(item).toHaveLength(1);

View File

@@ -1,8 +1,8 @@
import React from 'react';
import { ImportServersBtn } from '../../../src/servers/helpers/ImportServersBtn';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import { UncontrolledTooltip } from 'reactstrap';
import { ImportServersBtnComponent } from '../../../src/servers/helpers/ImportServersBtn';
describe('<ImportServersBtn />', () => {
let wrapper;
@@ -12,7 +12,7 @@ describe('<ImportServersBtn />', () => {
importServersFromFile: sinon.fake.returns(Promise.resolve([])),
};
const fileRef = {
current: { click: sinon.fake() }
current: { click: sinon.fake() },
};
beforeEach(() => {
@@ -22,11 +22,11 @@ describe('<ImportServersBtn />', () => {
fileRef.current.click.resetHistory();
wrapper = shallow(
<ImportServersBtn
onImport={onImportMock}
<ImportServersBtnComponent
createServers={createServersMock}
serversImporter={serversImporterMock}
fileRef={fileRef}
onImport={onImportMock}
/>
);
});
@@ -40,14 +40,16 @@ describe('<ImportServersBtn />', () => {
it('triggers click on file ref when button is clicked', () => {
const btn = wrapper.find('#importBtn');
btn.simulate('click');
expect(fileRef.current.click.callCount).toEqual(1);
});
it('imports servers when file input changes', done => {
it('imports servers when file input changes', (done) => {
const file = wrapper.find('.create-server__csv-select');
file.simulate('change', { target: { files: [''] } });
file.simulate('change', { target: { files: [ '' ] } });
setImmediate(() => {
expect(serversImporterMock.importServersFromFile.callCount).toEqual(1);

View File

@@ -1,24 +1,23 @@
import * as sinon from 'sinon';
import reduce, {
_selectServer,
RESET_SELECTED_SERVER,
resetSelectedServer,
SELECT_SERVER,
} from '../../../src/servers/reducers/selectedServer';
import * as sinon from 'sinon';
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
describe('selectedServerReducer', () => {
describe('reduce', () => {
it('returns default when action is not handled', () =>
expect(reduce(null, { type: 'unknown' })).toEqual(null)
);
expect(reduce(null, { type: 'unknown' })).toEqual(null));
it('returns default when action is RESET_SELECTED_SERVER', () =>
expect(reduce(null, { type: RESET_SELECTED_SERVER })).toEqual(null)
);
expect(reduce(null, { type: RESET_SELECTED_SERVER })).toEqual(null));
it('returns selected server when action is SELECT_SERVER', () => {
const selectedServer = { id: 'abc123' };
expect(reduce(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer);
});
});
@@ -31,14 +30,14 @@ describe('selectedServerReducer', () => {
describe('selectServer', () => {
const ShlinkApiClientMock = {
setConfig: sinon.spy()
setConfig: sinon.spy(),
};
const serverId = 'abc123';
const selectedServer = {
id: serverId
id: serverId,
};
const ServersServiceMock = {
findServerById: sinon.fake.returns(selectedServer)
findServerById: sinon.fake.returns(selectedServer),
};
afterEach(() => {
@@ -48,14 +47,15 @@ describe('selectedServerReducer', () => {
it('dispatches proper actions', () => {
const dispatch = sinon.spy();
const expectedDispatchCalls = 2;
_selectServer(ShlinkApiClientMock, ServersServiceMock, serverId)(dispatch);
expect(dispatch.callCount).toEqual(2);
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true);
expect(dispatch.secondCall.calledWith({
type: SELECT_SERVER,
selectedServer
selectedServer,
})).toEqual(true);
});

View File

@@ -1,3 +1,5 @@
import * as sinon from 'sinon';
import { values } from 'ramda';
import reduce, {
_createServer,
_deleteServer,
@@ -5,13 +7,11 @@ import reduce, {
_createServers,
FETCH_SERVERS,
} from '../../../src/servers/reducers/server';
import * as sinon from 'sinon';
import { values } from 'ramda';
describe('serverReducer', () => {
const servers = {
abc123: { id: 'abc123' },
def456: { id: 'def456' }
def456: { id: 'def456' },
};
const ServersServiceMock = {
listServers: sinon.fake.returns(servers),
@@ -22,12 +22,10 @@ describe('serverReducer', () => {
describe('reduce', () => {
it('returns servers when action is FETCH_SERVERS', () =>
expect(reduce({}, { type: FETCH_SERVERS, servers })).toEqual(servers)
);
expect(reduce({}, { type: FETCH_SERVERS, servers })).toEqual(servers));
it('returns default when action is unknown', () =>
expect(reduce({}, { type: 'unknown' })).toEqual({})
);
expect(reduce({}, { type: 'unknown' })).toEqual({}));
});
describe('action creators', () => {

View File

@@ -1,5 +1,5 @@
import { ServersExporter } from '../../../src/servers/services/ServersExporter';
import sinon from 'sinon';
import { ServersExporter } from '../../../src/servers/services/ServersExporter';
describe('ServersExporter', () => {
const createLinkMock = () => ({
@@ -17,7 +17,7 @@ describe('ServersExporter', () => {
appendChild: sinon.fake(),
removeChild: sinon.fake(),
},
}
},
});
const serversServiceMock = {
listServers: sinon.fake.returns({
@@ -41,11 +41,13 @@ describe('ServersExporter', () => {
beforeEach(() => {
originalConsole = global.console;
global.console = { error: sinon.fake() };
global.Blob = function Blob() {};
global.Blob = class Blob {};
global.URL = { createObjectURL: () => '' };
serversServiceMock.listServers.resetHistory();
});
afterEach(() => global.console = originalConsole);
afterEach(() => {
global.console = originalConsole;
});
it('logs an error if something fails', () => {
const csvjsonMock = createCsvjsonMock(true);

View File

@@ -1,5 +1,5 @@
import { ServersImporter } from '../../../src/servers/services/ServersImporter';
import sinon from 'sinon';
import { ServersImporter } from '../../../src/servers/services/ServersImporter';
describe('ServersImporter', () => {
const servers = [{ name: 'foo' }, { name: 'bar' }];
@@ -29,10 +29,13 @@ describe('ServersImporter', () => {
it('reads file when a CSV is provided', async () => {
const readAsText = sinon.fake.returns('');
global.FileReader = function FileReader() {
this.readAsText = readAsText;
this.addEventListener = (eventName, listener) =>
listener({ target: { result: '' } });
global.FileReader = class FileReader {
constructor() {
this.readAsText = readAsText;
this.addEventListener = (eventName, listener) =>
listener({ target: { result: '' } });
}
};
await importer.importServersFromFile({ type: 'text/csv' });

View File

@@ -1,13 +1,13 @@
import { ServersService } from '../../../src/servers/services/ServersService';
import sinon from 'sinon';
import { last } from 'ramda';
import { ServersService } from '../../../src/servers/services/ServersService';
describe('ServersService', () => {
const servers = {
abc123: { id: 'abc123' },
def456: { id: 'def456' },
};
const createStorageMock = returnValue => ({
const createStorageMock = (returnValue) => ({
set: sinon.fake(),
get: sinon.fake.returns(returnValue),
});