-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Disable fixture actions when fixture path is invalid (#911)
- Loading branch information
Showing
25 changed files
with
452 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'jest-dom/extend-expect'; | ||
|
||
// Some end to end server tests can be very slow... | ||
// Especially slow are the server tests which test webpack compilation | ||
jest.setTimeout(180000); // 3min |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/react-cosmos-playground2/src/plugins/FixtureHeader/__tests__/fullscreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import delay from 'delay'; | ||
import { render } from 'react-testing-library'; | ||
import { Slot, loadPlugins } from 'react-plugin'; | ||
import { | ||
cleanup, | ||
mockState, | ||
mockMethod, | ||
mockPlug | ||
} from '../../../testHelpers/plugin'; | ||
import { register } from '..'; | ||
|
||
afterEach(cleanup); | ||
|
||
function registerTestPlugins() { | ||
register(); | ||
mockState('router', { urlParams: { fixturePath: 'foo', fullScreen: true } }); | ||
mockMethod('renderer.isFixturePathValid', () => true); | ||
} | ||
|
||
function loadTestPlugins() { | ||
loadPlugins(); | ||
|
||
return render(<Slot name="fixtureHeader" />); | ||
} | ||
|
||
it('does not render close button', async () => { | ||
registerTestPlugins(); | ||
mockPlug({ slotName: 'fixtureActions', render: 'pluggable actions' }); | ||
const { queryByText } = loadTestPlugins(); | ||
|
||
// Make sure the element doesn't appear async in the next event loops | ||
await delay(100); | ||
expect(queryByText(/close/i)).toBeNull(); | ||
}); | ||
|
||
it('does not render "fixtureActions" slot', async () => { | ||
registerTestPlugins(); | ||
mockPlug({ slotName: 'fixtureActions', render: 'pluggable actions' }); | ||
const { queryByText } = loadTestPlugins(); | ||
|
||
// Make sure the element doesn't appear async in the next event loops | ||
await delay(100); | ||
expect(queryByText(/pluggable actions/i)).toBeNull(); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/react-cosmos-playground2/src/plugins/FixtureHeader/__tests__/missingFixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { render, fireEvent, waitForElement } from 'react-testing-library'; | ||
import { Slot, loadPlugins } from 'react-plugin'; | ||
import { cleanup, mockState, mockMethod } from '../../../testHelpers/plugin'; | ||
import { register } from '..'; | ||
|
||
afterEach(cleanup); | ||
|
||
function registerTestPlugins(handleSetUrlParams = () => {}) { | ||
register(); | ||
mockState('router', { urlParams: { fixturePath: 'foo' } }); | ||
mockMethod('router.setUrlParams', handleSetUrlParams); | ||
mockMethod('renderer.isFixturePathValid', () => false); | ||
} | ||
|
||
function loadTestPlugins() { | ||
loadPlugins(); | ||
|
||
return render(<Slot name="fixtureHeader" />); | ||
} | ||
|
||
it('renders missing state message', async () => { | ||
registerTestPlugins(); | ||
const { getByText } = loadTestPlugins(); | ||
|
||
await waitForElement(() => getByText(/fixture not found/i)); | ||
}); | ||
|
||
it('renders close button', async () => { | ||
const handleSetUrlParams = jest.fn(); | ||
registerTestPlugins(handleSetUrlParams); | ||
|
||
const { getByText } = loadTestPlugins(); | ||
fireEvent.click(getByText(/close/)); | ||
|
||
expect(handleSetUrlParams).toBeCalledWith(expect.any(Object), {}); | ||
}); | ||
|
||
it('renders disabled fullscreen button', async () => { | ||
registerTestPlugins(); | ||
const { getByText } = loadTestPlugins(); | ||
|
||
expect(getByText(/fullscreen/i)).toHaveAttribute('disabled'); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/react-cosmos-playground2/src/plugins/FixtureHeader/__tests__/noFixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { render, waitForElement } from 'react-testing-library'; | ||
import { Slot, loadPlugins } from 'react-plugin'; | ||
import { cleanup, mockState, mockMethod } from '../../../testHelpers/plugin'; | ||
import { register } from '..'; | ||
|
||
afterEach(cleanup); | ||
|
||
function registerTestPlugins() { | ||
register(); | ||
mockState('router', { urlParams: {} }); | ||
mockMethod('renderer.isFixturePathValid', () => false); | ||
} | ||
|
||
function loadTestPlugins() { | ||
loadPlugins(); | ||
|
||
return render(<Slot name="fixtureHeader" />); | ||
} | ||
|
||
it('renders blank state message', async () => { | ||
registerTestPlugins(); | ||
const { getByText } = loadTestPlugins(); | ||
|
||
await waitForElement(() => getByText(/no fixture selected/i)); | ||
}); | ||
|
||
it('renders disabled fullscreen button', async () => { | ||
registerTestPlugins(); | ||
const { getByText } = loadTestPlugins(); | ||
|
||
expect(getByText(/fullscreen/i)).toHaveAttribute('disabled'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.