Skip to content

Commit cf841ab

Browse files
committed
test(page): includeViewParams
Test added. Issue: TOBAGO-2462
1 parent e575afb commit cf841ab

File tree

4 files changed

+152
-1
lines changed

4 files changed

+152
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.myfaces.tobago.example.demo.test.page;
21+
22+
import jakarta.enterprise.context.RequestScoped;
23+
import jakarta.inject.Named;
24+
25+
import java.io.Serializable;
26+
import java.time.Instant;
27+
28+
@Named
29+
@RequestScoped
30+
public class ViewParamController implements Serializable {
31+
32+
private String parameter;
33+
34+
public String getParameter() {
35+
return parameter;
36+
}
37+
38+
public void setParameter(String parameter) {
39+
this.parameter = parameter;
40+
}
41+
42+
public long getTimestamp() {
43+
return Instant.now().toEpochMilli();
44+
}
45+
46+
public String reset() {
47+
parameter = null;
48+
return "/content/900-test/page/page.xhtml?faces-redirect=true";
49+
}
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
-->
18+
19+
<ui:composition template="/main.xhtml"
20+
xmlns="http://www.w3.org/1999/xhtml"
21+
xmlns:f="jakarta.faces.core"
22+
xmlns:tc="http://myfaces.apache.org/tobago/component"
23+
xmlns:ui="jakarta.faces.facelets">
24+
<ui:define name="metadata">
25+
<f:metadata>
26+
<f:viewParam name="parameter" value="#{viewParamController.parameter}"/>
27+
</f:metadata>
28+
</ui:define>
29+
30+
<tc:section label="includeViewParams=true">
31+
<tc:in id="param" label="Parameter from URL" value="#{viewParamController.parameter}" readonly="true"/>
32+
<tc:out id="timestamp" label="Timestamp" value="#{viewParamController.timestamp}"/>
33+
34+
<tc:link id="addTobagoParamLink" label="add 'parameter=tobago' to URL" outcome="/content/900-test/page/page.xhtml">
35+
<f:param name="parameter" value="tobago"/>
36+
</tc:link>
37+
<tc:button id="reset" label="Reset" action="#{viewParamController.reset}"/>
38+
<tc:button id="submit" label="Submit"/>
39+
</tc:section>
40+
</ui:composition>

tobago-example/tobago-example-demo/src/main/webapp/main.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</f:metadata>
3434
-->
3535

36-
<tc:page id="page"
36+
<tc:page id="page" includeViewParams="true"
3737
label="#{'Tobago Demo - '.concat(navigationState.currentNode.label != null ? navigationState.currentNode.label : '')}">
3838

3939
<!--
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import {expect, Page, test} from "@playwright/test";
21+
22+
test.describe("900-test/page/page.xhtml", () => {
23+
24+
test.beforeEach(async ({page}, testInfo) => {
25+
await page.goto("/content/900-test/page/page.xhtml");
26+
});
27+
28+
test("tc:page: includeViewParams", async ({page, browserName}) => {
29+
const paramFromUrl = page.locator("input[id='page:mainForm:param::field']");
30+
const addParamLink = page.locator("a[id='page:mainForm:addTobagoParamLink']");
31+
const reset = page.locator("button[id='page:mainForm:reset']");
32+
const submit = page.locator("button[id='page:mainForm:submit']");
33+
34+
let timestampValue: number;
35+
36+
timestampValue = await getCurrentTimestamp(page);
37+
await addParamLink.click();
38+
await expect.poll(() => getCurrentTimestamp(page)).toBeGreaterThan(timestampValue);
39+
await expect(paramFromUrl).toHaveValue("tobago");
40+
41+
timestampValue = await getCurrentTimestamp(page);
42+
await submit.click();
43+
await expect.poll(() => getCurrentTimestamp(page)).toBeGreaterThan(timestampValue);
44+
await expect(paramFromUrl).toHaveValue("tobago");
45+
46+
timestampValue = await getCurrentTimestamp(page);
47+
await reset.click();
48+
await expect.poll(() => getCurrentTimestamp(page)).toBeGreaterThan(timestampValue);
49+
await expect(paramFromUrl).toHaveValue("");
50+
51+
timestampValue = await getCurrentTimestamp(page);
52+
await submit.click();
53+
await expect.poll(() => getCurrentTimestamp(page)).toBeGreaterThan(timestampValue);
54+
await expect(paramFromUrl).toHaveValue("");
55+
});
56+
57+
async function getCurrentTimestamp(page: Page): Promise<number> {
58+
const timestamp = page.locator("tobago-out[id='page:mainForm:timestamp'] .form-control-plaintext");
59+
return Number(await timestamp.textContent());
60+
}
61+
});

0 commit comments

Comments
 (0)