Skip to content

Commit 8395792

Browse files
committed
Cleaned up comments and code, making pull request and checklist fo what is left
1 parent 7bd7a21 commit 8395792

File tree

2 files changed

+159
-169
lines changed

2 files changed

+159
-169
lines changed
Lines changed: 136 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'jquery'
22
import { assert } from 'chai'
33
import 'steal-mocha'
4-
import { vcGatherUsage, findMacroMatches, findLogicMatches, findLiteralMatches} from './vcGatherUsage'
4+
import { vcGatherUsage, findMacroMatches, findLogicMatches, findLiteralMatches, findMatches} from './vcGatherUsage'
55

66
// Tests for these functions reflect that varname and testValue will be lowercase by the point they reach these functions
77

@@ -13,149 +13,154 @@ describe('findMacroMatches', function () {
1313

1414
//explicit = true should pass, fail, pass
1515
//explicit = false should pass all
16+
1617
assert.deepEqual(matches, ['[Client First Name TE ]'], 'Should find one match')
1718
assert.deepEqual(matches2, ['[Client First Name TE D]'], 'Should find one match')
1819
assert.deepEqual(matches3, [ '[ Client First Name TE ]' ], 'Should find one match')
1920
})
2021
})
2122

23+
describe('findLogicMatches', function () {
24+
it.only('Returns true search target is matched', function () {
25+
const matches = findLogicMatches('set client first name te to "matt"','client first name te')
26+
const matches2 = findLogicMatches("set [client last name te] to 'matt'",'client first name te')
2227

23-
// describe('findLogicMatches', function () {
24-
// it.only('Returns true search target is matched', function () {
25-
// const matches = findLogicMatches('set client first name te to "matt"','client first name te')
26-
// const matches2 = findLogicMatches("set [client last name te] to 'matt'",'client first name te')
27-
28-
// assert.deepEqual(matches, true, "should return true if match is found")
29-
// assert.deepEqual(matches2, null, "should return null if no match is found")
30-
// })
31-
// })
28+
assert.deepEqual(matches, true, "should return true if match is found")
29+
assert.deepEqual(matches2, null, "should return null if no match is found")
30+
})
31+
})
3232

3333
describe('findLiteralMatches', function () {
3434
it.only('Returns true if target matches exactly', function () {
3535
const matches = findLiteralMatches('client age', 'clientage')
3636
const matches2 = findLiteralMatches('client age', 'CLIENT AGE')
3737

38-
assert.deepEqual(matches, null, "should return null if no match found")
39-
assert.deepEqual(matches2, true, "Returns true if exact match")
38+
assert.deepEqual(matches, [], "should return null if no match found")
39+
assert.deepEqual(matches2, [ 'client age'], "Returns true if exact match")
40+
})
41+
})
42+
43+
//Find Matches currently needs regex type things to have bracket, paren, percent, logic and literal
44+
describe('findMatches', function () {
45+
it.only('Returns found if it finds a match', function() {
46+
const testButton = {name:'', label:'', value:'', repeatVar:' [CLIENT FIRST NAME TE] ', url:''}
47+
const testEntry = {key: 'repeatVar', type: 'regex', display: 'Button Counting Variable' }
48+
const testVarName = 'Client First Name TE'
49+
50+
const found = findMatches(testButton, testEntry, testVarName)
51+
52+
assert.deepEqual(found, [ '[client first name te]' ], "testing")
4053
})
4154
})
4255

