Skip to content

Commit

Permalink
Merge pull request #4509 from easyops-cn/steve/v3-track-after-initial
Browse files Browse the repository at this point in the history
fix(): handle context change just after property being initialized
  • Loading branch information
willc001 authored Oct 11, 2024
2 parents 4b32254 + d1b99ff commit eceb450
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 70 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ jobs:
- run: yarn install --frozen-lockfile
env:
CYPRESS_INSTALL_BINARY: ''
CYPRESS_DOWNLOAD_MIRROR: ''

- name: Get checksum after yarn install
id: yarn-lock-check-after
Expand Down
29 changes: 29 additions & 0 deletions cypress/e2e/control-nodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,34 @@ for (const port of Cypress.env("ports")) {
"Add",
]);
});

it("should handle initial rerender", () => {
cy.visit(
`${origin}/e2e/initial-rerender/apps/a?systemId=1&serviceSetId=Set-X`,
{
onBeforeLoad(win) {
cy.spy(win.console, "error").as("console.error");
},
}
);

cy.expectMainContents(["Go 1Go 2Go undefined", "Set-X, Set-Y"]);

cy.contains("Go undefined").click();
cy.expectMainContents(["Go 1Go 2Go undefined", "No System ID"]);

cy.contains("Go 2").click();
cy.contains("Passed");
cy.expectMainContents(["Go 1Go 2Go undefined", "No Service SetPassed"]);

cy.contains("Go undefined").click();
cy.expectMainContents(["Go 1Go 2Go undefined", "No System ID"]);

cy.contains("Go 2").click();
cy.contains("Passed");
cy.expectMainContents(["Go 1Go 2Go undefined", "No Service SetPassed"]);

cy.get("@console.error").should("not.be.called");
});
});
}
146 changes: 146 additions & 0 deletions mock-micro-apps/e2e/storyboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,149 @@ routes:
- path: '${APP.homepage}/async-wrap-brick'
bricks:
- brick: e2e.async-wrap

- path: '${APP.homepage}/initial-rerender/:tab/:group?'
incrementalSubRoutes: true
context:
- name: systemId
value: <% QUERY.systemId %>
onChange:
if: <% CTX.hasSystemId !== !!EVENT.detail %>
action: context.replace
args:
- hasSystemId
- <% !!EVENT.detail %>
- name: hasSystemId
value: <% !!CTX.systemId %>
- name: serviceSetList
value: null
track: true
resolve:
if: <% CTX.systemId %>
useProvider: e2e.return-by-timeout
args:
- 100
- |
<%
CTX.systemId === '1'
? ['Set-X', 'Set-Y']
: []
%>
onChange:
- action: context.replace
args:
- selectedServiceSetId
- <% CTX.serviceSetList?.[0] %>
- name: debugData
resolve:
useProvider: e2e.return-by-timeout
args:
- 100
- |
<% !!CTX.serviceSetList && !CTX.serviceSetList.length %>
track: true
- name: selectedServiceSetId
value: <% CTX.serviceSetList?.[0] %>
onChange:
- action: history.pushQuery
args:
- serviceSetId: <% EVENT.detail %>
- notify: false
- name: serviceSet
value: null
track: true
resolve:
if: <% CTX.selectedServiceSetId %>
useProvider: e2e.return-by-timeout
args:
- 100
- |
<% `${Math.random()}/${CTX.selectedServiceSetId}` %>
bricks:
# - brick: h1
# properties:
# textContent: '<% `${Math.random()}` %>'
# - brick: p
# properties:
# textContent: '<%= `System ID: ${CTX.systemId}` %>'
# - brick: p
# properties:
# textContent: '<%= `Has System ID: ${CTX.hasSystemId}` %>'
# - brick: p
# properties:
# textContent: '<%= `Service Set List: ${JSON.stringify(CTX.serviceSetList)}` %>'
- brick: div
children:
- brick: :forEach
dataSource:
- '1'
- '2'
- <% undefined %>
children:
- brick: button
properties:
textContent: <% `Go ${ITEM}` %>
events:
click:
- action: context.replace
args:
- systemId
- <% ITEM %>
- action: history.pushQuery
args:
- systemId: <% ITEM %>
- brick: div
iid: p0
if: <%= CTX.hasSystemId %>
children:
- brick: div
iid: p00
if: <%= CTX.serviceSetList && !CTX.serviceSetList.length %>
children:
- brick: p
iid: p000
properties:
textContent: No Service Set
- brick: p
iid: p001
properties:
textContent: '<%= CTX.debugData ? "Passed" : "Failed" %>'
- brick: div
iid: p01
properties:
title: <%= CTX.serviceSet %>
children:
- brick: div
iid: p010
if: <%= !!CTX.serviceSetList?.length %>
slots:
'':
type: routes
routes:
- path: '${APP.homepage}/initial-rerender/apps/:group?'
exact: true
bricks:
- brick: p
iid: p0100
properties:
textContent: <%= CTX.serviceSetList?.join(", ") %>
- path: '${APP.homepage}/initial-rerender/arch'
exact: true
bricks:
- brick: hr
- brick: div
iid: p1
if: <%= !CTX.hasSystemId %>
children:
- brick: p
iid: p10
properties:
textContent: No System ID
# - brick: div
# slots:
# '':
# type: routes
# routes:
# - path: '${APP.homepage}/initial-rerender/apps/:group?'
# exact: true
# bricks: []
8 changes: 1 addition & 7 deletions packages/runtime/src/internal/Renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3281,13 +3281,6 @@ describe("renderBrick for tpl", () => {
const ctxStore = new DataStore("CTX");
const runtimeContext = {
ctxStore,
location: {
pathname: "/home/HOST",
},
app: {
homepage: "/home",
noAuthGuard: true,
},
pendingPermissionsPreCheck: [] as undefined[],
} as RuntimeContext;
const rendererContext = new RendererContext("page");
Expand All @@ -3307,6 +3300,7 @@ describe("renderBrick for tpl", () => {
type: "unknown.tpl-x",
},
});
expect(loadBricksImperatively).toBeCalledWith(["unknown.tpl-x"], []);
});
});

Expand Down
Loading

0 comments on commit eceb450

Please sign in to comment.