This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #525 from common-group/fix/user-undefined-global
🐞 carregar usuário antes do carregamento da página para evitar user u…
- Loading branch information
Showing
5 changed files
with
279 additions
and
178 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import m from 'mithril' | ||
import mq from 'mithril-query' | ||
import { Wrap } from '../../src/wrap' | ||
import userVM from '../../src/vms/user-vm' | ||
import '../lib/mocks/user-details.mock' | ||
|
||
describe('Wrap', () => { | ||
describe('view', () => { | ||
|
||
beforeAll(() => { | ||
window.optimizeObserver = { | ||
addListener() { } | ||
} | ||
}) | ||
|
||
it('should display component after user is loaded', async () => { | ||
// 1. arrange | ||
const userMocked = UserDetailMockery()[0] | ||
const user_id = userMocked.id | ||
jasmine.Ajax | ||
.stubRequest(`${apiPrefix}/user_details`) | ||
.andReturn({ | ||
responseText: `[{"id":${user_id},"name":"User Name"}]`, | ||
}) | ||
|
||
const component = mq(Wrap(TestComponent, { user_id })) | ||
|
||
// this is a hack to wait inner promises to resolve | ||
await sleep(0) | ||
component.redraw() | ||
// this is a hack to wait redraw execute after promises be resolved | ||
await sleep(0) | ||
|
||
// 2. act | ||
|
||
// 3. assert | ||
component.should.contain('INNER COMPONENT CONTENT') | ||
}) | ||
|
||
it('should not display component before user is loaded', async () => { | ||
// 1. arrange | ||
const userMocked = UserDetailMockery()[0] | ||
const user_id = userMocked.id | ||
jasmine.Ajax | ||
.stubRequest(`${apiPrefix}/user_details`) | ||
.andReturn({ | ||
responseText: `[{"id":${user_id},"name":"User Name"}]`, | ||
}) | ||
|
||
const component = mq(Wrap(TestComponent, { user_id })) | ||
|
||
// 2. act | ||
|
||
// 3. assert | ||
component.should.not.contain('INNER COMPONENT CONTENT') | ||
}) | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
}) | ||
}) | ||
|
||
class TestComponent implements m.Component<{}> { | ||
view() { | ||
return ( | ||
<div id='inner-component'>INNER COMPONENT CONTENT</div> | ||
) | ||
} | ||
} |
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.