Skip to content

Commit

Permalink
Fix test timing to wait for view to be rendered before running expect…
Browse files Browse the repository at this point in the history
…ations (#467)
  • Loading branch information
jonsnyder authored Feb 21, 2025
1 parent 32c433c commit bc2f3ae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/view/components/errorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default class ErrorBoundary extends Component {
return { error };
}

componentDidUpdate(_, { error: prevError }) {
const { error } = this.state;
if (error && prevError !== error) {
window.dispatchEvent(new Event("extension-reactor-alloy:rendered"));
}
}

render() {
const { error } = this.state;
const { children } = this.props;
Expand Down
22 changes: 22 additions & 0 deletions test/functional/helpers/endpointMocks/dataElementMocks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import responseHeaders from "./responseHeaders.mjs";

const DATA_ELEMENT_1_REGEX = /data_elements\/DE1/;
const DATA_ELEMENT_2_REGEX = /data_elements\/DE2/;
const DATA_ELEMENT_3_REGEX = /data_elements\/DE3/;
const DATA_SOLUTIONS_ELEMENT_1_REGEX = /data_elements\/SDE1/;

const testDataVariable1 = {
Expand Down Expand Up @@ -49,6 +50,23 @@ const testDataVariable2 = {
}),
},
};

const testDataVariable3 = {
id: "DE3",
attributes: {
name: "Test data variable 3",
delegate_descriptor_id: "adobe-alloy::dataElements::variable",
settings: JSON.stringify({
sandbox: {
name: "prod",
},
schema: {
id: "sch123",
version: "1.0",
},
}),
},
};
const testSolutionsVariable1 = {
id: "SDE1",
attributes: {
Expand All @@ -68,6 +86,10 @@ export const element2 = RequestMock()
.onRequestTo({ url: DATA_ELEMENT_2_REGEX, method: "GET" })
.respond({ data: testDataVariable2 }, 200, responseHeaders);

export const element3 = RequestMock()
.onRequestTo({ url: DATA_ELEMENT_3_REGEX, method: "GET" })
.respond({ data: testDataVariable3 }, 200, responseHeaders);

export const solutionsElement1 = RequestMock()
.onRequestTo({ url: DATA_SOLUTIONS_ELEMENT_1_REGEX, method: "GET" })
.respond({ data: testSolutionsVariable1 }, 200, responseHeaders);
2 changes: 2 additions & 0 deletions test/functional/helpers/extensionViewController.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export default {
initInfo,
sharedViewMethodMocks,
});
// This promise will resolve when the extension view is rendered.
return window.initializeExtensionViewPromise;
},
{
dependencies: {
Expand Down
10 changes: 5 additions & 5 deletions test/functional/specs/view/actions/updateVariable.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ test.requestHooks(dataElementMocks.element1, dataElementsMocks.multiple)(
},
);

test.requestHooks(dataElementMocks.element1, dataElementsMocks.multiple)(
test.requestHooks(dataElementMocks.element3, dataElementsMocks.multiple, schemaMocks.basic)(
"doesn't show warning when the schema version is the same",
async () => {
async (t) => {
await extensionViewController.init({
propertySettings: {
id: "PRabcd",
},
settings: {
dataElementId: "DE1",
dataElementId: "DE3",
schema: {
id: "https://ns.adobe.com/unifiedjsqeonly/schemas/8f9fc4c28403e4428bbe7b97436322c44a71680349dfd489",
version: "1.2",
id: "sch123",
version: "1.0",
},
data: {},
},
Expand Down

0 comments on commit bc2f3ae

Please sign in to comment.