Commit a7e13f22 authored by Giovanni's avatar Giovanni

lighter tests, and a lot of broken ones

parent 4aaa4bfd
Pipeline #62036867 failed with stage
in 1 minute and 25 seconds
......@@ -11,13 +11,14 @@ const axiosMock = new MockAdapter(axios);
process.env.NODE_ENV = 'test';
loadConfig('https://localhost', 'token', 'authType');
Enzyme.configure({adapter: new Adapter()});
jest.mock('react-native-fingerprint-scanner/src', () => ({isSensorAvailable: () => 'Fingerprint'}));
jest.mock('react-native-keychain', () => ({
setGenericPassword: jest.fn(),
getGenericPassword: jest.fn().mockReturnValue({password: JSON.stringify({userToken:"[{\"accessToken\":\"someToken\", \"type\":\"token\", \"url\": \"https://someGitlabUrl.com\"}]"})}),
setGenericPassword: jest.fn(),
resetGenericPassword: jest.fn()
}));
......@@ -51,5 +52,4 @@ function suppressDomErrors() {
};
}
suppressDomErrors();
require('./App');
\ No newline at end of file
suppressDomErrors();
\ No newline at end of file
......@@ -8,6 +8,15 @@ describe('Branches', () => {
let Branches;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
setStore(getStore());
});
beforeEach(() => {
Branches = getRegisteredRoutes().Branches;
......
......@@ -46,6 +46,16 @@ describe('CommitDiff', () => {
let CommitDiff;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
require('../../mergeRequest/reducers');
setStore(getStore());
});
beforeEach(() => {
CommitDiff = getRegisteredRoutes().CommitDiff;
......
......@@ -20,6 +20,15 @@ describe('Commits', () => {
let Commits;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
setStore(getStore());
});
beforeEach(() => {
Commits = getRegisteredRoutes().Commits;
......
......@@ -8,6 +8,14 @@ describe('AddCredentials', () => {
let AddCredentials;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
setStore(getStore());
});
beforeEach(() => {
AddCredentials = getRegisteredRoutes().AddCredentials;
......
......@@ -7,6 +7,14 @@ describe('AddGitlabUrl', () => {
let AddGitlabUrl;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
setStore(getStore());
});
beforeEach(() => {
AddGitlabUrl = getRegisteredRoutes().AddGitlabUrl;
......
......@@ -9,6 +9,14 @@ describe('HardwareLogin', () => {
let store;
let fingerprint;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
setStore(getStore());
});
beforeEach(() => {
jest.clearAllMocks();
fingerprint = require('react-native-fingerprint-scanner/src');
......
......@@ -8,6 +8,14 @@ describe('ScanFingerprint', () => {
let store;
let fingerprint;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
setStore(getStore());
});
beforeEach(() => {
jest.clearAllMocks();
fingerprint = require('react-native-fingerprint-scanner/src');
......
......@@ -23,6 +23,16 @@ describe('Issue', () => {
let Issue;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
require('../../profile/reducers');
setStore(getStore());
});
beforeEach(() => {
Issue = getRegisteredRoutes().Issue;
......
......@@ -20,6 +20,15 @@ describe('Issues', () => {
let Issues;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
setStore(getStore());
});
beforeEach(() => {
Issues = getRegisteredRoutes().Issues;
......
......@@ -7,6 +7,14 @@ describe('Logout', () => {
let Logout;
let store;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index')
setStore(getStore());
});
beforeEach(() => {
Logout = getRegisteredRoutes().Logout;
......
......@@ -72,22 +72,25 @@ index 4b05446..a706a26 100644
]
};
jest.mock('../actions', () => ({
...jest.requireActual('../actions'),
requestMergeRequest: jest.fn()
}));
describe('MergeRequest', () => {
let MergeRequest;
let store;
let actions;
beforeAll(() => {
const {setStore} = require("api");
const {getStore} = require('store');
require('../index');
require('../../repository/reducers');
require('../../profile/reducers');
setStore(getStore());
});
beforeEach(() => {
actions = require('../actions');
MergeRequest = getRegisteredRoutes().MergeRequest;
const {getStore} = require('store');
store = getStore();
store = require('store').getStore();
onGet({url: /discussions/, data: fakeDiscussions});
onGet({url: /compare*/, data: fakeDiffs});
onGet({url: /diff*/, data: fakeDiffs.diffs});
......@@ -104,7 +107,6 @@ describe('MergeRequest', () => {
onGet({url: /merge_requests*/, data: fakeMergeRequest});
const component = await asyncCreate(<Provider store={store}><MergeRequest/></Provider>);
expect(component.toJSON()).toMatchSnapshot();
});
......@@ -317,8 +319,12 @@ describe('MergeRequest', () => {
});
it('should add one thumb', async () => {
let actions;
jest.isolateModules(() => {
actions = require('../actions');
actions.requestMergeRequest = jest.fn().mockReturnValue({type: 'type'});
});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: {iid: 1}});
actions.requestMergeRequest = jest.fn();
store.dispatch(actions.addThumbs('direction'));
await waitForAsync();
......@@ -326,8 +332,8 @@ describe('MergeRequest', () => {
});
it('should not add one thumb', async () => {
actions.requestMergeRequest = jest.fn().mockReturnValue({type: 'type'});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: []});
actions.requestMergeRequest = jest.fn();
store.dispatch(actions.addThumbs('direction'));
await waitForAsync();
......@@ -335,8 +341,8 @@ describe('MergeRequest', () => {
});
it('should remove one thumb', async () => {
actions.requestMergeRequest = jest.fn().mockReturnValue({type: 'type'});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: {iid: 1}});
actions.requestMergeRequest = jest.fn();
store.dispatch(actions.removeThumbs('id'));
await waitForAsync();
......@@ -344,8 +350,8 @@ describe('MergeRequest', () => {
});
it('should not remove one thumb', async () => {
actions.requestMergeRequest = jest.fn().mockReturnValue({type: 'type'});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: []});
actions.requestMergeRequest = jest.fn();
store.dispatch(actions.removeThumbs('id'));
await waitForAsync();
......@@ -353,8 +359,8 @@ describe('MergeRequest', () => {
});
it('should not comment because there is no mr', async () => {
actions.requestDiscussions = jest.fn().mockReturnValue({type: 'type'});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: []});
actions.requestDiscussions = jest.fn();
store.dispatch(actions.commentMergeRequest('body'));
await waitForAsync();
......@@ -362,8 +368,8 @@ describe('MergeRequest', () => {
});
it('should not edit because there is no mr', async () => {
actions.requestDiscussions = jest.fn().mockReturnValue({type: 'type'});
store.dispatch({type: 'MERGE_REQUEST_RECEIVED', data: []});
actions.requestDiscussions = jest.fn();
store.dispatch(actions.editMergeRequest('changes'));
await waitForAsync();
......
......@@ -126,6 +126,7 @@ export function addThumbs(direction) {
data: {name: direction}
});
console.log(requestMergeRequest)
dispatch(requestMergeRequest(mr.iid));
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment