-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into updatelgformatURL
- Loading branch information
Showing
9 changed files
with
375 additions
and
12 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
Composer/packages/client/__tests__/pages/notifications/useNotifications.test.ts
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,118 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { hooks } from '@bfc/test-utils'; | ||
|
||
import { useStoreContext } from '../../../src/hooks/useStoreContext'; | ||
import useNotifications from '../../../src/pages/notifications/useNotifications'; | ||
|
||
const { renderHook } = hooks; | ||
|
||
jest.mock('../../../src/hooks/useStoreContext', () => ({ | ||
useStoreContext: jest.fn(), | ||
})); | ||
|
||
const state = { | ||
projectId: 'test', | ||
dialogs: [ | ||
{ | ||
id: 'test', | ||
content: 'test', | ||
luFile: 'test', | ||
referredLuIntents: [], | ||
diagnostics: [ | ||
{ | ||
message: 'must be an expression', | ||
path: 'test.triggers[0]#Microsoft.OnUnknownIntent#condition', | ||
severity: 1, | ||
source: 'test', | ||
}, | ||
], | ||
}, | ||
], | ||
luFiles: [ | ||
{ | ||
content: 'test', | ||
id: 'test.en-us', | ||
intents: [ | ||
{ | ||
Body: '- test12345 ss', | ||
Entities: [], | ||
Name: 'test', | ||
range: { | ||
endLineNumber: 7, | ||
startLineNumber: 4, | ||
}, | ||
}, | ||
], | ||
diagnostics: [ | ||
{ | ||
message: 'lu syntax error', | ||
severity: 0, | ||
source: 'test.en-us', | ||
range: { | ||
end: { character: 2, line: 7 }, | ||
start: { character: 0, line: 7 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
lgFiles: [ | ||
{ | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [ | ||
{ | ||
body: '- ${add(1,2)}', | ||
name: 'bar', | ||
range: { endLineNumber: 0, startLineNumber: 0 }, | ||
}, | ||
], | ||
diagnostics: [ | ||
{ | ||
message: 'lg syntax error', | ||
severity: 1, | ||
source: 'test.en-us', | ||
range: { | ||
end: { character: 2, line: 13 }, | ||
start: { character: 0, line: 13 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
diagnostics: [ | ||
{ | ||
message: 'server error', | ||
severity: 0, | ||
source: 'server', | ||
}, | ||
], | ||
}; | ||
|
||
const resolvers = { luFileResolver: jest.fn((id) => state.luFiles.find((file) => file.id === id)) }; | ||
|
||
const actions = { | ||
updateLuFile: jest.fn(), | ||
}; | ||
|
||
(useStoreContext as jest.Mock).mockReturnValue({ | ||
state, | ||
resolvers, | ||
actions, | ||
}); | ||
|
||
describe('useNotification hooks', () => { | ||
it('should return notifications', () => { | ||
const { result } = renderHook(() => useNotifications()); | ||
|
||
expect(result.current.length).toBe(4); | ||
}); | ||
|
||
it('should return filtered notifications', () => { | ||
const { result } = renderHook(() => useNotifications('Error')); | ||
|
||
expect(result.current.length).toBe(2); | ||
}); | ||
}); |
139 changes: 139 additions & 0 deletions
139
Composer/packages/client/__tests__/shell/lgApi.test.tsx
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,139 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { hooks } from '@bfc/test-utils'; | ||
|
||
import { useLgApi } from '../../src/shell/lgApi'; | ||
import { useStoreContext } from '../../src/hooks/useStoreContext'; | ||
|
||
jest.mock('../../src/hooks/useStoreContext', () => ({ | ||
useStoreContext: jest.fn(), | ||
})); | ||
|
||
const { renderHook } = hooks; | ||
|
||
const state = { | ||
lgFiles: [ | ||
{ | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [ | ||
{ | ||
body: '- ${add(1,2)}', | ||
name: 'bar', | ||
}, | ||
], | ||
}, | ||
], | ||
focusPath: '', | ||
locale: 'en-us', | ||
projectId: 'test', | ||
}; | ||
|
||
const resolvers = { lgFileResolver: jest.fn((id) => state.lgFiles.find((file) => file.id === id)) }; | ||
|
||
const actions = { | ||
updateLgTemplate: jest.fn(), | ||
copyLgTemplate: jest.fn(), | ||
removeLgTemplate: jest.fn(), | ||
removeLgTemplates: jest.fn(), | ||
}; | ||
|
||
(useStoreContext as jest.Mock).mockReturnValue({ | ||
state, | ||
resolvers, | ||
actions, | ||
}); | ||
|
||
describe('use lgApi hooks', () => { | ||
it('should get lg template by id', () => { | ||
const { result } = renderHook(() => useLgApi()); | ||
|
||
const templates = result.current.getLgTemplates('test.en-us'); | ||
expect(templates[0].name).toBe('bar'); | ||
|
||
function testWrongId() { | ||
result.current.getLgTemplates('wrong.en-us'); | ||
} | ||
expect(testWrongId).toThrow(); | ||
}); | ||
|
||
it('should call update lg template action', () => { | ||
const { result } = renderHook(() => useLgApi()); | ||
|
||
result.current.updateLgTemplate('test.en-us', 'bar', 'update'); | ||
|
||
expect(actions.updateLgTemplate).toBeCalledTimes(1); | ||
const arg = { | ||
file: { | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [{ body: '- ${add(1,2)}', name: 'bar' }], | ||
}, | ||
projectId: 'test', | ||
template: { | ||
body: 'update', | ||
name: 'bar', | ||
parameters: [], | ||
}, | ||
templateName: 'bar', | ||
}; | ||
expect(actions.updateLgTemplate).toBeCalledWith(arg); | ||
}); | ||
|
||
it('should call copy lg template action', () => { | ||
const { result } = renderHook(() => useLgApi()); | ||
|
||
result.current.copyLgTemplate('test.en-us', 'from', 'to'); | ||
|
||
expect(actions.copyLgTemplate).toBeCalledTimes(1); | ||
const arg = { | ||
file: { | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [{ body: '- ${add(1,2)}', name: 'bar' }], | ||
}, | ||
fromTemplateName: 'from', | ||
projectId: 'test', | ||
toTemplateName: 'to', | ||
}; | ||
expect(actions.copyLgTemplate).toBeCalledWith(arg); | ||
}); | ||
|
||
it('should call remove lg template action', () => { | ||
const { result } = renderHook(() => useLgApi()); | ||
|
||
result.current.removeLgTemplate('test.en-us', 'bar'); | ||
|
||
expect(actions.removeLgTemplate).toBeCalledTimes(1); | ||
|
||
const arg = { | ||
file: { | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [{ body: '- ${add(1,2)}', name: 'bar' }], | ||
}, | ||
projectId: 'test', | ||
templateName: 'bar', | ||
}; | ||
expect(actions.removeLgTemplate).toBeCalledWith(arg); | ||
}); | ||
|
||
it('should call remove lg templates action', () => { | ||
const { result } = renderHook(() => useLgApi()); | ||
|
||
result.current.removeLgTemplates('test.en-us', ['bar']); | ||
|
||
expect(actions.removeLgTemplates).toBeCalledTimes(1); | ||
const arg = { | ||
file: { | ||
content: 'test', | ||
id: 'test.en-us', | ||
templates: [{ body: '- ${add(1,2)}', name: 'bar' }], | ||
}, | ||
projectId: 'test', | ||
templateNames: ['bar'], | ||
}; | ||
expect(actions.removeLgTemplates).toBeCalledWith(arg); | ||
}); | ||
}); |
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,90 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { hooks } from '@bfc/test-utils'; | ||
|
||
import { useLuApi } from '../../src/shell/luApi'; | ||
import { useStoreContext } from '../../src/hooks/useStoreContext'; | ||
|
||
const { renderHook } = hooks; | ||
|
||
jest.mock('../../src/hooks/useStoreContext', () => ({ | ||
useStoreContext: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../src/store/parsers/luWorker', () => { | ||
return { addIntent: (a, b) => b.Body, updateIntent: (a, b, c) => c.Body, removeIntent: (a, b) => b }; | ||
}); | ||
|
||
const state = { | ||
luFiles: [ | ||
{ | ||
content: 'test', | ||
id: 'test.en-us', | ||
intents: [{ Body: '- test12345', Entities: [], Name: 'test' }], | ||
}, | ||
], | ||
focusPath: '', | ||
locale: 'en-us', | ||
projectId: 'test', | ||
}; | ||
|
||
const resolvers = { luFileResolver: jest.fn((id) => state.luFiles.find((file) => file.id === id)) }; | ||
|
||
const actions = { | ||
updateLuFile: jest.fn(), | ||
}; | ||
|
||
(useStoreContext as jest.Mock).mockReturnValue({ | ||
state, | ||
resolvers, | ||
actions, | ||
}); | ||
|
||
describe('use luApi hooks', () => { | ||
it('should call add lu intent action', () => { | ||
const { result } = renderHook(() => useLuApi()); | ||
|
||
result.current.addLuIntent('test.en-us', 'test', { Body: '- test add', Name: 'add' }).then(() => { | ||
expect(actions.updateLuFile).toBeCalledTimes(1); | ||
const arg = { content: '- test add', id: 'test.en-us', projectId: 'test' }; | ||
expect(actions.updateLuFile).toBeCalledWith(arg); | ||
}); | ||
}); | ||
|
||
it('should call update lu intent action', () => { | ||
const { result } = renderHook(() => useLuApi()); | ||
|
||
result.current.updateLuIntent('test.en-us', 'test', { Body: '- test update', Name: 'update' }).then(() => { | ||
expect(actions.updateLuFile).toBeCalledTimes(2); | ||
const arg = { content: '- test update', id: 'test.en-us', projectId: 'test' }; | ||
expect(actions.updateLuFile).toBeCalledWith(arg); | ||
}); | ||
}); | ||
|
||
it('should call remove lu intent action', () => { | ||
const { result } = renderHook(() => useLuApi()); | ||
|
||
result.current.removeLuIntent('test.en-us', 'remove').then(() => { | ||
expect(actions.updateLuFile).toBeCalledTimes(3); | ||
const arg = { content: 'remove', id: 'test.en-us', projectId: 'test' }; | ||
expect(actions.updateLuFile).toBeCalledWith(arg); | ||
}); | ||
}); | ||
|
||
it('should get lu intents', () => { | ||
const { result } = renderHook(() => useLuApi()); | ||
|
||
const intents = result.current.getLuIntents('test.en-us'); | ||
|
||
expect(intents[0].Name).toBe('test'); | ||
}); | ||
|
||
it('should get lu intent', () => { | ||
const { result } = renderHook(() => useLuApi()); | ||
|
||
const intent = result.current.getLuIntent('test.en-us', 'test'); | ||
|
||
expect(intent?.Name).toBe('test'); | ||
}); | ||
}); |
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,12 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { useContext } from 'react'; | ||
|
||
import { StoreContext } from '../store'; | ||
|
||
export function useStoreContext() { | ||
const { state, actions, resolvers } = useContext(StoreContext); | ||
|
||
return { state, actions, resolvers }; | ||
} |
6 changes: 3 additions & 3 deletions
6
Composer/packages/client/src/pages/notifications/useNotifications.tsx
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.