diff --git a/components/kube/applicationstate.js b/components/kube/applicationstate.js new file mode 100644 index 00000000..f2472520 --- /dev/null +++ b/components/kube/applicationstate.js @@ -0,0 +1,355 @@ +function initialState() +{ + function setHour(date, hour) { + var d = date + return new Date(d.setHours(hour)) + } + + function addDays(date, days) { + return new Date(date.getTime() + (24*60*60*1000 * days)) + } + + function getFirstDayOfWeek(date) { + //This works with negative days to get to the previous month + //Date.getDate() is the day of the month, Date.getDay() is the day of the week + return new Date(date.getFullYear(), date.getMonth(), date.getDate() - (date.getDay() - Qt.locale().firstDayOfWeek)) + } + + function dayOfWeek(date, day) { + //This works with negative days to get to the previous month + //Date.getDate() is the day of the month, Date.getDay() is the day of the week + return new Date(date.getFullYear(), date.getMonth(), date.getDate() - (date.getDay() - day)) + } + + var now = new Date() + var firstDayOfWeek = getFirstDayOfWeek(now) + return { + accounts: [{ + id: "account1", + name: "Work" + }, + { + id: "account2", + name: "Private" + }], + identities: [{ + account: "account1", + name: "John Doe", + address: "john@example.org" + }], + resources: [{ + id: "resource1", + account: "account1", + type: "dummy", + }, + { + id: "resource2", + account: "account2", + type: "dummy", + }], + folders: [{ + id: "folder1", + resource: "resource1", + name: "Inbox", + specialpurpose: ["inbox"], + mails: [{ + messageId: "", + date: setHour(now, 17), + to: ["\"John Doe\"", "\"Andrea Mueller\""], + from: "\"Jane Doe\"", + subject: "Kube 0.8 is out!", + body: "Hey,\n\nDid you see? Kube 0.8 is finally out!\n\nGet it now on www.kube-project.com\n\nCheers, Jane", + unread: false, + important: true + }, + { + inReplyTo: "", + date: setHour(now, 18), + from: "\"Andrea Mueller\"", + subject: "RE: Kube 0.8 is out!", + body: "Looking good indeed =)\n\n> Hey,\n\n> Did you see? Kube 0.8 is finally out!\n\n> Get it now on www.kube-project.com\n\n> Cheers, Jane", + to: ["\"Jane Doe\"", "\"John Doe\""], + important: true, + unread: false + }, + { + messageId: "", + date: setHour(now, 15), + subject: "subject1", + body: "body", + to: ["to@example.org"], + from: "\"Jane Doe\"", + unread: true + }, + { + inReplyTo: "", + date: setHour(now, 16), + subject: "RE: Meeting report", + body: "body2", + to: ["to@example.org"], + from: "\"Jane Doe\"", + unread: true + }, + { + date: setHour(now, 14), + subject: " ❆ ❆ ❆ Winter is coming ❆ ❆ ❆", + body: "UTF-8 Madness Umlauts:öüä Snowflake:❆ Heart:♥", + to: ["öüä@example.org"], + from: "\"Jane Doe\"", + unread: true + }, + { + date: addDays(now, -1), + subject: "Great Post!", + to: ["öüä@example.org"], + from: "\"Jane Doe\"", + unread: true + }, + { + date: addDays(now, -3), + subject: "Last weeks meeting", + to: ["öüä@example.org"], + from: "\"Evan Smith\"", + unread: false + }, + { + date: addDays(now, -4), + subject: "Tennis tomorrow?", + to: ["öüä@example.org"], + from: "\"Anna Cole\"", + unread: false + }, + { + date: addDays(now, -4), + subject: "Project report", + to: ["öüä@example.org"], + from: "\"Phil Barry\"", + unread: false + }, + { + date: addDays(now, -5), + subject: "Dummy", + from: "test@example.org", + }, + { + date: addDays(now, -5), + subject: "Dummy", + from: "test@example.org", + }, + { + date: addDays(now, -5), + subject: "Dummy", + from: "test@example.org", + }, + { + date: addDays(now, -5), + subject: "Dummy", + from: "test@example.org", + }, + { + date: addDays(now, -6), + subject: "Before last week", + from: "test@example.org", + }, + { + date: addDays(now, -7), + subject: "Last week", + from: "test@example.org", + }, + ]}, + { + id: "folder2", + resource: "resource1", + specialpurpose: ["drafts"], + name: "Drafts", + mails: [{ + date: setHour(now, 17), + to: ["\"Jane Doe\"", "\"Andrea Mueller\""], + from: "\"John Doe\"", + subject: "Kube 0.8 is out!", + body: "Hey,\n\nDid you see? Kube 0.8 is finally out!\n\nGet it now on www.kube-project.com\n\nCheers, Jane", + unread: false, + important: true + }] + }, + { + id: "folder3", + resource: "resource1", + specialpurpose: ["sent"], + name: "Sent" + }, + { + id: "folder4", + resource: "resource1", + specialpurpose: ["trash"], + name: "Trash" + }, + { + id: "folder5", + resource: "resource1", + name: "Spam" + }], + addressbooks: [{ + id: "addressbook1", + resource: "resource1", + name: "Personal Addressbook", + contacts: [{ + uid: "uid1", + givenname: "John", + familyname: "Doe", + email: ["doe@example.org"], + }, + { + uid: "uid2", + givenname: "Andrea", + familyname: "Mueller", + email: ["andrea@example.org"], + }, + { + uid: "uid3", + givenname: "Anna", + familyname: "Cole", + email: ["anna@example.org"], + }, + { + uid: "uid4", + givenname: "Jane", + familyname: "Doe", + email: ["jane@example.org"], + }, + { + uid: "uid5", + givenname: "Phil", + familyname: "Barry", + email: ["phil@example.org"], + }], + }], + calendars: [{ + id: "calendar1", + resource: "resource1", + name: "Calendar", + color: "#af1a6a", + contentTypes: ["event"], + enabled: true, + events: [{ + summary: "Monday morning standup", + starts: setHour(firstDayOfWeek, 9), + }, + { + summary: "Lunch with Claire", + starts: setHour(firstDayOfWeek, 12), + ends: setHour(firstDayOfWeek, 13), + }, + { + summary: "Meeting with Nik", + starts: setHour(firstDayOfWeek, 14), + ends: setHour(firstDayOfWeek, 16), + }, + { + summary: "Tennis?", + description: "This is test event #2", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 13), + ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 15), + }, + { + summary: "Dinner with Julia", + description: "This is test event #3", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 18), + ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 20), + }, + { + summary: "Mischa in Zurich", + description: "This is test event #4", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 2), 8), + ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 16), + }, + { + summary: "Draft Report", + description: "This is test event #3", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 13), + ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 17), + }, + { + summary: "Send Report", + description: "This is test event #3", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 12), + }], + }, + { + id: "calendar2", + resource: "resource1", + name: "Vacations", + color: "#00cc4b", + contentTypes: ["event"], + enabled: true, + events: [{ + summary: "Sandra is off", + description: "This is test day-long event #1", + starts: dayOfWeek(now, Qt.locale().firstDayOfWeek), + ends: dayOfWeek(now, Qt.locale().firstDayOfWeek + 7), + allDay: true, + }, + { + summary: "Jeremy is off", + description: "This is test day-long event #2", + starts: dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), + allDay: true, + }, + { + summary: "John's early weekend", + description: "This is test event #3", + starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 14), + ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 24), + }] + }, + { + id: "calendar3", + resource: "resource1", + name: "Tasks", + color: "#af1a6a", + contentTypes: ["todo"], + enabled: true, + todos: [{ + summary: "Prepare meeting", + starts: "2018-04-09T14:03:00", + doing: true + }, + { + summary: "Release Kube", + due: "2018-04-09T14:03:00", + doing: true + }, + { + summary: "Blog about latest improvements", + doing: true + }, + { + summary: "Pay bills", + doing: true + }, + { + summary: "Get a gift for Pam", + doing: true + }], + }, + { + id: "calendar3", + resource: "resource1", + name: "My Project", + color: "#f67400", + contentTypes: ["todo"], + enabled: true, + todos: [{ + summary: "Draft project plan", + doing: true + }] + }, + { + id: "account2calendar", + resource: "resource2", + name: "Account2Calendar", + color: "#f67400", + enabled: true + }], + } +} diff --git a/components/kube/main.qml b/components/kube/main.qml index 9dba1889..0dcc1dd0 100644 --- a/components/kube/main.qml +++ b/components/kube/main.qml @@ -1,409 +1,37 @@ /* * Copyright (C) 2018 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Window 2.0 import org.kube.components.kube 1.0 as KubeComponent import org.kube.framework 1.0 as Kube import org.kube.test 1.0 import "qml" - +import "applicationstate.js" as State KubeComponent.Kube { id: app height: Screen.desktopAvailableHeight * 0.8 width: Screen.desktopAvailableWidth * 0.8 - function setHour(date, hour) { - var d = date - return new Date(d.setHours(hour)) - } - - function addDays(date, days) { - return new Date(date.getTime() + (24*60*60*1000 * days)) - } - - function getFirstDayOfWeek(date) { - //This works with negative days to get to the previous month - //Date.getDate() is the day of the month, Date.getDay() is the day of the week - return new Date(date.getFullYear(), date.getMonth(), date.getDate() - (date.getDay() - Qt.locale().firstDayOfWeek)) - } - - function dayOfWeek(date, day) { - //This works with negative days to get to the previous month - //Date.getDate() is the day of the month, Date.getDay() is the day of the week - return new Date(date.getFullYear(), date.getMonth(), date.getDate() - (date.getDay() - day)) - } - Component.onCompleted: { - var now = new Date() - var firstDayOfWeek = getFirstDayOfWeek(now) - var initialState = { - accounts: [ - { - id: "account1", - name: "Work" - }, - { - id: "account2", - name: "Private" - }, - ], - identities: [{ - account: "account1", - name: "John Doe", - address: "john@example.org" - }], - resources: [ - { - id: "resource1", - account: "account1", - type: "dummy", - }, - { - id: "resource2", - account: "account2", - type: "dummy", - } - ], - folders: [{ - id: "folder1", - resource: "resource1", - name: "Inbox", - specialpurpose: ["inbox"], - mails: [ - { - messageId: "", - date: setHour(now, 17), - to: ["\"John Doe\"", "\"Andrea Mueller\""], - from: "\"Jane Doe\"", - subject: "Kube 0.8 is out!", - body: "Hey,\n\nDid you see? Kube 0.8 is finally out!\n\nGet it now on www.kube-project.com\n\nCheers, Jane", - unread: false, - important: true - }, - { - inReplyTo: "", - date: setHour(now, 18), - from: "\"Andrea Mueller\"", - subject: "RE: Kube 0.8 is out!", - body: "Looking good indeed =)\n\n> Hey,\n\n> Did you see? Kube 0.8 is finally out!\n\n> Get it now on www.kube-project.com\n\n> Cheers, Jane", - to: ["\"Jane Doe\"", "\"John Doe\""], - important: true, - unread: false - }, - { - messageId: "", - date: setHour(now, 15), - subject: "subject1", - body: "body", - to: ["to@example.org"], - from: "\"Jane Doe\"", - unread: true - }, - { - inReplyTo: "", - date: setHour(now, 16), - subject: "RE: Meeting report", - body: "body2", - to: ["to@example.org"], - from: "\"Jane Doe\"", - unread: true - }, - { - date: setHour(now, 14), - subject: " ❆ ❆ ❆ Winter is coming ❆ ❆ ❆", - body: "UTF-8 Madness Umlauts:öüä Snowflake:❆ Heart:♥", - to: ["öüä@example.org"], - from: "\"Jane Doe\"", - unread: true - }, - { - date: addDays(now, -1), - subject: "Great Post!", - to: ["öüä@example.org"], - from: "\"Jane Doe\"", - unread: true - }, - { - date: addDays(now, -3), - subject: "Last weeks meeting", - to: ["öüä@example.org"], - from: "\"Evan Smith\"", - unread: false - }, - { - date: addDays(now, -4), - subject: "Tennis tomorrow?", - to: ["öüä@example.org"], - from: "\"Anna Cole\"", - unread: false - }, - { - date: addDays(now, -4), - subject: "Project report", - to: ["öüä@example.org"], - from: "\"Phil Barry\"", - unread: false - }, - { - date: addDays(now, -5), - subject: "Dummy", - from: "test@example.org", - }, - { - date: addDays(now, -5), - subject: "Dummy", - from: "test@example.org", - }, - { - date: addDays(now, -5), - subject: "Dummy", - from: "test@example.org", - }, - { - date: addDays(now, -5), - subject: "Dummy", - from: "test@example.org", - }, - { - date: addDays(now, -6), - subject: "Before last week", - from: "test@example.org", - }, - { - date: addDays(now, -7), - subject: "Last week", - from: "test@example.org", - }, - ] - }, - { - id: "folder2", - resource: "resource1", - specialpurpose: ["drafts"], - name: "Drafts", - mails: [ - { - date: setHour(now, 17), - to: ["\"Jane Doe\"", "\"Andrea Mueller\""], - from: "\"John Doe\"", - subject: "Kube 0.8 is out!", - body: "Hey,\n\nDid you see? Kube 0.8 is finally out!\n\nGet it now on www.kube-project.com\n\nCheers, Jane", - unread: false, - important: true - }, - ] - }, - { - id: "folder3", - resource: "resource1", - specialpurpose: ["sent"], - name: "Sent" - }, - { - id: "folder4", - resource: "resource1", - specialpurpose: ["trash"], - name: "Trash" - }, - { - id: "folder5", - resource: "resource1", - name: "Spam" - } - ], - addressbooks: [{ - id: "addressbook1", - resource: "resource1", - name: "Personal Addressbook", - contacts: [ - { - uid: "uid1", - givenname: "John", - familyname: "Doe", - email: ["doe@example.org"], - }, - { - uid: "uid2", - givenname: "Andrea", - familyname: "Mueller", - email: ["andrea@example.org"], - }, - { - uid: "uid3", - givenname: "Anna", - familyname: "Cole", - email: ["anna@example.org"], - }, - { - uid: "uid4", - givenname: "Jane", - familyname: "Doe", - email: ["jane@example.org"], - }, - { - uid: "uid5", - givenname: "Phil", - familyname: "Barry", - email: ["phil@example.org"], - } - - ], - }], - calendars: [{ - id: "calendar1", - resource: "resource1", - name: "Calendar", - color: "#af1a6a", - contentTypes: ["event"], - enabled: true, - events: [ - { - summary: "Monday morning standup", - starts: setHour(firstDayOfWeek, 9), - }, - { - summary: "Lunch with Claire", - starts: setHour(firstDayOfWeek, 12), - ends: setHour(firstDayOfWeek, 13), - }, - { - summary: "Meeting with Nik", - starts: setHour(firstDayOfWeek, 14), - ends: setHour(firstDayOfWeek, 16), - }, - { - summary: "Tennis?", - description: "This is test event #2", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 13), - ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 15), - }, - { - summary: "Dinner with Julia", - description: "This is test event #3", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 18), - ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 1), 20), - }, - { - summary: "Mischa in Zurich", - description: "This is test event #4", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 2), 8), - ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 16), - }, - { - summary: "Draft Report", - description: "This is test event #3", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 13), - ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), 17), - }, - { - summary: "Send Report", - description: "This is test event #3", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 12), - }, - ], - }, - { - id: "calendar2", - resource: "resource1", - name: "Vacations", - color: "#00cc4b", - contentTypes: ["event"], - enabled: true, - events: [ - { - summary: "Sandra is off", - description: "This is test day-long event #1", - starts: dayOfWeek(now, Qt.locale().firstDayOfWeek), - ends: dayOfWeek(now, Qt.locale().firstDayOfWeek + 7), - allDay: true, - }, - { - summary: "Jeremy is off", - description: "This is test day-long event #2", - starts: dayOfWeek(now, Qt.locale().firstDayOfWeek + 4), - allDay: true, - }, - { - summary: "John's early weekend", - description: "This is test event #3", - starts: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 14), - ends: setHour(dayOfWeek(now, Qt.locale().firstDayOfWeek + 5), 24), - }, - ] - }, - { - id: "calendar3", - resource: "resource1", - name: "Tasks", - color: "#af1a6a", - contentTypes: ["todo"], - enabled: true, - todos: [ - { - summary: "Prepare meeting", - starts: "2018-04-09T14:03:00", - doing: true - }, - { - summary: "Release Kube", - due: "2018-04-09T14:03:00", - doing: true - }, - { - summary: "Blog about latest improvements", - doing: true - }, - { - summary: "Pay bills", - doing: true - }, - { - summary: "Get a gift for Pam", - doing: true - }, - ], - }, - { - id: "calendar3", - resource: "resource1", - name: "My Project", - color: "#f67400", - contentTypes: ["todo"], - enabled: true, - todos: [ - { - summary: "Draft project plan", - doing: true - } - ] - }, - { - id: "account2calendar", - resource: "resource2", - name: "Account2Calendar", - color: "#f67400", - enabled: true - }], - } - TestStore.setup(initialState) + TestStore.setup(State.initialState()) } } diff --git a/components/kube/tests/tst_screenshots.qml b/components/kube/tests/tst_screenshots.qml new file mode 100644 index 00000000..24097696 --- /dev/null +++ b/components/kube/tests/tst_screenshots.qml @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtTest 1.0 +import org.kube.test 1.0 +import "../qml" +import "../applicationstate.js" as State + +import org.kube.components.kube 1.0 as KubeComponent + + + +TestCase { + id: testCase + width: app.width + height: app.height + name: "Screenshots" + when: windowShown + + KubeComponent.Kube { + id: app + + width: 1024 + height: 768 + + Component.onCompleted: { + TestStore.setup(State.initialState()) + } + } + + function test_start() { + //Wait for animations to settle + wait(200) + // grabToImage(function(result) { + // result.saveToFile("something.png"); + // }); + var image = grabImage(app.contentItem) + // console.warn("Image ", image.size, app.contentItem.height) + image.save("something.png") + // wait(9999999) + } +}