PromucFlow_constructor/app/client/src/utils/WidgetQueryGeneratorRegistry.test.ts
Vemparala Surya Vamsi 6410892f2e
chore: [one click binding] Create a registry to maintain the list of the widget query generators (#21764)
## Description

Basic code to build datasource registry for one click binding.
Fixes #21506 

## Type of change

- New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

- Jest


### Test Plan
> Add Testsmith test cases links that relate to this PR

### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)


## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-03-28 20:03:29 +05:30

33 lines
1.1 KiB
TypeScript

import WidgetQueryGeneratorRegistry from "./WidgetQueryGeneratorRegistry";
describe("WidgetQueryGeneratorRegistry", () => {
const somepluginId = "somePluginId";
it("should be able to register a QueryGenerator", () => {
const someQueryGenerator = {};
WidgetQueryGeneratorRegistry.register(somepluginId, someQueryGenerator);
expect(WidgetQueryGeneratorRegistry.get(somepluginId)).toBeTruthy();
});
it("should return a falsey value when searching for an non existing generator", () => {
const nonExistingQueryGeneratopr = "someId";
expect(
WidgetQueryGeneratorRegistry.get(nonExistingQueryGeneratopr),
).toBeFalsy();
});
it("should return the same adaptor reference when querying the same pluginId", () => {
const adaptor = WidgetQueryGeneratorRegistry.get(somepluginId);
expect(adaptor).toBe(WidgetQueryGeneratorRegistry.get(somepluginId));
});
it("should not find the registered plugin after clearing the registry", () => {
WidgetQueryGeneratorRegistry.clear();
expect(WidgetQueryGeneratorRegistry.get(somepluginId)).toBeFalsy();
});
afterAll(() => {
WidgetQueryGeneratorRegistry.clear();
});
});