mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-21 14:06:19 +00:00
Flatten model holding list of servers
This commit is contained in:
@@ -6,7 +6,7 @@ describe('<Home />', () => {
|
||||
let wrapped;
|
||||
const defaultProps = {
|
||||
resetSelectedServer: jest.fn(),
|
||||
servers: { loading: false, list: {} },
|
||||
servers: {},
|
||||
};
|
||||
const createComponent = (props) => {
|
||||
const actualProps = { ...defaultProps, ...props };
|
||||
@@ -24,20 +24,12 @@ describe('<Home />', () => {
|
||||
expect(wrapped.find('Link')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('shows message when loading servers', () => {
|
||||
const wrapped = createComponent({ servers: { loading: true } });
|
||||
const span = wrapped.find('span');
|
||||
|
||||
expect(span).toHaveLength(1);
|
||||
expect(span.text()).toContain('Trying to load servers...');
|
||||
});
|
||||
|
||||
it('Asks to select a server when not loadign and servers exist', () => {
|
||||
const list = [
|
||||
{ name: 'foo', id: '1' },
|
||||
{ name: 'bar', id: '2' },
|
||||
];
|
||||
const wrapped = createComponent({ servers: { list } });
|
||||
it('asks to select a server when servers exist', () => {
|
||||
const servers = {
|
||||
1: { name: 'foo', id: '1' },
|
||||
2: { name: 'bar', id: '2' },
|
||||
};
|
||||
const wrapped = createComponent({ servers });
|
||||
const span = wrapped.find('span');
|
||||
|
||||
expect(span).toHaveLength(1);
|
||||
|
||||
@@ -8,12 +8,9 @@ describe('<ServersDropdown />', () => {
|
||||
let wrapped;
|
||||
let ServersDropdown;
|
||||
const servers = {
|
||||
list: {
|
||||
'1a': { name: 'foo', id: 1 },
|
||||
'2b': { name: 'bar', id: 2 },
|
||||
'3c': { name: 'baz', id: 3 },
|
||||
},
|
||||
loading: false,
|
||||
'1a': { name: 'foo', id: 1 },
|
||||
'2b': { name: 'bar', id: 2 },
|
||||
'3c': { name: 'baz', id: 3 },
|
||||
};
|
||||
const history = {
|
||||
push: jest.fn(),
|
||||
@@ -26,7 +23,7 @@ describe('<ServersDropdown />', () => {
|
||||
afterEach(() => wrapped.unmount());
|
||||
|
||||
it('contains the list of servers, the divider and the export button', () =>
|
||||
expect(wrapped.find(DropdownItem)).toHaveLength(values(servers.list).length + 2));
|
||||
expect(wrapped.find(DropdownItem)).toHaveLength(values(servers).length + 2));
|
||||
|
||||
it('contains a toggle with proper title', () =>
|
||||
expect(wrapped.find(DropdownToggle)).toHaveLength(1));
|
||||
@@ -40,7 +37,7 @@ describe('<ServersDropdown />', () => {
|
||||
|
||||
it('shows a message when no servers exist yet', () => {
|
||||
wrapped = shallow(
|
||||
<ServersDropdown servers={{ loading: false, list: {} }} listServers={identity} history={history} />
|
||||
<ServersDropdown servers={{}} listServers={identity} history={history} />
|
||||
);
|
||||
const item = wrapped.find(DropdownItem);
|
||||
|
||||
@@ -48,15 +45,4 @@ describe('<ServersDropdown />', () => {
|
||||
expect(item.prop('disabled')).toEqual(true);
|
||||
expect(item.find('i').text()).toEqual('Add a server first...');
|
||||
});
|
||||
|
||||
it('shows a message when loading', () => {
|
||||
wrapped = shallow(
|
||||
<ServersDropdown servers={{ loading: true, list: {} }} listServers={identity} history={history} />
|
||||
);
|
||||
const item = wrapped.find(DropdownItem);
|
||||
|
||||
expect(item).toHaveLength(1);
|
||||
expect(item.prop('disabled')).toEqual(true);
|
||||
expect(item.find('i').text()).toEqual('Trying to load servers...');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('<ServerError />', () => {
|
||||
])('renders expected information for type "%s"', (type, textsToFind) => {
|
||||
wrapper = shallow(
|
||||
<BrowserRouter>
|
||||
<ServerError type={type} servers={{ list: [] }} selectedServer={selectedServer} />
|
||||
<ServerError type={type} servers={{}} selectedServer={selectedServer} />
|
||||
</BrowserRouter>
|
||||
);
|
||||
const wrapperText = wrapper.html();
|
||||
|
||||
@@ -6,7 +6,6 @@ import reducer, {
|
||||
createServers,
|
||||
editServer,
|
||||
FETCH_SERVERS,
|
||||
FETCH_SERVERS_START,
|
||||
} from '../../../src/servers/reducers/server';
|
||||
|
||||
describe('serverReducer', () => {
|
||||
@@ -27,7 +26,7 @@ describe('serverReducer', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns servers when action is FETCH_SERVERS', () =>
|
||||
expect(reducer({}, { type: FETCH_SERVERS, list })).toEqual({ loading: false, list }));
|
||||
expect(reducer({}, { type: FETCH_SERVERS, list })).toEqual(list));
|
||||
});
|
||||
|
||||
describe('action creators', () => {
|
||||
@@ -39,9 +38,8 @@ describe('serverReducer', () => {
|
||||
it('fetches servers from local storage when found', async () => {
|
||||
await listServers(ServersServiceMock, axios)()(dispatch);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: FETCH_SERVERS_START });
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, expectedFetchServersResult);
|
||||
expect(dispatch).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, expectedFetchServersResult);
|
||||
expect(ServersServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||
expect(ServersServiceMock.createServer).not.toHaveBeenCalled();
|
||||
expect(ServersServiceMock.editServer).not.toHaveBeenCalled();
|
||||
@@ -90,9 +88,8 @@ describe('serverReducer', () => {
|
||||
|
||||
await listServers(NoListServersServiceMock, axios)()(dispatch);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: FETCH_SERVERS_START });
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: FETCH_SERVERS, list: expectedList });
|
||||
expect(dispatch).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: FETCH_SERVERS, list: expectedList });
|
||||
expect(NoListServersServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||
expect(NoListServersServiceMock.createServer).not.toHaveBeenCalled();
|
||||
expect(NoListServersServiceMock.editServer).not.toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user