Add Dynamic Poll Web Part with core functionality and styling
- Initialize Gulp build process with gulpfile.js - Create package.json for project dependencies and scripts - Add TypeScript declarations for SCSS modules - Implement DynamicPollWebPart with property pane configuration - Create PollDataService for SharePoint list interactions - Develop core polling logic in PollCore.ts - Define types for polls and answers in PollTypes.ts - Create React components for DynamicPoll UI - Add localization support for English and German - Implement unit tests for core polling functionality - Set up TypeScript and TSLint configurations
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { calculatePollResults, findUserAnswer, selectActivePoll } from '../src/webparts/dynamicPoll/PollCore';
|
||||
import { IPoll, IPollAnswer } from '../src/webparts/dynamicPoll/PollTypes';
|
||||
|
||||
let passed: number = 0;
|
||||
function assert(name: string, condition: boolean): void {
|
||||
if (!condition) { throw new Error('FAILED: ' + name); }
|
||||
passed++; console.log('OK:', name);
|
||||
}
|
||||
function poll(value: any): IPoll { return value as IPoll; } // tslint:disable-line:no-any
|
||||
|
||||
const now: Date = new Date('2026-08-23T12:00:00Z');
|
||||
const selected: IPoll = selectActivePoll([
|
||||
poll({ id: 1, question: 'old', options: ['A'], isActive: true,
|
||||
startDate: new Date('2026-08-20T00:00:00Z'), endDate: new Date('2026-08-22T00:00:00Z') }),
|
||||
poll({ id: 2, question: 'current', options: ['A', 'B'], isActive: true,
|
||||
startDate: new Date('2026-08-23T00:00:00Z'), endDate: new Date('2026-08-24T00:00:00Z') }),
|
||||
poll({ id: 3, question: 'future', options: ['A'], isActive: true,
|
||||
startDate: new Date('2026-08-24T00:00:00Z') })
|
||||
], now);
|
||||
assert('current poll is selected by activation window', !!selected && selected.id === 2);
|
||||
|
||||
const answers: IPollAnswer[] = [
|
||||
{ id: 1, userKey: 'one@contoso.local', answer: 'A' },
|
||||
{ id: 2, userKey: 'two@contoso.local', answer: 'B' },
|
||||
{ id: 3, userKey: 'three@contoso.local', answer: 'A' },
|
||||
{ id: 4, userKey: 'legacy@contoso.local', answer: 'Removed option' }
|
||||
];
|
||||
const results = calculatePollResults(['A', 'B'], answers);
|
||||
assert('votes are counted per configured option', results[0].votes === 2 && results[1].votes === 1);
|
||||
assert('invalid legacy answer is excluded from percentage', results[0].percentage === 67 && results[1].percentage === 33);
|
||||
assert('user lookup is case insensitive', findUserAnswer(answers, 'ONE@CONTOSO.LOCAL') === 'A');
|
||||
assert('unknown user has no answer', findUserAnswer(answers, 'unknown@contoso.local') === '');
|
||||
console.log('DynamicPoll core tests passed:', passed);
|
||||
|
||||
Reference in New Issue
Block a user