diff --git a/App.uvue b/App.uvue index 4526ab54670ef647068774c72f0534f6058b83d0..5ea58c1a3c19183ff3c1db343e69b86584259cb5 100644 --- a/App.uvue +++ b/App.uvue @@ -1,157 +1,174 @@ \ No newline at end of file diff --git a/main.uts b/main.uts index 83a1a182c18e43ec5b3d03269005c23e62474222..0ee20ce49271a0fe5ce1d7f7d712dd55c169c4c1 100644 --- a/main.uts +++ b/main.uts @@ -276,6 +276,28 @@ export function createApp() { }, 'CompForPlugin', CompForPlugin) // #endif + app.config.globalProperties.globalPropertiesStr = 'default string' + app.config.globalProperties.globalPropertiesNum = 0 + app.config.globalProperties.globalPropertiesBool = false + app.config.globalProperties.globalPropertiesObj = { + str: 'default globalProperties obj string', + num: 0, + bool: false, + } + app.config.globalProperties.globalPropertiesNull = null as string | null + app.config.globalProperties.globalPropertiesArr = [] as number[] + app.config.globalProperties.globalPropertiesSet = new Set() + app.config.globalProperties.globalPropertiesMap = new Map() + app.config.globalProperties.globalPropertiesReactiveObj = reactive({ + str: 'default reactive string', + num: 0, + bool: false, + } as UTSJSONObject) + app.config.globalProperties.globalPropertiesFn = function (): string { + console.log('this.globalPropertiesStr', this.globalPropertiesStr) + console.log('this.globalPropertiesNum', this.globalPropertiesNum) + return `globalPropertiesStr: ${this.globalPropertiesStr}, globalPropertiesNum: ${this.globalPropertiesNum}` + } return { app } diff --git a/pages.json b/pages.json index 184c30bcfaf0d14ee053bb23142fab8d49d0263a..a5eb2a69f1525e17bee4a63b77b8ec762cd79f11 100644 --- a/pages.json +++ b/pages.json @@ -12,6 +12,18 @@ "navigationBarTitleText": "app instance" } }, + { + "path": "pages/app-instance/globalData/globalData", + "style": { + "navigationBarTitleText": "globalData" + } + }, + { + "path": "pages/app-instance/globalProperties/globalProperties", + "style": { + "navigationBarTitleText": "globalProperties" + } + }, { "path": "pages/built-in-component/keep-alive/keep-alive", "style": { diff --git a/pages/app-instance/globalData/globalData.test.js b/pages/app-instance/globalData/globalData.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4a4459c16d0c4884c5180ff8a1668bb49e01dea4 --- /dev/null +++ b/pages/app-instance/globalData/globalData.test.js @@ -0,0 +1,39 @@ +const PAGE_PATH = '/pages/app-instance/globalData/globalData' + +describe('globalData', () => { + let page = null + beforeAll(async () => { + page = await program.navigateTo(PAGE_PATH) + await page.waitFor('view') + }) + it('globalData', async () => { + await page.callMethod('getGlobalData') + let data = await page.data() + expect(data.originGlobalData.str).toBe('default globalData str') + expect(data.originGlobalData.num).toBe(0) + expect(data.originGlobalData.bool).toBe(false) + expect(data.originGlobalData.obj).toEqual({ + bool: false, + num: 0, + str: 'default globalData obj str', + }) + expect(data.originGlobalData.arr).toEqual([]) + expect(data.originGlobalData.mySet).toEqual([]) + expect(data.originGlobalData.myMap).toEqual({}) + expect(data.originGlobalDataFuncRes).toBe('globalData func') + await page.callMethod('setGlobalData') + data = await page.data() + expect(data.newGlobalData.str).toBe('new globalData str') + expect(data.newGlobalData.num).toBe(100) + expect(data.newGlobalData.bool).toBe(true) + expect(data.newGlobalData.obj).toEqual({ + bool: true, + num: 200, + str: 'new globalData obj str', + }) + expect(data.newGlobalData.arr).toEqual([1, 2, 3]) + expect(data.newGlobalData.mySet).toEqual(['a', 'b', 'c']) + expect(data.newGlobalData.myMap).toEqual({a: 1, b: 2, c: 3}) + expect(data.newGlobalDataFuncRes).toBe('new globalData func') + }) +}) diff --git a/pages/app-instance/globalData/globalData.uvue b/pages/app-instance/globalData/globalData.uvue new file mode 100644 index 0000000000000000000000000000000000000000..9ee93725d54188da7f9b4bae86dd0569dbf10f4d --- /dev/null +++ b/pages/app-instance/globalData/globalData.uvue @@ -0,0 +1,167 @@ + + + + + \ No newline at end of file diff --git a/pages/app-instance/globalProperties/globalProperties.test.js b/pages/app-instance/globalProperties/globalProperties.test.js new file mode 100644 index 0000000000000000000000000000000000000000..bdc73f0c26dccf025f65ac99d35aa331afa57dc6 --- /dev/null +++ b/pages/app-instance/globalProperties/globalProperties.test.js @@ -0,0 +1,59 @@ +const PAGE_PATH = '/pages/app-instance/globalProperties/globalProperties' + +describe('globalProperties', () => { + let page = null + beforeAll(async () => { + page = await program.navigateTo(PAGE_PATH) + await page.waitFor(500) + }) + it('globalProperties', async () => { + let data = await page.data() + expect(data.myGlobalProperties.str).toBe('default string') + expect(data.myGlobalProperties.num).toBe(0) + expect(data.myGlobalProperties.bool).toBe(false) + expect(data.myGlobalProperties.obj).toEqual({ + bool: false, + num: 0, + str: 'default globalProperties obj string' + }) + expect(data.myGlobalProperties.arr).toEqual([]) + expect(data.myGlobalProperties.set).toEqual([]) + expect(data.myGlobalProperties.map).toEqual({}) + expect(data.myGlobalProperties.reactiveObj).toEqual({ + str: 'default reactive string', + num: 0, + bool: false + }) + expect(data.globalPropertiesFnRes).toBe('globalPropertiesStr: default string, globalPropertiesNum: 0') + await page.callMethod('updateGlobalProperties') + data = await page.data() + expect(data.myGlobalProperties.str).toBe('new string') + expect(data.myGlobalProperties.num).toBe(100) + expect(data.myGlobalProperties.bool).toBe(true) + expect(data.myGlobalProperties.obj).toEqual({ + bool: true, + num: 100, + str: 'new globalProperties obj string' + }) + expect(data.myGlobalProperties.arr).toEqual([1, 2, 3]) + expect(data.myGlobalProperties.set).toEqual(['a', 'b', 'c']) + expect(data.myGlobalProperties.map).toEqual({ + 'a': 1, + 'b': 2, + 'c': 3 + }) + expect(data.myGlobalProperties.reactiveObj).toEqual({ + str: 'new reactive string', + num: 200, + bool: true + }) + expect(data.globalPropertiesFnRes).toBe('globalPropertiesStr: new string, globalPropertiesNum: 100') + }) + it('screenshot', async () => { + await page.waitFor(500) + const image = await program.screenshot({ + fullPage: true + }); + expect(image).toMatchImageSnapshot(); + }) +}) \ No newline at end of file diff --git a/pages/app-instance/globalProperties/globalProperties.uvue b/pages/app-instance/globalProperties/globalProperties.uvue new file mode 100644 index 0000000000000000000000000000000000000000..3b1c7b79df26b8fc5d3af3b2ad7188b58851d39d --- /dev/null +++ b/pages/app-instance/globalProperties/globalProperties.uvue @@ -0,0 +1,110 @@ + + + + + \ No newline at end of file diff --git a/pages/index.uvue b/pages/index.uvue index 412ce15fa36f269956f5f46ca901c7b81c8d6d16..d31b27b1172b9047d25808d4b34c7aeffcdec8a7 100644 --- a/pages/index.uvue +++ b/pages/index.uvue @@ -61,6 +61,16 @@ url: 'index', enable: true, }, + { + name: 'globalData', + url: 'globalData', + enable: true, + }, + { + name: 'globalProperties', + url: 'globalProperties', + enable: true, + }, ] as PageItem[], }, { @@ -415,11 +425,11 @@ enable: false, // #endif }, - { - name: 'extends', - url: 'extends', - enable: false, - }, + { + name: 'extends', + url: 'extends', + enable: false, + } ] as PageItem[], }, {