43-
// saving just in case
44-
// const matches = findLiteralMatches('client age', 'client age')
45-
// const matches2 = findLiteralMatches('age', 'client age')
46-
47-
// assert.deepEqual(matches, true, "should return true if exact match")
48-
// assert.deepEqual(matches2, false, "should return false if not exact match")
49-
50-
51-
52-
// describe('vcGatherUsage', function () {
53-
// let usageTestPage
54-
// const testProps = {
55-
// page: [
56-
// { key: 'name', type: 'regex', display: 'Page Name' },
57-
// { key: 'text', type: 'regex', display: 'Question Text' },
58-
// { key: 'repeatVar', type: 'string', display: 'Counting Variable' },
59-
// { key: 'outerLoopVar', type: 'string', display: 'Outer Loop Variable' },
60-
// { key: 'learn', type: 'regex', display: 'LearnMore Prompt' },
61-
// { key: 'help', type: 'regex', display: 'LearnMore Response' },
62-
// { key: 'helpReader', type: 'regex', display: 'Video Transcript' },
63-
// { key: 'codeBefore', type: 'logic', display: 'Before Logic' },
64-
// { key: 'codeAfter', type: 'logic', display: 'After Logic' }
65-
// ],
66-
// fields: [
67-
// { key: 'label', type: 'regex', display: 'Field Label' },
68-
// { key: 'name', type: 'string', display: 'Field Variable' },
69-
// { key: 'value', type: 'regex', display: 'Field Default Value' },
70-
// { key: 'invalidPrompt', type: 'regex', display: 'Field Custom Invalid Prompt' },
71-
// { key: 'sample', type: 'regex', display: 'Field Sample Value' }
72-
// ],
73-
// buttons: [
74-
// { key: 'label', type: 'regex', display: 'Button Label' },
75-
// { key: 'name', type: 'string', display: 'Button Variable Name' },
76-
// { key: 'value', type: 'regex', display: 'Button Default Value' },
77-
// { key: 'repeatVar', type: 'string', display: 'Button Counting Variable' },
78-
// { key: 'url', type: 'regex', display: 'Button URL' }
79-
// ]
80-
// }
81-
82-
// beforeEach(() => {
83-
// usageTestPage = new window.TPage()
84-
// usageTestPage.fields = [new window.TField()]
85-
// usageTestPage.buttons = [new window.TButton()]
86-
87-
// const gGuide = new window.TGuide()
88-
// window.gGuide = gGuide
89-
// window.gGuide.pages = { usageTestPage }
90-
// })
91-
92-
// afterEach(() => {
93-
// window.gGuide = null
94-
// })
95-
96-
// it('gathers usage on Page, Field, and Button level property values using variables', function () {
97-
// const setTestProps = (targetMap, propsToSet) => {
98-
// for (const entry of propsToSet) {
99-
// const prop = entry.key
100-
// if (entry.type === 'regex') {
101-
// targetMap[prop] = 'macro style %%[Number NU]%%'
102-
// } else if (entry.type === 'logic') {
103-
// targetMap[prop] = 'SET [Number NU] TO 1'
104-
// } else { // direct var set
105-
// targetMap[prop] = 'Number NU'
106-
// }
107-
// }
108-
// }
109-
// setTestProps(usageTestPage, testProps.page)
110-
// setTestProps(usageTestPage.fields[0], testProps.fields)
111-
// setTestProps(usageTestPage.buttons[0], testProps.buttons)
112-
113-
// const foundMessage = vcGatherUsage('Number NU')
114-
// // if found, `display value` will be in foundMessage for each entry
115-
// for (const entry of testProps.page) {
116-
// const usedInPage = foundMessage.indexOf(entry.display) !== -1
117-
// assert.isTrue(usedInPage, `should find Number NU usage in page.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
118-
// }
119-
// for (const entry of testProps.fields) {
120-
// const usedInField = foundMessage.indexOf(entry.display) !== -1
121-
// assert.isTrue(usedInField, `should find Number NU usage in field.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
122-
// }
123-
// for (const entry of testProps.buttons) {
124-
// const usedInButton = foundMessage.indexOf(entry.display) !== -1
125-
// assert.isTrue(usedInButton, `should find Number NU usage in button.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
126-
// }
127-
// })
128-
129-
// it('gathers explicit usage on Page, Field, and Button level property values using variables', function () {
130-
// const setTestProps = (targetMap, propsToSet) => {
131-
// for (const entry of propsToSet) {
132-
// const prop = entry.key
133-
// if (entry.type === 'regex') {
134-
// targetMap[prop] = 'macro style %%[Number NU]%%'
135-
// } else if (entry.type === 'logic') {
136-
// targetMap[prop] = 'SET [Number123 NU] TO 1'
137-
// } else { // direct var set
138-
// targetMap[prop] = 'Number foo NU'
139-
// }
140-
// }
141-
// }
142-
// setTestProps(usageTestPage, testProps.page)
143-
// setTestProps(usageTestPage.fields[0], testProps.fields)
144-
// setTestProps(usageTestPage.buttons[0], testProps.buttons)
145-
146-
// const foundMessage = vcGatherUsage('Number NU')
147-
// // if found, `display value` will be in foundMessage for each entry
148-
// for (const entry of testProps.page) {
149-
// const usedInPage = foundMessage.indexOf(entry.display) !== -1
150-
// assert.isTrue(usedInPage, `should find Number NU usage in page.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
151-
// }
152-
// for (const entry of testProps.fields) {
153-
// const usedInField = foundMessage.indexOf(entry.display) !== -1
154-
// assert.isTrue(usedInField, `should find Number NU usage in field.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
155-
// }
156-
// for (const entry of testProps.buttons) {
157-
// const usedInButton = foundMessage.indexOf(entry.display) !== -1
158-
// assert.isTrue(usedInButton, `should find Number NU usage in button.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
159-
// }
160-
// })
161-
// })
56+
describe('vcGatherUsage', function () {
57+
let usageTestPage
58+
const testProps = {
59+
page: [
60+
{ key: 'name', type: 'regex', display: 'Page Name' },
61+
{ key: 'text', type: 'regex', display: 'Question Text' },
62+
{ key: 'repeatVar', type: 'string', display: 'Counting Variable' },
63+
{ key: 'outerLoopVar', type: 'string', display: 'Outer Loop Variable' },
64+
{ key: 'learn', type: 'regex', display: 'LearnMore Prompt' },
65+
{ key: 'help', type: 'regex', display: 'LearnMore Response' },
66+
{ key: 'helpReader', type: 'regex', display: 'Video Transcript' },
67+
{ key: 'codeBefore', type: 'logic', display: 'Before Logic' },
68+
{ key: 'codeAfter', type: 'logic', display: 'After Logic' }
69+
],
70+
fields: [
71+
{ key: 'label', type: 'regex', display: 'Field Label' },
72+
{ key: 'name', type: 'string', display: 'Field Variable' },
73+
{ key: 'value', type: 'regex', display: 'Field Default Value' },
74+
{ key: 'invalidPrompt', type: 'regex', display: 'Field Custom Invalid Prompt' },
75+
{ key: 'sample', type: 'regex', display: 'Field Sample Value' }
76+
],
77+
buttons: [
78+
{ key: 'label', type: 'regex', display: 'Button Label' },
79+
{ key: 'name', type: 'string', display: 'Button Variable Name' },
80+
{ key: 'value', type: 'regex', display: 'Button Default Value' },
81+
{ key: 'repeatVar', type: 'string', display: 'Button Counting Variable' },
82+
{ key: 'url', type: 'regex', display: 'Button URL' }
83+
]
84+
}
85+
86+
beforeEach(() => {
87+
usageTestPage = new window.TPage()
88+
usageTestPage.fields = [new window.TField()]
89+
usageTestPage.buttons = [new window.TButton()]
90+
91+
const gGuide = new window.TGuide()
92+
window.gGuide = gGuide
93+
window.gGuide.pages = { usageTestPage }
94+
})
95+
96+
afterEach(() => {
97+
window.gGuide = null
98+
})
99+
100+
it('gathers usage on Page, Field, and Button level property values using variables', function () {
101+
const setTestProps = (targetMap, propsToSet) => {
102+
for (const entry of propsToSet) {
103+
const prop = entry.key
104+
if (entry.type === 'regex') {
105+
targetMap[prop] = 'macro style %%[Number NU]%%'
106+
} else if (entry.type === 'logic') {
107+
targetMap[prop] = 'SET [Number NU] TO 1'
108+
} else { // direct var set
109+
targetMap[prop] = 'Number NU'
110+
}
111+
}
112+
}
113+
setTestProps(usageTestPage, testProps.page)
114+
setTestProps(usageTestPage.fields[0], testProps.fields)
115+
setTestProps(usageTestPage.buttons[0], testProps.buttons)
116+
117+
const foundMessage = vcGatherUsage('Number NU')
118+
// if found, `display value` will be in foundMessage for each entry
119+
for (const entry of testProps.page) {
120+
const usedInPage = foundMessage.indexOf(entry.display) !== -1
121+
assert.isTrue(usedInPage, `should find Number NU usage in page.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
122+
}
123+
for (const entry of testProps.fields) {
124+
const usedInField = foundMessage.indexOf(entry.display) !== -1
125+
assert.isTrue(usedInField, `should find Number NU usage in field.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
126+
}
127+
for (const entry of testProps.buttons) {
128+
const usedInButton = foundMessage.indexOf(entry.display) !== -1
129+
assert.isTrue(usedInButton, `should find Number NU usage in button.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
130+
}
131+
})
132+
133+
it('gathers explicit usage on Page, Field, and Button level property values using variables', function () {
134+
const setTestProps = (targetMap, propsToSet) => {
135+
for (const entry of propsToSet) {
136+
const prop = entry.key
137+
if (entry.type === 'regex') {
138+
targetMap[prop] = 'macro style %%[Number NU]%%'
139+
} else if (entry.type === 'logic') {
140+
targetMap[prop] = 'SET [Number123 NU] TO 1'
141+
} else { // direct var set
142+
targetMap[prop] = 'Number foo NU'
143+
}
144+
}
145+
}
146+
147+
setTestProps(usageTestPage, testProps.page)
148+
setTestProps(usageTestPage.fields[0], testProps.fields)
149+
setTestProps(usageTestPage.buttons[0], testProps.buttons)
150+
151+
const foundMessage = vcGatherUsage('Number NU')
152+
// if found, `display value` will be in foundMessage for each entry
153+
for (const entry of testProps.page) {
154+
const usedInPage = foundMessage.indexOf(entry.display) !== -1
155+
assert.isTrue(usedInPage, `should find Number NU usage in page.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
156+
}
157+
for (const entry of testProps.fields) {
158+
const usedInField = foundMessage.indexOf(entry.display) !== -1
159+
assert.isTrue(usedInField, `should find Number NU usage in field.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
160+
}
161+
for (const entry of testProps.buttons) {
162+
const usedInButton = foundMessage.indexOf(entry.display) !== -1
163+
assert.isTrue(usedInButton, `should find Number NU usage in button.${entry.key} by displaying ${entry.display} in returned foundMessage html`)
164+
}
165+
})
166+
})

0 commit comments

Comments
 (0)