Skip to content

Commit

Permalink
Add UrlManager tests that waits for the url setup
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Jul 19, 2019
1 parent f68bcc8 commit adcdca9
Showing 1 changed file with 66 additions and 9 deletions.
75 changes: 66 additions & 9 deletions src/test/components/UrlManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import { getUrlSetupPhase } from '../../selectors/app';
import UrlManager from '../../components/app/UrlManager';
import { blankStore } from '../fixtures/stores';
import { getDataSource } from '../../selectors/url-state';
import { waitUntilState } from '../fixtures/utils';
import { createGeckoProfile } from '../fixtures/profiles/gecko-profile';
import * as receiveProfile from '../../actions/receive-profile';

jest.mock('../../profile-logic/symbol-store');

describe('UrlManager', function() {
function setup(urlPath: ?string) {
(receiveProfile: any).doSymbolicateProfile = jest.fn(() => async () => {});

if (typeof urlPath === 'string') {
// jsdom doesn't allow us to rewrite window.location. Instead, use the
// History API to properly set the current location.
Expand All @@ -28,33 +35,83 @@ describe('UrlManager', function() {
<UrlManager>Contents</UrlManager>
</Provider>
);
return { dispatch, getState, createUrlManager };

const waitUntilUrlSetupPhase = phase =>
waitUntilState(store, state => getUrlSetupPhase(state) === phase);

return { dispatch, getState, createUrlManager, waitUntilUrlSetupPhase };
}

it('sets up the URL', function() {
const { getState, createUrlManager } = setup();
beforeEach(function() {
const profileJSON = createGeckoProfile();
const mockGetProfile = jest.fn().mockResolvedValue(profileJSON);

const geckoProfiler = {
getProfile: mockGetProfile,
getSymbolTable: jest
.fn()
.mockRejectedValue(new Error('No symbol tables available')),
};
window.fetch = jest
.fn()
.mockRejectedValue(new Error('No symbolication API in place'));
window.geckoProfilerPromise = Promise.resolve(geckoProfiler);
});

afterEach(function() {
delete window.geckoProfilerPromise;
delete window.fetch;
});

it('sets up the URL', async function() {
const { getState, createUrlManager, waitUntilUrlSetupPhase } = setup();
expect(getUrlSetupPhase(getState())).toBe('initial-load');
createUrlManager();

expect(getUrlSetupPhase(getState())).toBe('loading-profile');

await waitUntilUrlSetupPhase('done');
expect(getUrlSetupPhase(getState())).toBe('done');
expect(getDataSource(getState())).toMatch('none');
});

it('has no data source by default', function() {
const { getState, createUrlManager } = setup();
it('has no data source by default', async function() {
const { getState, createUrlManager, waitUntilUrlSetupPhase } = setup();
createUrlManager();
await waitUntilUrlSetupPhase('done');
expect(getDataSource(getState())).toMatch('none');
});

it('sets the data source to from-addon', function() {
const { getState, createUrlManager } = setup('/from-addon/');
it('sets the data source to from-addon', async function() {
const { getState, createUrlManager, waitUntilUrlSetupPhase } = setup(
'/from-addon/'
);
expect(getDataSource(getState())).toMatch('none');
createUrlManager();

await waitUntilUrlSetupPhase('done');
expect(getDataSource(getState())).toMatch('from-addon');
});

it('redirects from-file back to no data source', function() {
const { getState, createUrlManager } = setup('/from-file/');
it('redirects from-file back to no data source', async function() {
const { getState, createUrlManager, waitUntilUrlSetupPhase } = setup(
'/from-file/'
);
expect(getDataSource(getState())).toMatch('none');
createUrlManager();

await waitUntilUrlSetupPhase('done');
expect(getDataSource(getState())).toMatch('none');
});

it('sets the data source to public', async function() {
const { getState, createUrlManager, waitUntilUrlSetupPhase } = setup(
'/public/'
);
expect(getDataSource(getState())).toMatch('none');
createUrlManager();

await waitUntilUrlSetupPhase('done');
expect(getDataSource(getState())).toMatch('public');
});
});

0 comments on commit adcdca9

Please sign in to comment.