-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add React Hooks for customization (part 9) (#2550)
* Add multiple simple property hooks * Fix test * Fix ESLint
- Loading branch information
Showing
14 changed files
with
225 additions
and
12 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
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,24 @@ | ||
import { timeouts } from '../constants.json'; | ||
import uiConnected from '../setup/conditions/uiConnected'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('getter should return online', async () => { | ||
const { driver, pageObjects } = await setupWebDriver(); | ||
|
||
await driver.wait(uiConnected(), timeouts.directLine); | ||
|
||
const [connectivityStatus] = await pageObjects.runHook('useConnectivityStatus'); | ||
|
||
expect(connectivityStatus).toMatchInlineSnapshot(`"connected"`); | ||
}); | ||
|
||
test('setter should be falsy', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
const [_, setConnectivityStatus] = await pageObjects.runHook('useConnectivityStatus'); | ||
|
||
expect(setConnectivityStatus).toBeFalsy(); | ||
}); |
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,43 @@ | ||
import { timeouts } from '../constants.json'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('getter should return group timestamp set in props', async () => { | ||
const { pageObjects } = await setupWebDriver({ | ||
props: { | ||
groupTimestamp: 1000 | ||
} | ||
}); | ||
|
||
const [groupTimestamp] = await pageObjects.runHook('useGroupTimestamp'); | ||
|
||
expect(groupTimestamp).toMatchInlineSnapshot(`1000`); | ||
}); | ||
|
||
test('getter should return default group timestamp if not set in props', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
|
||
const [groupTimestamp] = await pageObjects.runHook('useGroupTimestamp'); | ||
|
||
expect(groupTimestamp).toMatchInlineSnapshot(`true`); | ||
}); | ||
|
||
test('getter should return false if group timestamp is disabled', async () => { | ||
const { pageObjects } = await setupWebDriver({ | ||
props: { groupTimestamp: false } | ||
}); | ||
|
||
const [groupTimestamp] = await pageObjects.runHook('useGroupTimestamp'); | ||
|
||
expect(groupTimestamp).toMatchInlineSnapshot(`false`); | ||
}); | ||
|
||
test('setter should be falsy', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
const [_, setGroupTimestamp] = await pageObjects.runHook('useGroupTimestamp'); | ||
|
||
expect(setGroupTimestamp).toBeFalsy(); | ||
}); |
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,36 @@ | ||
import { timeouts } from '../constants.json'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('getter should return timeout for sending activity', async () => { | ||
const { pageObjects } = await setupWebDriver({ | ||
props: { | ||
sendTimeout: 1000 | ||
} | ||
}); | ||
|
||
const [timeoutForSend] = await pageObjects.runHook('useTimeoutForSend'); | ||
|
||
expect(timeoutForSend).toMatchInlineSnapshot(`1000`); | ||
}); | ||
|
||
test('getter should return default timeout for sending activity if not set in props', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
|
||
const [timeoutForSend] = await pageObjects.runHook('useTimeoutForSend'); | ||
|
||
expect(timeoutForSend).toMatchInlineSnapshot(`20000`); | ||
}); | ||
|
||
test('setter should set the timeout for sending activity', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
|
||
await pageObjects.runHook('useTimeoutForSend', [], result => result[1](1000)); | ||
|
||
const [timeoutForSend] = await pageObjects.runHook('useTimeoutForSend'); | ||
|
||
expect(timeoutForSend).toMatchInlineSnapshot(`1000`); | ||
}); |
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,33 @@ | ||
import { timeouts } from '../constants.json'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('getter should return user ID set in props', async () => { | ||
const { pageObjects } = await setupWebDriver({ | ||
props: { | ||
userID: 'u-12345' | ||
} | ||
}); | ||
|
||
const [userID] = await pageObjects.runHook('useUserID'); | ||
|
||
expect(userID).toMatchInlineSnapshot(`"u-12345"`); | ||
}); | ||
|
||
test('getter should return empty string if not set in props', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
|
||
const [userID] = await pageObjects.runHook('useUserID'); | ||
|
||
expect(userID).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
test('setter should be falsy', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
const [_, setUserID] = await pageObjects.runHook('useUserID'); | ||
|
||
expect(setUserID).toBeFalsy(); | ||
}); |
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,33 @@ | ||
import { timeouts } from '../constants.json'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('getter should return username set in props', async () => { | ||
const { pageObjects } = await setupWebDriver({ | ||
props: { | ||
username: 'u-12345' | ||
} | ||
}); | ||
|
||
const [username] = await pageObjects.runHook('useUsername'); | ||
|
||
expect(username).toMatchInlineSnapshot(`"u-12345"`); | ||
}); | ||
|
||
test('getter should return undefined if not set in props', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
|
||
const [username] = await pageObjects.runHook('useUsername'); | ||
|
||
expect(username).toMatchInlineSnapshot(`"Happy Web Chat user"`); | ||
}); | ||
|
||
test('setter should be falsy', async () => { | ||
const { pageObjects } = await setupWebDriver(); | ||
const [_, setUsername] = await pageObjects.runHook('useUsername'); | ||
|
||
expect(setUsername).toBeFalsy(); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useSelector } from '../WebChatReduxContext'; | ||
|
||
export default function useConnectivityStatus() { | ||
return [useSelector(({ connectivityStatus }) => connectivityStatus)]; | ||
} |
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,7 @@ | ||
import { useContext } from 'react'; | ||
|
||
import WebChatUIContext from '../WebChatUIContext'; | ||
|
||
export default function useGroupTimestamp() { | ||
return [useContext(WebChatUIContext).groupTimestamp]; | ||
} |
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,8 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { useSelector } from '../WebChatReduxContext'; | ||
import WebChatUIContext from '../WebChatUIContext'; | ||
|
||
export default function useTimeoutForSend() { | ||
return [useSelector(({ sendTimeout }) => sendTimeout), useContext(WebChatUIContext).setSendTimeout]; | ||
} |
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,7 @@ | ||
import { useContext } from 'react'; | ||
|
||
import WebChatUIContext from '../WebChatUIContext'; | ||
|
||
export default function useUserID() { | ||
return [useContext(WebChatUIContext).userID]; | ||
} |
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,7 @@ | ||
import { useContext } from 'react'; | ||
|
||
import WebChatUIContext from '../WebChatUIContext'; | ||
|
||
export default function useUsername() { | ||
return [useContext(WebChatUIContext).username]; | ||
} |