Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public TokenPage create(String userName) {

WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(createTokenForm().selectUserNameDropdown()));
setExpireTime(30);
createTokenForm().selectUserNameDropdown().click();
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.visibilityOfElementLocated(new By.ByClassName(
Expand Down Expand Up @@ -161,4 +162,27 @@ public class TokenForm {
private WebElement buttonCancel;

}

private void setExpireTime(int daysAfter) {
try {
WebElement datePickerInput = driver.findElement(By.cssSelector(".n-date-picker input"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use css selectors, please use a more rigorous writing, which will lead to an flaky exception in getting elements.


LocalDateTime futureDate = LocalDateTime.now().plusDays(daysAfter);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String futureDateStr = futureDate.format(formatter);

datePickerInput.clear();
datePickerInput.sendKeys(futureDateStr.substring(0, 10));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better not to use truncated strings to get dates.


Thread.sleep(100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use thread.sleep in e2e tests.

WebElement timeInput = driver.findElement(By.cssSelector(".n-time-picker input"));
timeInput.clear();
timeInput.sendKeys(futureDateStr.substring(11));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

timeInput.sendKeys(Keys.ENTER);

Thread.sleep(100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

} catch (Exception e) {
throw new RuntimeException("Failed to set expire time", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const TokenModal = defineComponent({
(userStore.getUserInfo as UserInfoRes).userType === 'GENERAL_USER'
? (userStore.getUserInfo as UserInfoRes).id
: null
variables.model.expireTime = Date.now()
variables.model.expireTime = null
variables.model.token = ''
} else {
variables.model.userId = props.row.userId
Expand Down Expand Up @@ -110,7 +110,7 @@ const TokenModal = defineComponent({
(userStore.getUserInfo as UserInfoRes).userType === 'GENERAL_USER'
? (userStore.getUserInfo as UserInfoRes).id
: null
variables.model.expireTime = Date.now()
variables.model.expireTime = null
variables.model.token = ''
} else {
variables.model.id = props.row.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useModal(
? (userStore.getUserInfo as UserInfoRes).id
: null
),
expireTime: ref(Date.now()),
expireTime: null as number | null,
token: ref(''),
generalOptions: []
},
Expand Down Expand Up @@ -101,7 +101,7 @@ export function useModal(
const getToken = () => {
const data = {
userId: (userStore.getUserInfo as UserInfoRes).id,
expireTime: format(variables.model.expireTime, 'yyyy-MM-dd HH:mm:ss')
expireTime: format(variables.model.expireTime!, 'yyyy-MM-dd HH:mm:ss')
}

useAsyncState(
Expand Down Expand Up @@ -129,7 +129,7 @@ export function useModal(
const submitTokenModal = () => {
const data = {
userId: Number(variables.model.userId),
expireTime: format(variables.model.expireTime, 'yyyy-MM-dd HH:mm:ss'),
expireTime: format(variables.model.expireTime!, 'yyyy-MM-dd HH:mm:ss'),
token: variables.model.token
}

Expand All @@ -138,7 +138,7 @@ export function useModal(
(userStore.getUserInfo as UserInfoRes).userType === 'GENERAL_USER'
? (userStore.getUserInfo as UserInfoRes).id
: null
variables.model.expireTime = Date.now()
variables.model.expireTime = null
variables.model.token = ''
ctx.emit('confirmModal', props.showModalRef)
})
Expand All @@ -148,7 +148,7 @@ export function useModal(
const data = {
id: variables.model.id,
userId: Number(variables.model.userId),
expireTime: format(variables.model.expireTime, 'yyyy-MM-dd HH:mm:ss'),
expireTime: format(variables.model.expireTime!, 'yyyy-MM-dd HH:mm:ss'),
token: variables.model.token
}

Expand Down