-
Notifications
You must be signed in to change notification settings - Fork 2
Rename CioPlpContext to CioPlp #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React from 'react'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes here just moved the file into CioPlp |
||
| import ReactDOMServer from 'react-dom/server'; | ||
| import CioPlp from '../../src/components/CioPlp'; | ||
| import { useCioPlpContext } from '../../src/hooks/useCioPlpContext'; | ||
| import { DEMO_API_KEY } from '../../src/constants'; | ||
|
|
||
| describe('CioPlp React Server-Side Rendering', () => { | ||
| it("throws an error if apiKey isn't provided", () => { | ||
| expect(() => { | ||
| ReactDOMServer.renderToString(<CioPlp />); | ||
| }).toThrow(); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider without children on the server without error', () => { | ||
| // Render the component to a string | ||
| const html = ReactDOMServer.renderToString(<CioPlp apiKey={DEMO_API_KEY} />); | ||
|
|
||
| expect(html).toContain(''); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with children correctly on the server', () => { | ||
| // Render the component to a string | ||
| const html = ReactDOMServer.renderToString( | ||
| <CioPlp apiKey={DEMO_API_KEY}> | ||
| <div>Test</div> | ||
| </CioPlp>, | ||
| ); | ||
| expect(html).toContain('<div>Test</div>'); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with render props on the server', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only new test case for renderProps pattern |
||
| // Render the component to a string | ||
| const html = ReactDOMServer.renderToString( | ||
| <CioPlp apiKey={DEMO_API_KEY}>{() => <div>Test</div>}</CioPlp>, | ||
| ); | ||
| expect(html).toContain('<div>Test</div>'); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with children that has access to Context value on the server', () => { | ||
| function ContextConsumer() { | ||
| const context = useCioPlpContext(); | ||
|
|
||
| return <div>{JSON.stringify(context)}</div>; | ||
| } | ||
|
|
||
| // Render the component to a string | ||
| const html = ReactDOMServer.renderToString( | ||
| <CioPlp apiKey={DEMO_API_KEY}> | ||
| <ContextConsumer /> | ||
| </CioPlp>, | ||
| ); | ||
| expect(html).toContain( | ||
| '<div>{"cioClient":null,"cioClientOptions":{},"getters":{},"formatters":{},"callbacks":{}}</div>', | ||
| ); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React from 'react'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for client side |
||
| import { render } from '@testing-library/react'; | ||
| import CioPlp from '../../src/components/CioPlp'; | ||
| import { useCioPlpContext } from '../../src/hooks/useCioPlpContext'; | ||
| import { DEMO_API_KEY } from '../../src/constants'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| describe('CioPlp React Client-Side Rendering', () => { | ||
| beforeEach(() => { | ||
| const spy = jest.spyOn(console, 'error'); | ||
| spy.mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it("throws an error if apiKey isn't provided", () => { | ||
| expect(() => { | ||
| render(<CioPlp />); | ||
| }).toThrow(); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider without children on the client without error', () => { | ||
| expect(() => render(<CioPlp apiKey={DEMO_API_KEY} />)).not.toThrow(); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with children correctly on the client', () => { | ||
| // Render the component to a string | ||
| const { getByText } = render( | ||
| <CioPlp apiKey={DEMO_API_KEY}> | ||
| <div>Test</div> | ||
| </CioPlp>, | ||
| ); | ||
| expect(getByText('Test')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with render props on the client', () => { | ||
| const { getByText } = render(<CioPlp apiKey={DEMO_API_KEY}>{() => <div>Test</div>}</CioPlp>); | ||
|
|
||
| expect(getByText('Test')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders CioPlp provider with children that has access to Context value on the client', () => { | ||
| function ContextConsumer() { | ||
| const context = useCioPlpContext(); | ||
|
|
||
| return <div className='context-consumer'>{context.cioClient.options.serviceUrl}</div>; | ||
| } | ||
|
|
||
| // Render the component to a string | ||
| const { getByText } = render( | ||
| <CioPlp apiKey={DEMO_API_KEY}> | ||
| <ContextConsumer /> | ||
| </CioPlp>, | ||
| ); | ||
| expect(getByText('https://ac.cnstrc.com')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was breaking the hooks examples